Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enh(settings): Load from disabled users endpoint #40169

Merged
merged 3 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions apps/settings/src/components/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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 })
Expand Down
36 changes: 36 additions & 0 deletions apps/settings/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ const state = {
minPasswordLength: 0,
usersOffset: 0,
usersLimit: 25,
disabledUsersOffset: 0,
disabledUsersLimit: 25,
userCount: 0,
showConfig: {
showStoragePath: false,
Expand All @@ -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
},
Expand Down Expand Up @@ -237,6 +242,7 @@ const mutations = {
resetUsers(state) {
state.users = []
state.usersOffset = 0
state.disabledUsersOffset = 0
},

setShowConfig(state, { key, value }) {
Expand Down Expand Up @@ -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
},
Expand Down Expand Up @@ -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<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
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User_LDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
return $enabled;
}

public function getDisabledUserList(int $offset = 0, ?int $limit = null): array {
public function getDisabledUserList(?int $limit = null, int $offset = 0): array {
throw new \Exception('This is implemented directly in User_Proxy');
}
}
2 changes: 1 addition & 1 deletion apps/user_ldap/lib/User_Proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
return $this->handleRequest($uid, 'setUserEnabled', [$uid, $enabled, $queryDatabaseValue, $setDatabaseValue]);
}

public function getDisabledUserList(int $offset = 0, ?int $limit = null): array {
public function getDisabledUserList(?int $limit = null, int $offset = 0): array {
return array_map(
fn (OfflineUser $user) => $user->getOCName(),
array_slice(
Expand Down
4 changes: 2 additions & 2 deletions dist/settings-users-8351.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-users-8351.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/settings-vue-settings-apps-users-management.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/settings-vue-settings-apps-users-management.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/public/User/Backend/IProvideEnabledStateBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ public function setUserEnabled(string $uid, bool $enabled, callable $queryDataba
*
* @return string[]
*/
public function getDisabledUserList(int $offset = 0, ?int $limit = null): array;
public function getDisabledUserList(?int $limit = null, int $offset = 0): array;
}
Loading