perf: 禁止用户自身更新自己的某些属性

This commit is contained in:
wangruidong 2024-02-01 18:00:44 +08:00 committed by Bryan
parent 2a92c7657c
commit ba109da324
5 changed files with 24 additions and 9 deletions

View File

@ -7,13 +7,11 @@
v-bind="data.attrs" v-bind="data.attrs"
> >
<template v-if="data.helpTips" #label> <template v-if="data.helpTips" #label>
{{ data.label }}
<el-tooltip placement="top" effect="light" popper-class="help-tips"> <el-tooltip placement="top" effect="light" popper-class="help-tips">
<div slot="content" v-html="data.helpTips" /> <div slot="content" v-html="data.helpTips" />
<el-button style="padding: 0"> <i class="fa fa-question-circle-o" />
<i class="fa fa-question-circle" />
</el-button>
</el-tooltip> </el-tooltip>
{{ data.label }}
</template> </template>
<template v-if="readonly && hasReadonlyContent"> <template v-if="readonly && hasReadonlyContent">
<div <div
@ -70,7 +68,8 @@
:key="opt.label" :key="opt.label"
v-bind="opt" v-bind="opt"
:label="'value' in opt ? opt.value : opt.label" :label="'value' in opt ? opt.value : opt.label"
>{{ opt.label }}</el-radio> >{{ opt.label }}
</el-radio>
</template> </template>
</custom-component> </custom-component>
<div v-if="data.helpText" class="help-block" v-html="data.helpText" /> <div v-if="data.helpText" class="help-block" v-html="data.helpText" />

View File

@ -2116,7 +2116,8 @@
"passwordWillExpiredPrefixMsg": "The password will expire in ", "passwordWillExpiredPrefixMsg": "The password will expire in ",
"passwordWillExpiredSuffixMsg": " days.Please change your password as soon as possible.", "passwordWillExpiredSuffixMsg": " days.Please change your password as soon as possible.",
"dateLastLogin": "Date last login", "dateLastLogin": "Date last login",
"AddAllMembersWarningMsg": "Are you sure you want to add all members?" "AddAllMembersWarningMsg": "Are you sure you want to add all members?",
"disallowSelfUpdateFields": "Not allowed to modify the current fields oneself"
}, },
"notifications": { "notifications": {
"MessageType": "Message Type", "MessageType": "Message Type",

View File

@ -2105,7 +2105,8 @@
"passwordExpired": "パスワードが期限切れです", "passwordExpired": "パスワードが期限切れです",
"passwordWillExpiredPrefixMsg": "パスワードはまもなく", "passwordWillExpiredPrefixMsg": "パスワードはまもなく",
"passwordWillExpiredSuffixMsg": "期限が切れた後、できるだけ早くパスワードを変更してください。", "passwordWillExpiredSuffixMsg": "期限が切れた後、できるだけ早くパスワードを変更してください。",
"AddAllMembersWarningMsg": "すべてのメンバーを追加してもよろしいですか?" "AddAllMembersWarningMsg": "すべてのメンバーを追加してもよろしいですか?",
"disallowSelfUpdateFields": "現在のフィールドを自分で変更することは許可されていません"
}, },
"notifications": { "notifications": {
"MessageType": "メッセージタイプ", "MessageType": "メッセージタイプ",

View File

@ -2099,7 +2099,8 @@
"SetPublicKey": "设置SSH公钥", "SetPublicKey": "设置SSH公钥",
"passwordExpired": "密码过期了", "passwordExpired": "密码过期了",
"passwordWillExpiredPrefixMsg": "密码即将在 ", "passwordWillExpiredPrefixMsg": "密码即将在 ",
"passwordWillExpiredSuffixMsg": "天 后过期,请尽快修改您的密码。" "passwordWillExpiredSuffixMsg": "天 后过期,请尽快修改您的密码。",
"disallowSelfUpdateFields": "不允许自己修改当前字段"
}, },
"notifications": { "notifications": {
"MessageType": "消息类型", "MessageType": "消息类型",

View File

@ -133,6 +133,7 @@ export default {
}, },
org_roles: { org_roles: {
component: Select2, component: Select2,
label: this.$t('users.OrgRoles'),
rules: this.$store.getters.currentOrgIsRoot ? [] : [rules.RequiredChange], rules: this.$store.getters.currentOrgIsRoot ? [] : [rules.RequiredChange],
el: { el: {
multiple: true, multiple: true,
@ -164,6 +165,10 @@ export default {
}, },
phone: { phone: {
component: PhoneInput component: PhoneInput
},
is_active: {
label: this.$t('users.IsActive'),
el: {}
} }
}, },
submitMethod() { submitMethod() {
@ -200,7 +205,7 @@ export default {
} }
}, },
computed: { computed: {
...mapGetters(['currentOrgIsRoot']) ...mapGetters(['currentOrgIsRoot', 'currentUser'])
}, },
async mounted() { async mounted() {
if (this.currentOrgIsRoot) { if (this.currentOrgIsRoot) {
@ -212,6 +217,14 @@ export default {
methods: { methods: {
afterGetUser(user) { afterGetUser(user) {
this.user = user this.user = user
if (this.user.id === this.currentUser.id) {
const fieldsToUpdate = ['system_roles', 'org_roles', 'is_active']
fieldsToUpdate.forEach(field => {
const msg = this.$t('users.disallowSelfUpdateFields', { attr: this.fieldsMeta[field]['label'] })
this.fieldsMeta[field].el.disabled = true
this.fieldsMeta[field].helpTips = msg
})
}
this.fieldsMeta.password.el.userIsOrgAdmin = user['is_org_admin'] this.fieldsMeta.password.el.userIsOrgAdmin = user['is_org_admin']
if (this.$route.query.clone_from) { if (this.$route.query.clone_from) {
this.user.groups = [] this.user.groups = []