From 27497451d9847fc57b7e67b8676f35532e299b2d Mon Sep 17 00:00:00 2001 From: advplyr Date: Sun, 29 Oct 2023 11:28:34 -0500 Subject: [PATCH] Add:Ereader device setting to set users that have access #1982 --- .../modals/emails/EReaderDeviceModal.vue | 84 +++++++++++++++++-- client/components/ui/Dropdown.vue | 2 +- client/components/ui/InputDropdown.vue | 12 +-- client/components/ui/MultiSelectDropdown.vue | 40 +++++---- client/strings/da.json | 5 ++ client/strings/de.json | 5 ++ client/strings/en-us.json | 5 ++ client/strings/es.json | 5 ++ client/strings/fr.json | 5 ++ client/strings/gu.json | 5 ++ client/strings/hi.json | 5 ++ client/strings/hr.json | 5 ++ client/strings/it.json | 5 ++ client/strings/lt.json | 5 ++ client/strings/nl.json | 5 ++ client/strings/no.json | 5 ++ client/strings/pl.json | 5 ++ client/strings/ru.json | 5 ++ client/strings/zh-cn.json | 5 ++ server/controllers/EmailController.js | 29 +++++-- server/objects/settings/EmailSettings.js | 65 ++++++++++++-- server/objects/user/User.js | 3 + server/routers/ApiRouter.js | 10 +-- 23 files changed, 266 insertions(+), 54 deletions(-) diff --git a/client/components/modals/emails/EReaderDeviceModal.vue b/client/components/modals/emails/EReaderDeviceModal.vue index 4b6e87cf33..79d80f7c46 100644 --- a/client/components/modals/emails/EReaderDeviceModal.vue +++ b/client/components/modals/emails/EReaderDeviceModal.vue @@ -8,7 +8,7 @@
-
+
@@ -16,6 +16,14 @@
+
+
+ +
+
+ +
+
@@ -45,8 +53,11 @@ export default { processing: false, newDevice: { name: '', - email: '' - } + email: '', + availabilityOption: 'adminAndUp', + users: [] + }, + users: [] } }, watch: { @@ -68,10 +79,55 @@ export default { } }, title() { - return this.ereaderDevice ? 'Create Device' : 'Update Device' + return !this.ereaderDevice ? 'Create Device' : 'Update Device' + }, + userAvailabilityOptions() { + return [ + { + text: this.$strings.LabelAdminUsersOnly, + value: 'adminOrUp' + }, + { + text: this.$strings.LabelAllUsersExcludingGuests, + value: 'userOrUp' + }, + { + text: this.$strings.LabelAllUsersIncludingGuests, + value: 'guestOrUp' + }, + { + text: this.$strings.LabelSelectUsers, + value: 'specificUsers' + } + ] + }, + userOptions() { + return this.users.map((u) => ({ text: u.username, value: u.id })) } }, methods: { + availabilityOptionChanged(option) { + if (option === 'specificUsers' && !this.users.length) { + this.loadUsers() + } + }, + async loadUsers() { + this.processing = true + this.users = await this.$axios + .$get('/api/users') + .then((res) => { + return res.users.sort((a, b) => { + return a.createdAt - b.createdAt + }) + }) + .catch((error) => { + console.error('Failed', error) + return [] + }) + .finally(() => { + this.processing = false + }) + }, submitForm() { this.$refs.ereaderNameInput.blur() this.$refs.ereaderEmailInput.blur() @@ -81,19 +137,27 @@ export default { return } + if (this.newDevice.availabilityOption === 'specificUsers' && !this.newDevice.users.length) { + this.$toast.error('Must select at least one user') + return + } + if (this.newDevice.availabilityOption !== 'specificUsers') { + this.newDevice.users = [] + } + this.newDevice.name = this.newDevice.name.trim() this.newDevice.email = this.newDevice.email.trim() if (!this.ereaderDevice) { if (this.existingDevices.some((d) => d.name === this.newDevice.name)) { - this.$toast.error('EReader device with that name already exists') + this.$toast.error('Ereader device with that name already exists') return } this.submitCreate() } else { if (this.ereaderDevice.name !== this.newDevice.name && this.existingDevices.some((d) => d.name === this.newDevice.name)) { - this.$toast.error('EReader device with that name already exists') + this.$toast.error('Ereader device with that name already exists') return } @@ -160,9 +224,17 @@ export default { if (this.ereaderDevice) { this.newDevice.name = this.ereaderDevice.name this.newDevice.email = this.ereaderDevice.email + this.newDevice.availabilityOption = this.ereaderDevice.availabilityOption || 'adminOrUp' + this.newDevice.users = this.ereaderDevice.users || [] + + if (this.newDevice.availabilityOption === 'specificUsers' && !this.users.length) { + this.loadUsers() + } } else { this.newDevice.name = '' this.newDevice.email = '' + this.newDevice.availabilityOption = 'adminOrUp' + this.newDevice.users = [] } } }, diff --git a/client/components/ui/Dropdown.vue b/client/components/ui/Dropdown.vue index 69f04afe2b..5815549985 100644 --- a/client/components/ui/Dropdown.vue +++ b/client/components/ui/Dropdown.vue @@ -13,7 +13,7 @@ -
    +