Skip to content

Commit

Permalink
fix(backend): 权限体验问题修复 #3605
Browse files Browse the repository at this point in the history
  • Loading branch information
hLinx authored and zhangzhw8 committed Apr 10, 2024
1 parent 66fb5f1 commit c8cc9f0
Show file tree
Hide file tree
Showing 46 changed files with 916 additions and 715 deletions.
89 changes: 51 additions & 38 deletions dbm-ui/frontend/src/components/apply-items/BusinessItems.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,41 @@
:label="t('所属业务')"
property="bk_biz_id"
required>
<AppSelect
:data="withFavorBizList"
:generate-key="(item: IAppItem) => item.bk_biz_id"
:generate-name="(item: IAppItem) => item.display_name"
style="width: 435px"
:value="currentBiz"
@change="handleAppChange">
<template #default="{ data }">
<AuthTemplate
:action-id="perrmisionActionId"
:biz-id="data.bk_biz_id"
:permission="data.permission.db_manage"
:resource="data.bk_biz_id"
style="width: 100%">
<div class="db-app-select-item">
<div>{{ data.name }} (#{{ data.bk_biz_id }})</div>
<div style="margin-left: auto">
<DbIcon
v-if="favorBizIdMap[data.bk_biz_id]"
class="unfavor-btn"
style="color: #ffb848"
type="star-fill"
@click.stop="handleUnfavor(data.bk_biz_id)" />
<DbIcon
v-else
class="favor-btn"
type="star"
@click.stop="handleFavor(data.bk_biz_id)" />
<BkLoading :loading="isBizLoading">
<AppSelect
:data="withFavorBizList"
:generate-key="(item: IAppItem) => item.bk_biz_id"
:generate-name="(item: IAppItem) => item.display_name"
style="width: 435px"
:value="currentBiz"
@change="handleAppChange">
<template #default="{ data }">
<AuthTemplate
:action-id="perrmisionActionId"
:biz-id="data.bk_biz_id"
:permission="data.permission[perrmisionActionId]"
:resource="data.bk_biz_id"
style="width: 100%">
<div class="db-app-select-item">
<div>{{ data.name }} (#{{ data.bk_biz_id }})</div>
<div style="margin-left: auto">
<DbIcon
v-if="favorBizIdMap[data.bk_biz_id]"
class="unfavor-btn"
style="color: #ffb848"
type="star-fill"
@click.stop="handleUnfavor(data.bk_biz_id)" />
<DbIcon
v-else
class="favor-btn"
type="star"
@click.stop="handleFavor(data.bk_biz_id)" />
</div>
</div>
</div>
</AuthTemplate>
</template>
</AppSelect>
</AuthTemplate>
</template>
</AppSelect>
</BkLoading>
</BkFormItem>
<BkFormItem
ref="appAbbrRef"
Expand All @@ -74,12 +76,13 @@
<script setup lang="ts">
import _ from 'lodash';
import { useI18n } from 'vue-i18n';
import { useRequest } from 'vue-request';
import { useRoute } from 'vue-router';

import { getBizs } from '@services/source/cmdb';
import type { BizItem } from '@services/types';

import { useGlobalBizs, useUserProfile } from '@stores';
import { useUserProfile } from '@stores';

import { UserPersonalSettings } from '@common/const';
import { nameRegx } from '@common/regex';
Expand All @@ -94,7 +97,7 @@
perrmisionActionId: string;
}

defineProps<Props>();
const props = defineProps<Props>();

const emits = defineEmits<Emits>();

Expand All @@ -113,14 +116,15 @@
const { t } = useI18n();

const route = useRoute();
const { bizs: bizList } = useGlobalBizs();
const userProfile = useUserProfile();

const bizList = shallowRef<IAppItem[]>([]);
const currentBiz = shallowRef<IAppItem>();
const favorBizIdMap = shallowRef(makeMap(userProfile.profile[UserPersonalSettings.APP_FAVOR] || []));
const hasEnglishName = ref(false);
const appAbbrRef = ref();

const withFavorBizList = computed(() => _.sortBy(bizList, (item) => favorBizIdMap.value[item.bk_biz_id]));
const withFavorBizList = computed(() => _.sortBy(bizList.value, (item) => favorBizIdMap.value[item.bk_biz_id]));

const dbAppAbbrPlaceholder = t('以小写英文字母开头_且只能包含英文字母_数字_连字符');

Expand All @@ -142,7 +146,16 @@
},
];

