Skip to content

Commit

Permalink
enh(settings): Load from disabled users endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Sep 9, 2023
1 parent 4d63760 commit 65b6467
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 6 deletions.
27 changes: 21 additions & 6 deletions apps/settings/src/components/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,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
},
Expand Down Expand Up @@ -312,12 +320,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 })
Expand Down
38 changes: 38 additions & 0 deletions apps/settings/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ const state = {
minPasswordLength: 0,
usersOffset: 0,
usersLimit: 25,
disabledUsersOffset: 0,
disabledUsersLimit: 25,
userCount: 0,
showConfig: {
showStoragePath: false,
Expand All @@ -81,6 +83,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
},
Expand Down Expand Up @@ -230,6 +235,7 @@ const mutations = {
resetUsers(state) {
state.users = []
state.usersOffset = 0
state.disabledUsersOffset = 0
},

setShowConfig(state, { key, value }) {
Expand Down Expand Up @@ -257,6 +263,12 @@ const getters = {
getUsersLimit(state) {
return state.usersLimit
},
getDisabledUsersOffset(state) {
return state.disabledUsersOffset
},
getDisabledUsersLimit(state) {
return state.disabledUsersLimit
},
getUserCount(state) {
return state.userCount
},
Expand Down Expand Up @@ -358,6 +370,32 @@ const actions = {
})
},

// TODO test many users

/**
* 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<number>}
*/
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}`
Expand Down

0 comments on commit 65b6467

Please sign in to comment.