Skip to content

Commit

Permalink
Merge pull request #10541 from vhwweng/issue_10356
Browse files Browse the repository at this point in the history
feat:流水线权限代持功能重构 #10356
  • Loading branch information
bkci-bot authored Aug 19, 2024
2 parents dfb651e + c4596bd commit 6cde509
Show file tree
Hide file tree
Showing 8 changed files with 407 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
<template>
<main class="delegation-permission" v-bkloading="{ isLoading }">
<section class="content-warpper">
<header class="header">
<logo class="mr5" name="help-document-fill" size="20" />
{{ $t('delegationPermission') }}
</header>
<div class="content">
<p>{{ $t('delegation.tips1') }}</p>
<i18n
class="mt10"
tag="p"
path="delegation.tips2">
<span class="highlight">{{ $t('delegation.pipelineExecPermission') }}</span>
</i18n>
<i18n
tag="p"
path="delegation.tips3">
<span class="highlight">{{ 'BK_CI_START_USER_ID' }}</span>
</i18n>
<p class="mt20">{{ $t('delegation.tips4') }}</p>
<i18n
tag="p"
path="delegation.tips5">
<span class="highlight">{{ $t('delegation.newOperator') }}</span>
</i18n>
</div>
</section>

<section class="mt30">
<div class="panel-content">
<p>
<label class="block-row-label">{{ $t('delegation.proxyHolderForExecutionPermissions') }}</label>
<span
:class="{
'block-row-value': true,
'reset-row': !resourceAuthData.executePermission
}">
<span
:class="{
'name': true,
'not-permission': !resourceAuthData.executePermission
}"
v-bk-tooltips="{
content: $t('delegation.expiredTips'),
disabled: resourceAuthData.executePermission
}"
>
{{ resourceAuthData.handoverFrom }}
</span>
<bk-tag theme="danger" v-if="!resourceAuthData?.executePermission && !isLoading">{{ $t('delegation.expired') }}</bk-tag>
<span
class="refresh-auth"
v-perm="{
hasPermission: hasResetPermission,
disablePermissionApi: true,
permissionData: {
projectId,
resourceType: 'pipeline',
resourceCode: pipelineId,
action: RESOURCE_ACTION.MANAGE
}
}"
@click="handleShowResetDialog">
<logo class="refresh-icon" name="refresh" size="14" />
{{ $t('delegation.resetAuthorization') }}
</span>
</span>
</p>
<p>
<label class="block-row-label">{{ $t('delegation.authTime') }}</label>
<span class="block-row-value">{{ convertTime(resourceAuthData.handoverTime) }}</span>
</p>
</div>
</section>

<bk-dialog
ext-cls="reset-auth-confirm-dialog"
:value="showResetDialog"
:show-footer="false"
@value-change="handleToggleShowResetDialog"
>
<span class="close-confirm-title">
{{ $t('delegation.confirmReset') }}
</span>
<span class="close-confirm-tips">
<i18n
tag="p"
path="delegation.resetAuthTips1">
<span class="highlight">{{ $t('delegation.yourPermission') }}</span>
</i18n>
<p>{{ $t('delegation.resetAuthTips2') }}</p>
</span>
<span class="close-confirm-footer">
<bk-button
class="mr10 btn"
theme="primary"
:loading="resetLoading"
@click="handleReset"
>
{{ $t('delegation.reset') }}
</bk-button>
<bk-button
class="btn"
:loading="resetLoading"
@click="showResetDialog = !showResetDialog">
{{ $t('delegation.cancel') }}
</bk-button>
</span>
</bk-dialog>
</main>
</template>

