Skip to content

Commit 12c66ae

Browse files
committed
feat: add permission selection for user roles and update related UI components
1 parent e6f0b83 commit 12c66ae

File tree

4 files changed

+66
-18
lines changed

4 files changed

+66
-18
lines changed

apps/locales/en_US/LC_MESSAGES/django.po

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8885,8 +8885,5 @@ msgstr ""
88858885
msgid "Role IDs cannot be empty"
88868886
msgstr ""
88878887

8888-
msgid "Role IDs"
8889-
msgstr ""
8890-
88918888
msgid "Some roles do not exist"
88928889
msgstr ""

apps/locales/zh_CN/LC_MESSAGES/django.po

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9011,8 +9011,5 @@ msgstr "导出知识工作流"
90119011
msgid "Role IDs cannot be empty"
90129012
msgstr "角色 ID 不能为空"
90139013

9014-
msgid "Role IDs"
9015-
msgstr "角色 ID"
9016-
90179014
msgid "Some roles do not exist"
90189015
msgstr "部分角色不存在"

apps/locales/zh_Hant/LC_MESSAGES/django.po

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9011,8 +9011,5 @@ msgstr "匯出知識工作流"
90119011
msgid "Role IDs cannot be empty"
90129012
msgstr "角色 ID 不能为空"
90139013

9014-
msgid "Role IDs"
9015-
msgstr "角色 ID"
9016-
90179014
msgid "Some roles do not exist"
90189015
msgstr "部分角色不存在"

