Skip to content

Commit

Permalink
Fix loading/editing users that do not have a role assignment (#8590)
Browse files Browse the repository at this point in the history
  • Loading branch information
JammingBen committed Mar 10, 2023
1 parent 399aa4c commit 04ddb85
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 8 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/bugfix-users-without-role-assignment
@@ -0,0 +1,6 @@
Bugfix: Users without role assignment

Listing and editing users without a role assignment in the admin settings has been fixed.

https://github.com/owncloud/web/issues/8585
https://github.com/owncloud/web/pull/8590
Expand Up @@ -118,8 +118,10 @@ export default defineComponent({
roleDisplayName() {
const assignedRole = this.user.appRoleAssignments[0]
return this.$gettext(
this.roles.find((role) => role.id === assignedRole.appRoleId)?.displayName || ''
return (
this.$gettext(
this.roles.find((role) => role.id === assignedRole?.appRoleId)?.displayName || ''
) || '-'
)
},
groupsDisplayValue() {
Expand Down
Expand Up @@ -205,9 +205,9 @@ export default defineComponent({
return cloneDeep(this.user)
},
selectedRoleName() {
const assignedRole = this.editUser.appRoleAssignments[0]
return this.$gettext(
this.roles.find((role) => role.id === this.editUser.appRoleAssignments[0].appRoleId)
.displayName
this.roles.find((role) => role.id === assignedRole?.appRoleId)?.displayName || ''
)
}
},
Expand Down Expand Up @@ -313,6 +313,10 @@ export default defineComponent({
})
},
onUpdateRole(role) {
if (!this.editUser.appRoleAssignments.length) {
this.editUser.appRoleAssignments.push({ appRoleId: role.id, displayName: role.displayName })
return
}
this.editUser.appRoleAssignments[0].appRoleId = role.id
},
onUpdatePassword(password) {
Expand Down
Expand Up @@ -346,8 +346,10 @@ export default defineComponent({
getRoleDisplayNameByUser(user) {
const assignedRole = user.appRoleAssignments[0]
return this.$gettext(
this.roles.find((role) => role.id === assignedRole.appRoleId)?.displayName || ''
return (
this.$gettext(
this.roles.find((role) => role.id === assignedRole?.appRoleId)?.displayName || ''
) || '-'
)
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/web-app-admin-settings/src/views/Users.vue
Expand Up @@ -229,6 +229,7 @@ export default defineComponent({
const roles = ref([])
const selectedUsers = ref([])
const additionalUserDataLoadedForUserIds = ref([])
const applicationId = ref()
const selectedUserIds = computed(() =>
unref(selectedUsers).map((selectedUser) => selectedUser.id)
)
Expand Down Expand Up @@ -263,6 +264,7 @@ export default defineComponent({
const loadAppRolesTask = useTask(function* (signal) {
const applicationsResponse = yield unref(graphClient).applications.listApplications()
roles.value = applicationsResponse.data.value[0].appRoles
applicationId.value = applicationsResponse.data.value[0].id
})
const loadUsersTask = useTask(function* (signal) {
Expand Down Expand Up @@ -511,6 +513,7 @@ export default defineComponent({
users,
roles,
groups,
applicationId,
loadResourcesTask,
loadAdditionalUserDataTask,
graphClient,
Expand Down Expand Up @@ -648,7 +651,7 @@ export default defineComponent({
}
if (
!isEqual(user.appRoleAssignments[0].appRoleId, editUser.appRoleAssignments[0].appRoleId)
!isEqual(user.appRoleAssignments[0]?.appRoleId, editUser.appRoleAssignments[0]?.appRoleId)
) {
await this.updateUserAppRoleAssignments(user, editUser)
}
Expand Down Expand Up @@ -693,7 +696,7 @@ export default defineComponent({
updateUserAppRoleAssignments(user, editUser) {
return this.graphClient.users.createUserAppRoleAssignment(user.id, {
appRoleId: editUser.appRoleAssignments[0].appRoleId,
resourceId: editUser.appRoleAssignments[0].resourceId,
resourceId: this.applicationId,
principalId: editUser.id
})
},
Expand Down

0 comments on commit 04ddb85

Please sign in to comment.