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

Fix loading/editing users that do not have a role assignment #8590

Merged
merged 3 commits into from Mar 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -119,7 +119,7 @@ export default defineComponent({
const assignedRole = this.user.appRoleAssignments[0]

return this.$gettext(
this.roles.find((role) => role.id === assignedRole.appRoleId)?.displayName || ''
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 @@ -347,7 +347,7 @@ export default defineComponent({
const assignedRole = user.appRoleAssignments[0]

return this.$gettext(
this.roles.find((role) => role.id === assignedRole.appRoleId)?.displayName || ''
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: editUser.appRoleAssignments[0].resourceId || this.applicationId,
JammingBen marked this conversation as resolved.
Show resolved Hide resolved
principalId: editUser.id
})
},
Expand Down