ui/src/views/system-setting/authentication/component/Setting.vue

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,17 @@
111111
]"
112112
>
113113
<el-row :gutter="16" style="margin-left: 10px">
114-
<el-col :span="12">
115-
<div style="display: flex; align-items: center; gap: 8px; min-width: 0">
116-
<span style="font-size: 13px; white-space: nowrap">
114+
<el-col :span="24">
115+
<div class="flex">
116+
<span style="font-size: 13px; white-space: nowrap;width: 50px"
117+
class="text-right mr-8">
117118
{{ $t('views.role.member.role') }}
118119
</span>
119120
<el-select
120121
v-model="form.role_id"
121122
:placeholder="`${$t('common.selectPlaceholder')}${$t('views.role.member.role')}`"
122-
style="flex: 1; min-width: 180px"
123123
@change="handleRoleChange"
124+
class="w-240"
124125
>
125126
<el-option
126127
v-for="role in roleOptions"
@@ -131,15 +132,16 @@
131132
</el-select>
132133
</div>
133134
</el-col>
134-
<el-col :span="12" v-if="user.isEE() && showWorkspaceSelector">
135-
<div style="display: flex; align-items: center; gap: 8px; min-width: 0">
136-
<span style="font-size: 13px; white-space: nowrap">
135+
<el-col :span="24" v-if="user.isEE() && showWorkspaceSelector" class="mt-16">
136+
<div class="flex">
137+
<span style="font-size: 13px; white-space: nowrap;width: 50px"
138+
class="text-right mr-8">
137139
{{ $t('views.role.member.workspace') }}
138140
</span>
139141
<el-select
140142
v-model="form.workspace_id"
141143
:placeholder="`${$t('common.selectPlaceholder')}${$t('views.role.member.workspace')}`"
142-
style="flex: 1; min-width: 180px"
144+
class="w-240"
143145
>
144146
<el-option
145147
v-for="workspace in workspaceOptions"
@@ -150,6 +152,27 @@
150152
</el-select>
151153
</div>
152154
</el-col>
155+
<el-col :span="24" v-if="(user.isEE() || user.isPE()) && showPermissionSelector"
156+
class="mt-16">
157+
<div class="flex">
158+
<span style="font-size: 13px; white-space: nowrap;width: 50px"
159+
class="text-right mr-8">
160+
{{ $t('views.system.resourceAuthorization.title') }}
161+
</span>
162+
<el-select
163+
v-model="form.permission"
164+
:placeholder="`${$t('common.selectPlaceholder')}${$t('views.system.resourceAuthorization.title')}`"
165+
class="w-240"
166+
>
167+
<el-option
168+
v-for="permission in permissionOptions"
169+
:key="permission.value"
170+
:label="permission.label"
171+
:value="permission.value"
172+
/>
173+
</el-select>
174+
</div>
175+
</el-col>
153176
</el-row>
154177
</el-form-item>
155178
</el-form>
@@ -174,13 +197,15 @@
174197
<script setup lang="ts">
175198
import {ref, onMounted, computed} from 'vue'
176199
import {ComplexPermission} from '@/utils/permission/type'
177-
import {PermissionConst, RoleConst} from '@/utils/permission/data'
200+
import {EditionConst, PermissionConst, RoleConst} from '@/utils/permission/data'
178201
import type {FormInstance} from 'element-plus'
179202
import {t} from '@/locales'
180203
import authApi from '@/api/system-settings/auth-setting.ts'
181204
import {MsgSuccess} from '@/utils/message.ts'
182205
import WorkspaceApi from '@/api/workspace/workspace.ts'
183206
import useStore from '@/stores'
207+
import {AuthorizationEnum} from "@/enums/system.ts";
208+
import {hasPermission} from "@/utils/permission";
184209
185210
const loginMethods = ref<Array<{ label: string; value: string }>>([])
186211
const loading = ref(false)
@@ -194,6 +219,7 @@ const form = ref<any>({
194219
lock_time: 10,
195220
role_id: 'USER',
196221
workspace_id: 'default',
222+
permission: 'NOT_AUTH',
197223
})
198224
199225
const normalizeInputValue = (val: number | null): number => {
@@ -234,6 +260,7 @@ const submit = async () => {
234260
lock_time: form.value.lock_time,
235261
role_id: form.value.role_id,
236262
workspace_id: form.value.workspace_id,
263+
permission: form.value.permission,
237264
}
238265
await authApi.putLoginSetting(params)
239266
MsgSuccess(t('common.saveSuccess'))
@@ -250,7 +277,36 @@ const workspaceOptions = ref<Array<{ id: string; name: string }>>([])
250277
const {user} = useStore()
251278
const selectedRoleType = ref<string>('') // 存储选中角色类型,用于控制 workspace 显示
252279
const showWorkspaceSelector = computed(() => selectedRoleType.value !== 'ADMIN')
280+
const showPermissionSelector = computed(() => selectedRoleType.value === 'USER')
281+
const permissionOptions = computed(() => {
282+
const baseOptions = [
283+
{
284+
label: t('views.system.resourceAuthorization.setting.check'),
285+
value: AuthorizationEnum.VIEW,
286+
desc: t('views.system.resourceAuthorization.setting.checkDesc'),
287+
},
288+
{
289+
label: t('views.system.resourceAuthorization.setting.management'),
290+
value: AuthorizationEnum.MANAGE,
291+
desc: t('views.system.resourceAuthorization.setting.managementDesc'),
292+
},
293+
{
294+
label: t('views.system.resourceAuthorization.setting.notAuthorized'),
295+
value: AuthorizationEnum.NOT_AUTH,
296+
desc: '',
297+
}
298+
];
299+
300+
if (hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR')) {
301+
baseOptions.splice(2, 0, {
302+
label: t('views.system.resourceAuthorization.setting.role'),
303+
value: AuthorizationEnum.ROLE,
304+
desc: t('views.system.resourceAuthorization.setting.roleDesc'),
305+
});
306+
}
253307
308+
return baseOptions;
309+
});
254310
// 当角色变更时更新 selectedRoleType
255311
const handleRoleChange = (roleId: string) => {
256312
const selectedRole = roleOptions.value.find((role) => role.id === roleId)
@@ -304,6 +360,7 @@ onMounted(async () => {
304360
lock_time: data.lock_time ?? form.value.lock_time ?? 10,
305361
role_id: data.role_id ?? form.value.role_id ?? 'USER',
306362
workspace_id: data.workspace_id ?? form.value.workspace_id ?? 'default',
363+
permission: data.permission ?? form.value.permission ?? 'NOT_AUTH',
307364
}
308365
loginMethods.value = Array.isArray(data.auth_types) ? data.auth_types : []
309366

0 commit comments

Comments
 (0)