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

Commit

Permalink
fix(user): allow email modification if permitted
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Nov 14, 2022
1 parent 465149b commit 48489a3
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions pages/settings/account.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
<form class="account-settings" @submit.prevent>
<NonSensitiveTextualField
v-model="email"
v-model:status="emailFieldStatus"
:disabled="mayEditEmail"
:status="emailFieldStatus"
class="submittable-field email-field"
:label="emailVerified"
type="email"/>
Expand Down Expand Up @@ -99,7 +98,9 @@ import Fetcher from "$@/fetchers/user"
import settingsTabInfos from "@/settings/settings_tab_infos"
import { user as permissionGroup } from "$/permissions/permission_list"
import {
UPDATE_OWN_DATA
UPDATE_OWN_DATA,
UPDATE_ANYONE_ON_OWN_DEPARTMENT,
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
} from "$/permissions/user_combinations"
import SettingsHeader from "@/helpers/tabbed_page_header.vue"
Expand All @@ -118,17 +119,19 @@ const { userProfile } = pageProps
const receivedErrors = ref<string[]>([])
const successMessages = ref<string[]>([])
const emailFieldStatus = ref<FieldStatus>("enabled")
const oldEmail = userProfile.data.email
const email = ref<string>(userProfile.data.email)
const mayEditEmail = computed<boolean>(() => {
const isPermitted = permissionGroup.hasOneRoleAllowed(userProfile.data.roles.data, [
UPDATE_OWN_DATA
UPDATE_OWN_DATA,
UPDATE_ANYONE_ON_OWN_DEPARTMENT,
UPDATE_ANYONE_ON_ALL_DEPARTMENTS
])
return isPermitted
})
const emailFieldStatus = ref<FieldStatus>(mayEditEmail.value ? "enabled" : "disabled")
const emailVerified = computed<string>(() => {
let verifyEmail = ""
Expand Down Expand Up @@ -176,7 +179,7 @@ function updateUser(): void {
"email": email.value,
"kind": userProfile.data.kind,
"name": userProfile.data.name,
"emailVerifiedAt": userProfile.data.emailVerifiedAt,
"emailVerifiedAt": userProfile.data.emailVerifiedAt?.toJSON() ?? null,
"prefersDark": userProfile.data.prefersDark
})
.then(() => {
Expand Down

0 comments on commit 48489a3

Please sign in to comment.