Skip to content

Commit

Permalink
refactor: 平台/项目部分资源鉴权逻辑调整 --story=119946365
Browse files Browse the repository at this point in the history
  • Loading branch information
luofann committed Oct 8, 2024
1 parent dbb3466 commit 04aee82
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 100 deletions.
84 changes: 44 additions & 40 deletions frontend/pc/src/views/processManagement/apiConfigure/apiTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<ul class="bk-dropdown-list" slot="dropdown-content">
<li>
<a href="javascript:;"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
:title="$t(`m.systemConfig['接入API']`)"
data-test-id="api_a_apiTableAccessApi"
@click="openShade('JOIN')">
Expand All @@ -47,8 +47,8 @@
<li>
<a href="javascript:;"
data-test-id="api_a_apiTableCreateApi"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
:title="$t(`m.systemConfig['新增API']`)"
@click="openShade('ADD')">
{{$t(`m.systemConfig['新增API']`)}}
Expand All @@ -60,16 +60,16 @@
data-test-id="api_button_apiTableuploadApi"
:theme="'default'"
:disabled="disableImport"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="['mr10 bk-btn-file', { 'btn-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }]"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="['mr10 bk-btn-file', { 'btn-permission-disable': !hasPermission(targetPerms, curPerms) }]"
:title="$t(`m.systemConfig['点击上传']`)">
<input :disabled="disableImport" :type="!hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) ? 'button' : 'file'" :value="fileVal" class="bk-input-file" @change="handleFile" @click="hasImportPermission">
<input :disabled="disableImport" :type="!hasPermission(targetPerms, curPerms) ? 'button' : 'file'" :value="fileVal" class="bk-input-file" @change="handleFile" @click="hasImportPermission">
{{$t(`m.systemConfig['导入']`)}}
</bk-button>
<bk-button :theme="'default'"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
data-test-id="api_button_apiTableBatchDeleteApi"
:class="['mr10 batch-remove-btn', { 'btn-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }]"
:class="['mr10 batch-remove-btn', { 'btn-permission-disable': !hasPermission(targetPerms, curPerms) }]"
:title="$t(`m.systemConfig['批量移除']`)"
:disabled="!checkList.length"
@click="deleteCheck">
Expand Down Expand Up @@ -111,8 +111,8 @@
<!-- :disabled="props.row.is_builtin || !!props.row.count" -->
<span class="bk-lable-primary"
data-test-id="api_span_apiTableViewDetail"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
:title="props.row.name"
@click="entryOne(props.row)">
{{props.row.name || '--'}}
Expand Down Expand Up @@ -163,17 +163,17 @@
</bk-button>
<bk-button theme="primary" text
data-test-id="api_button_apiTableEditApi"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !props.row.is_builtin && !props.row.count && !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !props.row.is_builtin && !props.row.count && !hasPermission(targetPerms, curPerms) }"
:title="$t(`m.systemConfig['编辑']`)"
:disabled="props.row.is_builtin || !!props.row.count"
@click="entryOne(props.row)">
{{ $t('m.systemConfig["编辑"]') }}
</bk-button>
<bk-button theme="primary" text
data-test-id="api_button_apiTableDeleteApi"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !props.row.is_builtin && !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !props.row.is_builtin && !hasPermission(targetPerms, curPerms) }"
:title="$t(`m.systemConfig['移除']`)"
:disabled="props.row.is_builtin"
@click="openDelete(props.row)">
Expand Down Expand Up @@ -309,17 +309,18 @@
disableImport() {
return Number(this.remoteSystem) === 0;
},
},
watch: {
},
mounted() {

targetPerms() {
return this.projectId ? ['system_settings_manage'] : ['public_apis_manage'];
},
curPerms() {
return this.projectId ? this.$store.state.project.projectAuthActions : this.$store.state.common.systemPermission;
},
},
methods: {
async entryOne(item) {
// 公共api
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
return;
}
this.$parent.displayInfo.level_1 = item;
Expand All @@ -344,20 +345,23 @@
changTitle(item, index) {
this.checkIndex = index;
},
applyProjectManagePerm() {
const projectInfo = this.$store.state.project.projectInfo;
const resourceData = {
project: [{
id: projectInfo.key,
name: projectInfo.name,
}],
};
this.applyForPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions, resourceData);
applyPerm() {
let resourceData = {};
if (this.projectId) {
const projectInfo = this.$store.state.project.projectInfo;
resourceData = {
project: [{
id: projectInfo.key,
name: projectInfo.name,
}],
};
}
this.applyForPermission(this.targetPerms, this.curPerms, resourceData);
},
// 新增
openShade(type) {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
} else {
this.typeInfo = type;
this.entryInfo.title = type === 'ADD'
Expand Down Expand Up @@ -413,14 +417,14 @@
},
disabledFn(item) {
if (!this.projectId) {
return this.hasPermission(['public_api_manage'], item.auth_actions) && !item.is_builtin;
return this.hasPermission(this.targetPerms, this.curPerms) && !item.is_builtin;
}
return !item.is_builtin;
},
// 二次弹窗确认
openDelete(item) {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
return;
}
this.$bkInfo({
Expand Down Expand Up @@ -450,8 +454,8 @@
});
},
deleteCheck() {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
return;
}
this.$bkInfo({
Expand Down Expand Up @@ -482,8 +486,8 @@
},
//
hasImportPermission() {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
}
},
// 上传文件模板
Expand Down
57 changes: 31 additions & 26 deletions frontend/pc/src/views/processManagement/apiConfigure/apiTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<li>
<a href="javascript:;"
data-test-id="api_a_accessApi"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
:title="$t(`m.systemConfig['系统接入']`)"
@click="openDictionary('JION')">
{{ $t(`m.systemConfig['系统接入']`) }}
Expand All @@ -52,8 +52,8 @@
<li>
<a href="javascript:;"
data-test-id="api_a_createApi"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
:title="$t(`m.systemConfig['系统新增']`)"
@click="openDictionary('ADD')">
{{$t(`m.systemConfig['系统新增']`)}}
Expand Down Expand Up @@ -90,15 +90,15 @@
<li
v-if="!item.is_builtin"
data-test-id="api_li_deleteApiDirectory"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
@click.stop="openDelete(item)">
<span>{{ $t('m.systemConfig["删除"]') }}</span>
</li>
<li
data-test-id="api_li_editApiDirectory"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
v-cursor="{ active: !hasPermission(targetPerms, curPerms) }"
:class="{ 'text-permission-disable': !hasPermission(targetPerms, curPerms) }"
@click.stop="openDictionary('CHANGE' ,item)">
<span>{{ $t('m.systemConfig["编辑"]') }}</span>
</li>
Expand Down Expand Up @@ -320,6 +320,12 @@
});
},
},
targetPerms() {
return this.projectId ? ['system_settings_manage'] : ['public_apis_manage'];
},
curPerms() {
return this.projectId ? this.$store.state.project.projectAuthActions : this.$store.state.common.systemPermission;
},
},
async mounted() {
await this.treeListOri;
Expand Down Expand Up @@ -443,15 +449,8 @@
});
},
openDictionary(type, item) {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
const projectInfo = this.$store.state.project.projectInfo;
const resourceData = {
project: [{
id: projectInfo.key,
name: projectInfo.name,
}],
};
this.applyForPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions, resourceData);
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
return;
}
this.dictDataTable.showDialog = true;
Expand Down Expand Up @@ -484,15 +483,8 @@
},
// 二次弹窗确认
openDelete(item) {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
const projectInfo = this.$store.state.project.projectInfo;
const resourceData = {
project: [{
id: projectInfo.key,
name: projectInfo.name,
}],
};
this.applyForPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions, resourceData);
if (!this.hasPermission(this.targetPerms, this.curPerms)) {
this.applyPerm();
return;
}
this.$bkInfo({
Expand Down Expand Up @@ -521,6 +513,19 @@
},
});
},
applyPerm() {
let resourceData = {};
if (this.projectId) {
const projectInfo = this.$store.state.project.projectInfo;
resourceData = {
project: [{
id: projectInfo.key,
name: projectInfo.name,
}],
};
}
this.applyForPermission(this.targetPerms, this.curPerms, resourceData);
},
},
};
</script>
Expand Down
11 changes: 7 additions & 4 deletions frontend/pc/src/views/processManagement/publicField/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,17 @@
}
return status;
},
viewFieldPerm() {
return this.projectId ? ['field_view'] : ['public_fields_manage'];
},
createFieldPerm() {
return this.projectId ? ['field_create'] : ['public_field_create'];
return this.projectId ? ['field_create'] : ['public_fields_manage'];
},
editFieldPerm() {
return this.projectId ? ['field_edit'] : ['public_field_edit'];
return this.projectId ? ['field_edit'] : ['public_fields_manage'];
},
deleteFieldPerm() {
return this.projectId ? ['field_delete'] : ['public_field_delete'];
return this.projectId ? ['field_delete'] : ['public_fields_manage'];
},
sliderStatus() {
return this.$store.state.common.slideStatus;
Expand All @@ -395,7 +398,7 @@
return this.$store.state.common.configurInfo;
},
curPermission() {
return this.projectId ? this.$store.state.project.projectAuthActions : [];
return this.projectId ? this.$store.state.project.projectAuthActions : this.$store.state.common.systemPermission;
},
},
mounted() {
Expand Down
Loading

0 comments on commit 04aee82

Please sign in to comment.