Skip to content

Commit 22e3bc1

Browse files
committed
feat: Model permission
1 parent dca48d1 commit 22e3bc1

File tree

5 files changed

+97
-44
lines changed

5 files changed

+97
-44
lines changed

ui/src/permission/model/system-manage.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,16 @@ const workspace = {
66
hasPermission(
77
new ComplexPermission(
88
[RoleConst.ADMIN],
9-
[PermissionConst.SHARED_TOOL_READ],
9+
[PermissionConst.MODEL_READ],
1010
[EditionConst.IS_EE],
1111
'OR',
1212
),
1313
'OR',
1414
),
15-
delete: () =>
16-
hasPermission(
17-
[
18-
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
19-
RoleConst.USER.getWorkspaceRole,
20-
PermissionConst.TOOL_DELETE.getWorkspacePermission,
21-
],
22-
'OR',
23-
),
15+
addModel: () => false,
16+
modify: () => false,
17+
paramSetting: () => false,
18+
delete: () => false,
2419
}
2520

2621
export default workspace

ui/src/permission/model/system-share.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ import { ComplexPermission } from '@/utils/permission/type'
33
import { EditionConst, PermissionConst, RoleConst } from '@/utils/permission/data'
44
const share = {
55
is_share: () => false,
6+
addModel: () => false,
7+
modify: () => false,
8+
paramSetting: () => false,
9+
delete: () => false,
10+
611
}
712
export default share

ui/src/permission/model/workspace.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,52 @@ const workspace = {
66
hasPermission(
77
new ComplexPermission(
88
[RoleConst.ADMIN],
9-
[PermissionConst.SHARED_TOOL_READ],
9+
[PermissionConst.MODEL_READ],
1010
[EditionConst.IS_EE],
1111
'OR',
1212
),
1313
'OR',
1414
),
15+
addModel: () =>
16+
hasPermission(
17+
[
18+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
19+
RoleConst.USER.getWorkspaceRole,
20+
PermissionConst.MODEL_CREATE.getWorkspacePermission,
21+
PermissionConst.MODEL_CREATE.getWorkspacePermissionWorkspaceManageRole
22+
],
23+
'OR'
24+
),
25+
modify: () =>
26+
hasPermission(
27+
[
28+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
29+
RoleConst.USER.getWorkspaceRole,
30+
PermissionConst.MODEL_EDIT.getWorkspacePermission,
31+
PermissionConst.MODEL_EDIT.getWorkspacePermissionWorkspaceManageRole
32+
],
33+
'OR'
34+
),
35+
paramSetting: () =>
36+
hasPermission(
37+
[
38+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
39+
RoleConst.USER.getWorkspaceRole,
40+
PermissionConst.MODEL_EDIT.getWorkspacePermission,
41+
PermissionConst.MODEL_EDIT.getWorkspacePermissionWorkspaceManageRole
42+
],
43+
'OR'
44+
),
45+
delete: () =>
46+
hasPermission(
47+
[
48+
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
49+
RoleConst.USER.getWorkspaceRole,
50+
PermissionConst.MODEL_DELETE.getWorkspacePermission,
51+
PermissionConst.MODEL_DELETE.getWorkspacePermissionWorkspaceManageRole
52+
],
53+
'OR'
54+
),
1555
}
1656

1757
export default workspace

ui/src/views/model/component/ModelCard.vue

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,7 @@
7777
<template #dropdown>
7878
<el-dropdown-menu>
7979
<el-dropdown-item
80-
v-if="
81-
hasPermission(
82-
[
83-
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
84-
RoleConst.USER.getWorkspaceRole,
85-
PermissionConst.MODEL_EDIT.getWorkspacePermission,
86-
],
87-
'OR',
88-
)
89-
"
80+
v-if="permissionPrecise.modify()"
9081
icon="EditPen"
9182
:disabled="!is_permisstion"
9283
text
@@ -101,14 +92,8 @@
10192
currentModel.model_type === 'LLM' ||
10293
currentModel.model_type === 'IMAGE' ||
10394
currentModel.model_type === 'TTI' ||
104-
hasPermission(
105-
[
106-
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
107-
RoleConst.USER.getWorkspaceRole,
108-
PermissionConst.MODEL_EDIT.getWorkspacePermission,
109-
],
110-
'OR',
111-
)
95+
permissionPrecise.paramSetting()
96+
11297
"
11398
:disabled="!is_permisstion"
11499
icon="Setting"
@@ -123,14 +108,7 @@
123108
text
124109
@click.stop="deleteModel"
125110
v-if="
126-
hasPermission(
127-
[
128-
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
129-
RoleConst.USER.getWorkspaceRole,
130-
PermissionConst.MODEL_DELETE.getWorkspacePermission,
131-
],
132-
'OR',
133-
)
111+
permissionPrecise.delete()
134112
"
135113
>
136114
{{ $t('common.delete') }}
@@ -156,6 +134,24 @@ import ParamSettingDialog from './ParamSettingDialog.vue'
156134
import { t } from '@/locales'
157135
import { PermissionConst, RoleConst } from '@/utils/permission/data'
158136
import { hasPermission } from '@/utils/permission'
137+
import { useRoute } from 'vue-router'
138+
import permissionMap from '@/permission'
139+
140+
141+
const route = useRoute()
142+
143+
const type = computed(() => {
144+
if (route.path.includes('shared')) {
145+
return 'systemShare'
146+
} else if (route.path.includes('resource-management')) {
147+
return 'systemManage'
148+
} else {
149+
return 'workspace'
150+
}
151+
})
152+
const permissionPrecise = computed(() => {
153+
return permissionMap['model'][type.value]
154+
})
159155
160156
const props = defineProps<{
161157
model: Model

ui/src/views/model/index.vue

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@click="clickListHandle"
88
:loading="loading"
99
shareTitle="views.system.share_tool"
10-
isShared
10+
:showShared="permissionPrecise['is_share']()"
1111
:active="active_provider"
1212
/>
1313
</template>
@@ -55,15 +55,12 @@
5555
</el-select>
5656
</div>
5757
<el-button
58-
v-if="!isShared"
58+
v-if="!isShared &&
59+
permissionPrecise.addModel()
60+
"
5961
class="ml-16"
6062
type="primary"
6163
@click="openCreateModel(active_provider)"
62-
v-hasPermission="[
63-
RoleConst.WORKSPACE_MANAGE.getWorkspaceRole,
64-
RoleConst.USER.getWorkspaceRole,
65-
PermissionConst.MODEL_CREATE.getWorkspacePermission,
66-
]"
6764
>
6865
{{ $t('views.model.addModel') }}
6966
</el-button>
@@ -128,6 +125,26 @@ import SelectProviderDialog from '@/views/model/component/SelectProviderDialog.v
128125
import { t } from '@/locales'
129126
import { PermissionConst, RoleConst } from '@/utils/permission/data'
130127
import { loadSharedApi } from '@/utils/dynamics-api/shared-api'
128+
import { useRoute } from 'vue-router'
129+
import useStore from '@/stores'
130+
import permissionMap from '@/permission'
131+
132+
133+
const route = useRoute()
134+
const { folder, user } = useStore()
135+
136+
const type = computed(() => {
137+
if (route.path.includes('shared')) {
138+
return 'systemShare'
139+
} else if (route.path.includes('resource-management')) {
140+
return 'systemManage'
141+
} else {
142+
return 'workspace'
143+
}
144+
})
145+
const permissionPrecise = computed(() => {
146+
return permissionMap['model'][type.value]
147+
})
131148
132149
const commonList1 = ref()
133150
const commonList2 = ref()

0 commit comments

Comments
 (0)