const appAbbrRef = ref();
const { loading: isBizLoading } = useRequest(getBizs, {
defaultParams: [
{
action: props.perrmisionActionId,
},
],
onSuccess(result) {
bizList.value = result;
},
});

watch(
route,
Expand All @@ -160,7 +173,7 @@
watch(
bizId,
() => {
currentBiz.value = _.find(bizList, (item) => item.bk_biz_id === bizId.value);
currentBiz.value = _.find(bizList.value, (item) => item.bk_biz_id === bizId.value);
const englishName = currentBiz.value?.english_name;
hasEnglishName.value = !!englishName;
appAbbr.value = englishName ?? '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<table>
<thead>
<tr>
<th>{{ t('系统') }}</th>
<th>{{ t('需要申请的权限') }}</th>
<th style="min-width: 120px">{{ t('系统') }}</th>
<th style="min-width: 150px">{{ t('需要申请的权限') }}</th>
<th>{{ t('关联的资源实例') }}</th>
</tr>
</thead>
Expand All @@ -41,7 +41,7 @@
<p
v-for="(resourceItem, rindex) in permissionItem.relatedResources"
:key="rindex">
{{ resourceItem.type }}-{{ resourceItem.instances.join(',') }}
{{ resourceItem.type }}:{{ resourceItem.instances.join(',') }}
</p>
<p v-if="permissionItem.relatedResources.length < 1">--</p>
</td>
Expand Down
24 changes: 11 additions & 13 deletions dbm-ui/frontend/src/components/auth-component/button.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@
v-bind="attrs">
<slot />
</BkButton>
<span
<BkButton
v-else
disabled>
<BkButton
v-cursor
class="auth-button-disable"
v-bind="inheritAttrs"
:disabled="false"
:loading="loading"
@click.stop="handleRequestPermission">
<slot />
</BkButton>
</span>
v-cursor
class="auth-button-disable"
v-bind="inheritAttrs"
:disabled="false"
:loading="loading"
@click.stop="handleRequestPermission">
<slot />
</BkButton>
</template>
<script setup lang="ts">
import { useAttrs } from 'vue';
Expand All @@ -38,6 +35,7 @@
resource: '',
bizId: undefined,
});
defineOptions({
inheritAttrs: false,
});
Expand All @@ -63,7 +61,7 @@
background-color: transparent !important;
border-color: transparent !important;
.bk-button-text {
* {
color: #c4c6cc !important;
}
}
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/frontend/src/layout/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
'PlatformDbConfigure',
'PlatformWhitelist',
'PlatGlobalStrategy',
'PlatRotateSet',
'dutyRuleManange',
// 'PlatMonitorAlarmGroup',
'passwordManage',
'PlatformTicketFlowSetting',
Expand Down
2 changes: 1 addition & 1 deletion dbm-ui/frontend/src/layout/components/PlatformManage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<FunController
controller-id="duty_rule"
module-id="monitor">
<BkMenuItem key="PlatRotateSet">
<BkMenuItem key="dutyRuleManange">
<template #icon>
<DbIcon type="db-config" />
</template>
Expand Down
2 changes: 2 additions & 0 deletions dbm-ui/frontend/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
import BizPermission from '@views/BizPermission.vue';
import getDbConfRoutes from '@views/db-configure/routes';
import getDbhaSwitchEventsRouters from '@views/dbha-switch-events/routes';
import getDutyRuleManageRoutes from '@views/duty-rule-manage/routes'
import getESRoutes from '@views/es-manage/routes';
import getHDFSRoutes from '@views/hdfs-manage/routes';
import getInfluxDBRoutes from '@views/influxdb-manage/routes';
Expand Down Expand Up @@ -131,6 +132,7 @@ export default () => {
...getServiceApplyRoutes(),
...getQuickSearchRoutes(),
...getTicketsRoutes(),
...getDutyRuleManageRoutes()
],
},
{
Expand Down
10 changes: 5 additions & 5 deletions dbm-ui/frontend/src/services/model/es/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ export default class Es {
title: string;
}>;
permission: {
es_view: boolean;
es_enable_disable: boolean;
access_entry_edit: boolean;
es_destroy: boolean;
es_enable_disable: boolean;
es_reboot: boolean;
es_replace: boolean;
es_scale_up: boolean;
es_shrink: boolean;
es_replace: boolean;
es_reboot: boolean;
access_entry_edit: boolean;
es_view: boolean;
};
phase: 'online' | 'offline';
region: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class FunctionController {
const item = this[key] as ControllerItem<T>;

if (!item) {
return {};
return {} as Record<T | K, boolean>;
}

const flatData = {
Expand Down
6 changes: 6 additions & 0 deletions dbm-ui/frontend/src/services/model/monitor/duty-rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ export default class DutyRule {
is_enabled: boolean;
is_show_edit: boolean;
name: string;
permission: {
duty_rule_create: boolean;
duty_rule_destroy: boolean;
duty_rule_update: boolean;
};
priority: number;
status: string;
updater: string;
Expand All @@ -58,6 +63,7 @@ export default class DutyRule {
this.is_show_edit = false;
this.end_time = payload.end_time;
this.name = payload.name;
this.permission = payload.permission;
this.priority = payload.priority;
this.updater = payload.updater;
this.update_at = payload.update_at;
Expand Down
3 changes: 1 addition & 2 deletions dbm-ui/frontend/src/services/model/mysql/tendbha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,10 @@ export default class Tendbha {
title: string;
}>;
permission: {
mysql_authorize_rules: boolean;
access_entry_edit: boolean;
mysql_destroy: boolean;
mysql_enable_disable: boolean;
mysql_view: boolean;
access_entry_edit: boolean;
tbinlogdumper_install: boolean;
};
phase: string;
Expand Down
1 change: 0 additions & 1 deletion dbm-ui/frontend/src/services/model/mysql/tendbsingle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default class Tendbsingle {
title: string;
}>;
permission: {
mysql_authorize_rules: boolean;
mysql_destroy: boolean;
mysql_enable_disable: boolean;
mysql_view: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ export default class NoticGroup {
updater: string;
used_count: number;
permission: {
global_notify_group_create: boolean;
global_notify_group_delete: boolean;
global_notify_group_update: boolean;
notify_group_create: boolean;
notify_group_delete: boolean;
Expand Down
1 change: 1 addition & 0 deletions dbm-ui/frontend/src/services/model/partition/partition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class Partition {
mysql_partition_delete: boolean;
mysql_partition_enable_disable: boolean;
mysql_partition_update: boolean;
tendbcluster_partition: boolean;
tendb_partition_enable_disable: boolean;
tendbcluster_partition_create: boolean;
tendbcluster_partition_delete: boolean;
Expand Down
7 changes: 6 additions & 1 deletion dbm-ui/frontend/src/services/model/spider/tendbCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ export default class TendbCluster {
operationDisabled: boolean;
}>;
permission: {
tendbcluster_enable_disable: boolean;
tendbcluster_destroy: boolean;
tendbcluster_enable_disable: boolean;
tendbcluster_node_rebalance: boolean;
tendbcluster_spider_add_nodes: boolean;
tendbcluster_spider_mnt_destroy: boolean;
tendbcluster_spider_reduce_nodes: boolean;
tendbcluster_view: boolean;
tendb_spider_slave_destroy: boolean;
access_entry_edit: boolean;
};
phase: 'online' | 'offline';
Expand Down
37 changes: 27 additions & 10 deletions dbm-ui/frontend/src/services/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import type {
PermissionCloneRes,
PermissionRule,
PermissionRulesParams,
PermissionRulesResult,
} from './types/permission';

// 密码随机化周期
Expand Down Expand Up @@ -159,16 +158,34 @@ export const verifyPasswordStrength = (params: { password: string }) =>
/**
* 查询账号规则列表
*/
export const getPermissionRules = (params: PermissionRulesParams) =>
export const getPermissionRules = (params: PermissionRulesParams, payload = {} as IRequestPayload) =>
http
.get<PermissionRulesResult>(`/apis/mysql/bizs/${params.bk_biz_id}/permission/account/list_account_rules/`, params)
.then((data) => ({
...data,
results: data.results.map((item) => ({
...item,
permission: data.permission || {},
})),
}));
.get<{
count: number;
results: {
account: {
account_id: number;
bk_biz_id: number;
create_time: string;
creator: string;
user: string;
};
permission: {
mysql_account_delete: boolean;
mysql_add_account_rule: boolean;
};
rules: {
access_db: string;
account_id: number;
bk_biz_id: number;
create_time: string;
creator: string;
privilege: string;
rule_id: number;
}[];
}[];
}>(`/apis/mysql/bizs/${params.bk_biz_id}/permission/account/list_account_rules/`, params, payload)
.then((data) => data);

/**
* 创建账户
Expand Down
Loading

0 comments on commit c8cc9f0

Please sign in to comment.