Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
fix(user): hide the attachment of roles if not permitted
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Nov 14, 2022
1 parent e4ce4bf commit 1a255ef
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions pages/user/read.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</form>

<form
v-if="mayUpdateAnyone"
class="user-data-form"
@submit.prevent="updateRoles">
<h1 class="user-data-form-header">
Expand Down Expand Up @@ -75,7 +76,7 @@
Archive
</button>
<button
v-if="mayReset"
v-if="mayResetPassword"
type="button"
class="btn btn-primary"
@click="resetUserPassword">
Expand Down Expand Up @@ -184,22 +185,31 @@ const isOnSameDepartment = computed<boolean>(() => {
const ownDepartment = userProfile.data.department.data.id
return ownDepartment === user.value.data.department.data.id
})
const mayUpdateAnyone = computed<boolean>(() => {
const userRoles = userProfile.data.roles.data
const isLimitedUpToGlobalScope = permissionGroup.hasOneRoleAllowed(userRoles, [
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
])
return isLimitedUpToGlobalScope
})
const mayUpdateUser = computed<boolean>(() => {
const users = userProfile.data.roles.data
const isLimitedUpToDepartmentScope = permissionGroup.hasOneRoleAllowed(users, [
const userRoles = userProfile.data.roles.data
const isLimitedUpToDepartmentScope = permissionGroup.hasOneRoleAllowed(userRoles, [
UPDATE_ANYONE_ON_OWN_DEPARTMENT
]) && isOnSameDepartment.value
const isLimitedUpToGlobalScope = permissionGroup.hasOneRoleAllowed(userProfile.data.roles.data, [
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
])
const isLimitedUpToGlobalScope = mayUpdateAnyone.value
return isLimitedUpToDepartmentScope || isLimitedUpToGlobalScope
})
const mayArchiveOrRestoreUser = computed<boolean>(() => {
const users = userProfile.data.roles.data
const isLimitedUpToDepartmentScope = permissionGroup.hasOneRoleAllowed(users, [
const userRoles = userProfile.data.roles.data
const isLimitedUpToDepartmentScope = permissionGroup.hasOneRoleAllowed(userRoles, [
ARCHIVE_AND_RESTORE_ANYONE_ON_OWN_DEPARTMENT
]) && isOnSameDepartment.value
Expand All @@ -220,7 +230,6 @@ const mayResetPassword = computed<boolean>(() => {
return isLimitedUpToDepartmentScope
})
const mayReset = computed<boolean>(() => mayResetPassword.value)
const nameFieldStatus = ref<FieldStatus>(mayUpdateUser.value ? "locked" : "disabled")
const mayNotSelect = computed<boolean>(() => !mayUpdateUser.value)
Expand All @@ -231,6 +240,7 @@ const successMessages = ref<string[]>([])
async function updateUser() {
await fetcher.update(user.value.data.id, {
"email": user.value.data.email,
"emailVerifiedAt": null,
"kind": user.value.data.kind,
"name": user.value.data.name,
"prefersDark": user.value.data.prefersDark ? user.value.data.prefersDark : false
Expand Down

0 comments on commit 1a255ef

Please sign in to comment.