<script>
import Logo from '@/components/Logo'
import { mapActions, mapState } from 'vuex'
import { convertTime } from '@/utils/util'
import {
RESOURCE_ACTION
} from '@/utils/permission'
export default {
components: {
Logo
},
data () {
return {
isLoading: false,
showResetDialog: false,
resetLoading: false,
resourceAuthData: {}
}
},
computed: {
...mapState('atom', ['pipelineInfo']),
hasResetPermission () {
return this.pipelineInfo?.permissions.canManage
},
RESOURCE_ACTION () {
return RESOURCE_ACTION
},
pipelineId () {
return this.pipelineInfo.pipelineId
},
projectId () {
return this.$route.params.projectId
}
},
created () {
this.fetchResourceAuth()
},
methods: {
convertTime,
...mapActions('pipelines', [
'getResourceAuthorization',
'resetPipelineAuthorization'
]),
handleShowResetDialog () {
this.showResetDialog = true
},
handleToggleShowResetDialog (val) {
if (!val) {
this.showResetDialog = false
this.resetLoading = false
}
},
async fetchResourceAuth () {
try {
this.isLoading = true
this.resourceAuthData = await this.getResourceAuthorization({
projectId: this.projectId,
resourceType: 'pipeline',
resourceCode: this.pipelineId
})
} catch (e) {
console.error(e)
} finally {
this.isLoading = false
}
},
async handleReset () {
this.resetLoading = true
try {
this.resetLoading = false
const res = await this.resetPipelineAuthorization({
projectId: this.projectId,
params: {
projectCode: this.projectId,
resourceType: 'pipeline',
handoverChannel: 'OTHER',
resourceAuthorizationHandoverList: [
{
projectCode: this.projectId,
resourceType: 'pipeline',
resourceName: this.resourceAuthData.resourceName,
resourceCode: this.resourceAuthData.resourceCode,
handoverFrom: this.resourceAuthData.handoverFrom,
handoverTo: this.$userInfo.username
}
]
}
})
this.showResetDialog = false
if (res?.FAILED?.length) {
const message = res.FAILED[0]?.handoverFailedMessage || ''
this.$bkMessage({
theme: 'error',
message
})
} else {
this.fetchResourceAuth()
this.$bkMessage({
theme: 'success',
message: this.$t('delegation.resetSuc')
})
}
} catch (e) {
this.resetLoading = false
this.$bkMessage({
theme: 'error',
message: e.message || e
})
}
}
}
}
</script>
<style lang="scss">
.delegation-permission {
padding: 24px;
font-size: 12px;
.content-warpper {
border-radius: 2px;
border: 1px solid #DCDEE5;
}
.header {
display: flex;
align-items: center;
height: 40px;
background-color: #F5F7FA;
padding: 0 16px;
font-size: 14px;
font-weight: 700;
}
.content {
padding: 20px 16px;
line-height: 24px;
color: #63656E;
font-size: 12px;
}
.highlight {
color: #FF9C01;
font-weight: 700;
}
.reset-row {
position: relative;
top: -4px;
.not-permission {
color: #C4C6CC;
text-decoration: line-through;
margin-right: 5px;
}
}
}
.panel-content {
display: grid;
grid-gap: 16px;
grid-template-rows: minmax(18px, auto);
margin-bottom: 32px;
p {
display: grid;
grid-auto-flow: column;
grid-template-columns: 120px 1fr;
align-items: flex-start;
grid-gap: 10px;
font-size: 12px;
color: #63656e;
>label {
text-align: right;
line-height: 18px;
color: #979BA5;
}
}
.refresh-auth {
margin-left: 20px;
cursor: pointer;
color: #3A84FF;
}
.refresh-icon {
position: relative;
top: 2px;
margin-right: 2px;
}
}
.reset-auth-confirm-dialog {
text-align: center;
.bk-dialog-body {
display: flex;
flex-direction: column;
align-items: center;
max-height: calc(50vh - 50px);
}
.close-confirm-title {
font-size: 20px;
color: #313238;
margin-bottom: 15px;
}
.close-confirm-tips {
text-align: left;
color: #63656E;
font-size: 12px;
padding: 10px 20px;
background: #F5F7FA;
span {
color: #FF9C01;
}
}
.close-confirm-footer {
margin-top: 24px;
.btn {
width: 88px;
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import BuildHistoryTab from './BuildHistoryTab'
import ChangeLog from './ChangeLog'
import PipelineConfig from './PipelineConfig'
import TriggerEvent from './TriggerEvent'
import DelegationPermission from './DelegationPermission'

export {
BuildHistoryTab, ChangeLog, PipelineConfig,
TriggerEvent
TriggerEvent, DelegationPermission
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import {
BACKEND_API_URL_PREFIX,
FETCH_ERROR,
PROCESS_API_URL_PREFIX,
STORE_API_URL_PREFIX
STORE_API_URL_PREFIX,
AUTH_URL_PREFIX
} from '@/store/constants'
import ajax from '@/utils/request'

Expand Down Expand Up @@ -414,6 +415,14 @@ const actions = {
// 重新触发事件
reTriggerEvent (_, { projectId, detailId }) {
return ajax.post(`${triggerPrefix}/${projectId}/${detailId}/replay`)
},
getResourceAuthorization (_, { projectId, resourceType, resourceCode }) {
return ajax.get(`${AUTH_URL_PREFIX}/user/auth/authorization/${projectId}/${resourceType}/getResourceAuthorization?resourceCode=${resourceCode}`)
.then(res => res.data)
},
resetPipelineAuthorization (_, { projectId, params }) {
return ajax.post(`${AUTH_URL_PREFIX}/user/auth/authorization/${projectId}/resetResourceAuthorization`, params)
.then(res => res.data)
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/frontend/devops-pipeline/src/utils/permission.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const RESOURCE_ACTION = {
VIEW: 'pipeline_view',
EDIT: 'pipeline_edit',
DOWNLOAD: 'pipeline_download',
DELETE: 'pipeline_delete'
DELETE: 'pipeline_delete',
MANAGE: 'pipeline_manage'
}

export const PROJECT_RESOURCE_ACTION = {
Expand Down
Loading

0 comments on commit 6cde509

Please sign in to comment.