feat: Add permission checks for platform editing

This commit is contained in:
wangruidong 2024-12-17 15:48:23 +08:00 committed by Bryan
parent 320613d15d
commit 23fae59411
3 changed files with 13 additions and 10 deletions

View File

@ -122,7 +122,7 @@ export default {
},
onCanSetting() {
const filterField = Object.keys(this.remoteMeta)
this.canSetting = filterField.includes(this.method)
this.canSetting = filterField.includes(this.method) && this.$hasPerm('assets.change_platform')
this.$emit('canSetting', this.canSetting)
return this.canSetting
},

View File

@ -27,6 +27,7 @@ export default {
}
},
data() {
const canEdit = !this.object['internal'] && this.$hasPerm('assets.change_platform')
return {
loading: true,
initial: {
@ -35,14 +36,14 @@ export default {
}
},
url: `/api/v1/assets/platforms/`,
disabled: this.object.internal,
disabled: !canEdit,
hasReset: false,
hasDetailInMsg: false,
submitMethod: () => 'patch',
fields: [['', ['automation']]],
fieldsMeta: platformFieldsMeta(this),
onSubmit: this.submit,
canSubmit: !this.object.internal,
canSubmit: canEdit,
defaultOptions: {},
afterGetFormValue: (obj) => {
updateAutomationParams(this, obj)
@ -65,7 +66,7 @@ export default {
},
methods: {
submit(validValues) {
if (!this.$hasPerm('assets.change_platform') || !this.isSystemAdmin) {
if (!this.canSubmit || !this.isSystemAdmin) {
return this.$message.error(this.$tc('NoPermission'))
}
this.$axios.patch(`${this.url}${this.object.id}/`, validValues).then(() => {

View File

@ -10,10 +10,10 @@
v-if="protocolChoices"
v-model="object.protocols"
:choices="protocolChoices"
:readonly="object['internal']"
:readonly="!canEdit"
/>
<el-button
v-if="!object.internal"
v-if="canEdit"
size="small"
style="margin-top: 10px"
type="primary"
@ -71,7 +71,8 @@ export default {
],
protocolChoices: null,
constraints: {}
constraints: {},
canEdit: !this.object['internal'] && this.$hasPerm('assets.change_platform')
}
},
computed: {},
@ -103,7 +104,7 @@ export default {
attrs: {
label: this.$t('Update'),
model: object['domain_enabled'],
disabled: object['internal'] || this.constraints['domain_enabled'] === false
disabled: !this.canEdit || this.constraints['domain_enabled'] === false
},
callbacks: Object.freeze({
change: (val) => {
@ -120,7 +121,7 @@ export default {
type: 'switch',
attrs: {
model: object['su_enabled'],
disabled: object['internal'] || this.constraints['su_enabled'] === false
disabled: !this.canEdit || this.constraints['su_enabled'] === false
},
callbacks: Object.freeze({
change: (val) => {
@ -136,7 +137,8 @@ export default {
title: this.$t('SyncProtocolToAsset'),
attrs: {
type: 'primary',
label: this.$t('Sync')
label: this.$t('Sync'),
disabled: !this.canEdit
},
callbacks: Object.freeze({
click: () => {