From f9bd957b037636be483aa5f9f68e31fbb1088a2a Mon Sep 17 00:00:00 2001 From: Christopher Ng Date: Wed, 30 Aug 2023 17:45:16 -0700 Subject: [PATCH] enh(settings): Load from disabled users endpoint Signed-off-by: Christopher Ng --- apps/settings/src/components/UserList.vue | 27 +++++++++++++---- apps/settings/src/store/users.js | 36 +++++++++++++++++++++++ 2 files changed, 57 insertions(+), 6 deletions(-) diff --git a/apps/settings/src/components/UserList.vue b/apps/settings/src/components/UserList.vue index 5c7e9ba4dda6c..92c823e8bc5e5 100644 --- a/apps/settings/src/components/UserList.vue +++ b/apps/settings/src/components/UserList.vue @@ -223,6 +223,14 @@ export default { return this.$store.getters.getUsersLimit }, + disabledUsersOffset() { + return this.$store.getters.getDisabledUsersOffset + }, + + disabledUsersLimit() { + return this.$store.getters.getDisabledUsersLimit + }, + usersCount() { return this.users.length }, @@ -297,12 +305,19 @@ export default { async loadUsers() { this.loading.users = true try { - await this.$store.dispatch('getUsers', { - offset: this.usersOffset, - limit: this.usersLimit, - group: this.selectedGroup !== 'disabled' ? this.selectedGroup : '', - search: this.searchQuery, - }) + if (this.selectedGroup === 'disabled') { + await this.$store.dispatch('getDisabledUsers', { + offset: this.disabledUsersOffset, + limit: this.disabledUsersLimit, + }) + } else { + await this.$store.dispatch('getUsers', { + offset: this.usersOffset, + limit: this.usersLimit, + group: this.selectedGroup, + search: this.searchQuery, + }) + } logger.debug(`${this.users.length} total user(s) loaded`) } catch (error) { logger.error('Failed to load users', { error }) diff --git a/apps/settings/src/store/users.js b/apps/settings/src/store/users.js index b031f768fd1ad..2682415a01636 100644 --- a/apps/settings/src/store/users.js +++ b/apps/settings/src/store/users.js @@ -63,6 +63,8 @@ const state = { minPasswordLength: 0, usersOffset: 0, usersLimit: 25, + disabledUsersOffset: 0, + disabledUsersLimit: 25, userCount: 0, showConfig: { showStoragePath: false, @@ -83,6 +85,9 @@ const mutations = { state.usersOffset += state.usersLimit state.users = users }, + updateDisabledUsers(state, _usersObj) { + state.disabledUsersOffset += state.disabledUsersLimit + }, setPasswordPolicyMinLength(state, length) { state.minPasswordLength = length !== '' ? length : 0 }, @@ -237,6 +242,7 @@ const mutations = { resetUsers(state) { state.users = [] state.usersOffset = 0 + state.disabledUsersOffset = 0 }, setShowConfig(state, { key, value }) { @@ -264,6 +270,12 @@ const getters = { getUsersLimit(state) { return state.usersLimit }, + getDisabledUsersOffset(state) { + return state.disabledUsersOffset + }, + getDisabledUsersLimit(state) { + return state.disabledUsersLimit + }, getUserCount(state) { return state.userCount }, @@ -373,6 +385,30 @@ const actions = { }) }, + /** + * Get disabled users with full details + * + * @param {object} context store context + * @param {object} options destructuring object + * @param {number} options.offset List offset to request + * @param {number} options.limit List number to return from offset + * @return {Promise} + */ + async getDisabledUsers(context, { offset, limit }) { + const url = generateOcsUrl('cloud/users/disabled?offset={offset}&limit={limit}', { offset, limit }) + try { + const response = await api.get(url) + const usersCount = Object.keys(response.data.ocs.data.users).length + if (usersCount > 0) { + context.commit('appendUsers', response.data.ocs.data.users) + context.commit('updateDisabledUsers', response.data.ocs.data.users) + } + return usersCount + } catch (error) { + context.commit('API_FAILURE', error) + } + }, + getGroups(context, { offset, limit, search }) { search = typeof search === 'string' ? search : '' const limitParam = limit === -1 ? '' : `&limit=${limit}`