Skip to content
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
8 changes: 7 additions & 1 deletion apps/common/constants/permission_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class Operate(Enum):
AUTH = "READ+AUTH" # 资源授权
TAG = "READ+TAG" # 标签设置
REPLACE = "READ+REPLACE" # 标签设置
UPDATE = "READ+UPDATE" # 更新license


class RoleGroup(Enum):
Expand Down Expand Up @@ -1014,9 +1015,14 @@ class PermissionConstants(Enum):
)

ABOUT_READ = Permission(group=Group.OTHER, operate=Operate.READ,
role_list=[RoleConstants.ADMIN, RoleConstants.USER],
parent_group=[SystemGroup.OTHER, WorkspaceGroup.OTHER, UserGroup.OTHER],
label=_('About')
)
ABOUT_UPDATE = Permission(group=Group.OTHER, operate=Operate.UPDATE,
role_list=[RoleConstants.ADMIN],
parent_group=[SystemGroup.OTHER],
label=_('About')
label=_('Update License')
)
SWITCH_LANGUAGE = Permission(group=Group.OTHER, operate=Operate.EDIT,
role_list=[RoleConstants.ADMIN, RoleConstants.USER],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks mostly correct, but there are some suggestions to improve it:

  1. Remove Redundant READ Enum Member:
    The READ member is repeated in both Operate and PermissionConstants. This redundancy can remove the need for duplicate values.

    class Operate(Enum):
        AUTH = "READ+AUTH" # 资源授权
        TAG = "READ+TAG" # 标签设置
        REPLACE = "READ+REPLACE" # 标签设置
        UPDATE = "READ+UPDATE"

2. **Optimize Documentation Strings**:
   Ensure that documentation strings are concise and descriptive, and keep consistent spacing around them.

   ```python
   class AboutReadPermission(Permission):
       group = Group.OTHER
       operation = Operate.READ
       role_list = [RoleConstants.ADMIN, RoleConstants.USER]
       parent_groups = [SystemGroup.OTHER, WorkspaceGroup.OTHER, UserGroup.OTHER]
       label = _('About')
       

   class AboutUpdatePermission(Permission):
       group = Group.OTHER
       operation = Operate.UPDATE
       role_list = [RoleConstants.ADMIN]
       parent_groups = [SystemGroup.OTHER]
       label = _('Update License')
  1. Separate Permissions into Classes (Optional):
    If your application requires more complex permission checks or organization, consider separating permissions into separate classes.

    class BasePermission(Permission):
        def __init__(self, operation, role_list=[], parent_groups=[]):
            super().__init__(group=Group.OTHER, operate=operation, role_list=role_list, parent_group=parent_groups)
    
    class AboutReadPermission(BasePermission):
        label = _('About')
    
    class AboutUpdatePermission(BasePermission):
        label = _('Update License')

By making these adjustments, the code will be cleaner, more readable, and potentially easier to maintain.

Expand Down
3 changes: 3 additions & 0 deletions apps/locales/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8742,4 +8742,7 @@ msgid "Download Original Document"
msgstr ""

msgid "Replace Original Document"
msgstr ""

msgid "Update License"
msgstr ""
3 changes: 3 additions & 0 deletions apps/locales/zh_CN/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8869,3 +8869,6 @@ msgstr "下载原文档"

msgid "Replace Original Document"
msgstr "替换原文档"

msgid "Update License"
msgstr "更新许可证"
3 changes: 3 additions & 0 deletions apps/locales/zh_Hant/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8869,3 +8869,6 @@ msgstr "下載原文件"

msgid "Replace Original Document"
msgstr "替換原文件"

msgid "Update License"
msgstr "更新許可證"
7 changes: 6 additions & 1 deletion ui/src/layout/layout-header/avatar/AboutDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@
:auto-upload="false"
:show-file-list="false"
:on-change="onChange"
v-hasPermission="new Role('ADMIN')"
v-if="hasPermission([
RoleConst.ADMIN,
PermissionConst.ABOUT_UPDATE
],'OR')"
>
<el-button class="border-primary mr-16"
>{{ $t('layout.about.update') }} License
Expand All @@ -70,6 +73,8 @@ import {fromNowDate} from '@/utils/time'
import {Role} from '@/utils/permission/type'
import useStore from '@/stores'
import { t } from '@/locales'
import { hasPermission } from '@/utils/permission'
import { PermissionConst, RoleConst } from '@/utils/permission/data'
const {user, theme} = useStore()
const isDefaultTheme = computed(() => {
return theme.isDefaultTheme()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There appears to be an issue with line 49 of the provided code snippet. The v-hasPermission directive seems to have been replaced by v-if, which may cause unexpected behavior if you intend to use permission-based logic for displaying certain components.

Additionally, lines 68-73 should be moved outside of the <template> block as they don't belong there. They appear to define utility functions and store variables, which are typically handled within the setup function in Vue.js.

For optimization, remove the unnecessary import statements for the roles like 'USER' before importing from @/utils/permission/data. Here's the revised version:

<template>
  <!-- Your template content here -->
</template>

<script lang="ts">
import {defineComponent} from "vue";
// import {RoleConst, PermissionConst} from "@/utils/permission/data"; // Remove this line
import userStore from "@/stores/userStore";

export default defineComponent({
  data() {
    return {};
  },
  computed: {
    isDefaultTheme() {
      return this.user.theme.isDefaultTheme();
    }
  }
});
</script>

This approach keeps the scope clean while ensuring all necessary imports are included where needed. Make sure each component has the appropriate role checks based on your application's security requirements.

Expand Down
1 change: 1 addition & 0 deletions ui/src/utils/permission/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ const PermissionConst = {
OPERATION_LOG_CLEAR_POLICY: new Permission('OPERATION_LOG:READ+CLEAR_POLICY'),

ABOUT_READ: new Permission('OTHER:READ'),
ABOUT_UPDATE: new Permission('OTHER:READ+UPDATE'),
SWITCH_LANGUAGE: new Permission('OTHER:READ+EDIT'),
CHANGE_PASSWORD: new Permission('OTHER:READ+CREATE'),
SYSTEM_API_KEY_EDIT: new Permission('OTHER:READ+DELETE'),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code snippet for PermissionConst looks mostly correct with minor formatting and comment changes. Here's a concise review:

  1. Comments: Ensure each permission is well-commented to describe its purpose clearly.

  2. Order of Operations: Permissions related to specific actions (e.g., updating, reading) should be mentioned first. It makes sense to group those at the beginning.

  3. Syntax Consistency: The syntax seems consistent, but ensure there are no typos or extra characters that might cause issues.

  4. Documentation: Consider adding comments describing what each permission string means if it's not clear from context.

Overall, the existing permissions seem logically organized and don't contain known issues. If there are additional requirements or security concerns, consider consulting them further.

Expand Down
Loading