Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: 项目管理鉴权优化 #1414

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/pc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
window.BK_SHARED_RES_URL = "{{BK_SHARED_RES_URL}}"
window.BK_PLATFORM_NAME = "{{BK_PLATFORM_NAME}}"
window.VERSION = "{{VERSION}}"
window.BKAPP_CSRF_COOKIE_NAME = "{{BKAPP_CSRF_COOKIE_NAME}}"
</script>
<script>
var isMobileDevice = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,18 +241,19 @@
}
const id = this.ticketInfo.comment_id;

this.$emit('beforeSubmit');
this.$emit('updatePendingStatus', true);
this.$store.dispatch('evaluation/postEvaluation', { params, id }).then(() => {
this.$emit('submitSuccess');
this.$bkMessage({
message: this.$t('m.newCommon["评价成功"]'),
theme: 'success',
});
})
.catch((res) => {
this.$emit('updatePendingStatus', false);
errorHandler(res, this);
})
.finally(() => {
this.$emit('submitSuccess');
this.scoreInfo.clickSecond = false;
});
},
Expand Down Expand Up @@ -336,7 +337,7 @@
id = this.ticketInfo.id;
}

this.$emit('beforeSubmit');
this.$emit('updatePendingStatus', true);
this.$store.dispatch(url, { params, id }).then(() => {
this.$bkMessage({
message: this.$t('m.newCommon["发送成功"]'),
Expand All @@ -345,6 +346,7 @@
this.$emit('submitSuccess');
})
.catch(() => {
this.$emit('updatePendingStatus', false);
errorHandler(this);
})
.finally(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
:satisfact-info="satisfactInfo"
:ticket-info="ticketInfo"
:is-show-submit-btn="false"
@beforeSubmit="onBeforeSubmit"
@updatePendingStatus="onUpdatePendingStatus"
@submitSuccess="onSubmitSuccess">
</evaluation-ticket-content>
</div>
Expand Down Expand Up @@ -117,8 +117,8 @@
this.submitting = false;
this.$emit('submitSuccess');
},
onBeforeSubmit() {
this.submitting = true;
onUpdatePendingStatus(status = true) {
this.submitting = status;
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion frontend/pc/src/utils/ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const instance = axios.create({
// `headers` are custom headers to be sent
headers: { 'X-Requested-With': 'XMLHttpRequest' },
// csrftoken变量名
xsrfCookieName: 'bkitsm_csrftoken',
xsrfCookieName: `${window.BKAPP_CSRF_COOKIE_NAME}_csrftoken`,
// cookie中的csrftoken信息名称
xsrfHeaderName: 'X-CSRFToken',
withCredentials: true,
Expand Down
78 changes: 30 additions & 48 deletions frontend/pc/src/views/processManagement/apiConfigure/apiTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@
{{$t(`m.systemConfig['导入']`)}}
</bk-button>
<bk-button :theme="'default'"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
data-test-id="api_button_apiTableBatchDeleteApi"
class="mr10 batch-remove-btn"
:class="['mr10 batch-remove-btn', { 'btn-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }]"
:title="$t(`m.systemConfig['批量移除']`)"
:disabled="!checkList.length"
@click="deleteCheck">
Expand Down Expand Up @@ -110,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: !projectId && !hasPermission(['public_api_manage'], props.row.auth_actions) }"
:class="{ 'text-permission-disable': !projectId && !hasPermission(['public_api_manage'], props.row.auth_actions) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:title="props.row.name"
@click="entryOne(props.row)">
{{props.row.name || '--'}}
Expand Down Expand Up @@ -162,22 +163,17 @@
</bk-button>
<bk-button theme="primary" text
data-test-id="api_button_apiTableEditApi"
v-cursor="{ active: !projectId
&& !hasPermission(['public_api_manage'], props.row.auth_actions) }"
:class="{ 'text-permission-disable': !projectId
&& !hasPermission(['public_api_manage'], props.row.auth_actions) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:title="$t(`m.systemConfig['编辑']`)"
:disabled="(projectId || hasPermission(['public_api_manage'], props.row.auth_actions))
&& (props.row.is_builtin || !!props.row.count)"
: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: !projectId
&& !hasPermission(['public_api_manage'], props.row.auth_actions) }"
:class="{ 'text-permission-disable': !projectId
&& !hasPermission(['public_api_manage'], props.row.auth_actions) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:title="$t(`m.systemConfig['移除']`)"
:disabled="props.row.is_builtin"
@click="openDelete(props.row)">
Expand Down Expand Up @@ -322,14 +318,8 @@
methods: {
async entryOne(item) {
// 公共api
if (!this.projectId && !this.hasPermission(['public_api_manage'], item.auth_actions)) {
const resourceData = {
public_api: [{
id: item.id,
name: item.name,
}],
};
this.applyForPermission(['public_api_manage'], item.auth_actions, resourceData);
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
return;
}
this.$parent.displayInfo.level_1 = item;
Expand All @@ -354,17 +344,20 @@
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);
},
// 新增
openShade(type) {
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);
this.applyProjectManagePerm();
} else {
this.typeInfo = type;
this.entryInfo.title = type === 'ADD'
Expand Down Expand Up @@ -426,17 +419,9 @@
},
// 二次弹窗确认
openDelete(item) {
if (!this.projectId) {
if (!this.hasPermission(['public_api_manage'], item.auth_actions)) {
const resourceData = {
public_api: [{
id: item.id,
name: item.name,
}],
};
this.applyForPermission(['public_api_manage'], item.auth_actions, resourceData);
return;
}
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
return;
}
this.$bkInfo({
type: 'warning',
Expand Down Expand Up @@ -465,6 +450,10 @@
});
},
deleteCheck() {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectManagePerm();
return;
}
this.$bkInfo({
type: 'warning',
title: this.$t('m.systemConfig["确认移除服务?"]'),
Expand Down Expand Up @@ -494,14 +483,7 @@
//
hasImportPermission() {
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);
this.applyProjectManagePerm();
}
},
// 上传文件模板
Expand Down
56 changes: 29 additions & 27 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: !projectId && !hasPermission(['public_api_create']) }"
:class="{ 'text-permission-disable': !projectId && !hasPermission(['public_api_create']) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
: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: !projectId && !hasPermission(['public_api_create']) }"
:class="{ 'text-permission-disable': !projectId && !hasPermission(['public_api_create']) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
: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: !projectId && hasPermission(['public_api_manage']) }"
:class="{ 'text-permission-disable': !projectId && hasPermission(['public_api_manage']) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
@click.stop="openDelete(item)">
<span>{{ $t('m.systemConfig["删除"]') }}</span>
</li>
<li
data-test-id="api_li_editApiDirectory"
v-cursor="{ active: !projectId && hasPermission(['public_api_manage']) }"
:class="{ 'text-permission-disable': !projectId && hasPermission(['public_api_manage']) }"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
@click.stop="openDictionary('CHANGE' ,item)">
<span>{{ $t('m.systemConfig["编辑"]') }}</span>
</li>
Expand Down Expand Up @@ -443,24 +443,16 @@
});
},
openDictionary(type, item) {
if (!this.projectId) {
let reqPerm = ['public_api_create'];
let crtPerm = [];
let resourceData = {};
if (!['JION', 'ADD'].includes(type)) {
reqPerm = ['public_api_manage'];
crtPerm = item.auth_actions;
resourceData = {
public_api: [{
id: item.id,
name: item.name,
}],
};
}
if (crtPerm && !this.hasPermission(reqPerm, crtPerm)) {
this.applyForPermission(reqPerm, crtPerm, resourceData);
return;
}
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);
return;
}
this.dictDataTable.showDialog = true;
this.dictDataTable.type = type;
Expand Down Expand Up @@ -492,6 +484,17 @@
},
// 二次弹窗确认
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);
return;
}
this.$bkInfo({
type: 'warning',
title: this.$t('m.systemConfig["确认移除系统?"]'),
Expand Down Expand Up @@ -551,7 +554,6 @@
.bk-group-li {
color: #4b8fff;
background-color: #e1ecff;

}

.bk-group-name {
Expand Down
31 changes: 30 additions & 1 deletion frontend/pc/src/views/project/notice.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
</li>
</ul>
<div class="bk-only-btn">
<bk-button theme="primary"
<bk-button
data-test-id="notice_button_create"
theme="primary"
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'btn-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
@click="addNotice">
<i class="bk-itsm-icon icon-itsm-icon-one-five"></i>
{{ $t(`m.deployPage['新增']`) }}
Expand Down Expand Up @@ -45,12 +48,16 @@
<bk-table-column :label="$t(`m.deployPage['操作']`)" width="150">
<template slot-scope="props">
<bk-button
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
theme="primary"
text
@click="editNotice(props.row)">
{{ $t('m.deployPage["编辑"]') }}
</bk-button>
<bk-button
v-cursor="{ active: !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
:class="{ 'text-permission-disable': !hasPermission(['system_settings_manage'], $store.state.project.projectAuthActions) }"
theme="primary"
text
@click="deleteNotice(props.row)">
Expand Down Expand Up @@ -314,10 +321,18 @@
},
// 新增配置
addNotice() {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectPerm();
return;
}
this.isEdit = false;
this.isShowEdit = true;
},
editNotice(row) {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectPerm();
return;
}
this.editNoticeId = row.id;
this.formData.noticeUserBy = row.used_by;
this.handleSelectUserBy(row.used_by);
Expand All @@ -330,6 +345,10 @@
this.isShowEdit = true;
},
deleteNotice(row) {
if (!this.hasPermission(['system_settings_manage'], this.$store.state.project.projectAuthActions)) {
this.applyProjectPerm();
return;
}
this.$bkInfo({
title: this.$t('m["确认要删除?"]'),
confirmLoading: true,
Expand All @@ -347,6 +366,16 @@
closeEditor() {
this.isShowEdit = false;
},
applyProjectPerm() {
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);
},
},
};

Expand Down
Loading
Loading