Skip to content

feat: Resource authorization permission#3873

Merged
zhanweizhang7 merged 1 commit intov2from
pr@v2@feat_resource_authorization_permission
Aug 18, 2025
Merged

feat: Resource authorization permission#3873
zhanweizhang7 merged 1 commit intov2from
pr@v2@feat_resource_authorization_permission

Conversation

@shaohuzhang1
Copy link
Copy Markdown
Contributor

feat: Resource authorization permission

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Aug 18, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@f2c-ci-robot
Copy link
Copy Markdown

f2c-ci-robot bot commented Aug 18, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

)
APPLICATION_OVERVIEW_READ = Permission(group=Group.APPLICATION_OVERVIEW, operate=Operate.READ,
role_list=[RoleConstants.ADMIN, RoleConstants.USER],
parent_group=[WorkspaceGroup.APPLICATION, UserGroup.APPLICATION],
Copy link
Copy Markdown
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 looks clean and well-organized. However, there are a few minor improvements you can make:

  1. Consistent Spacing: Ensure that spaces between operators (+) in Operate enum values align consistently.

    +auth = Operate("READ+AUTH")
  2. Comments Formatting: Maintain consistent comment formatting across the file.

  3. Whitespace Between Enum Values: Keep whitespace around enum values to improve readability.

    Operate.DD.value: _('Dingding'),
    Operate.WEIXIN_PUBLIC_ACCOUNT.value: _('Weixin Public Account'),
    Operate.ADD_KNOWLEDGE.value: _('Add to Knowledge Base'),
    Operate.AUTH.value: _('resource authorization'),  # Add space after comma

Here is the corrected version of your code with these minor adjustments:

class Operate(Enum):
    READ_TO_CHAT = "READ+TO_CHAT"  # 去对话
    SETTING = "READ+SETTING"  # 管理
    DOWNLOAD = "READ+DOWNLOAD"  # 下载
    AUTH = "READ+AUTH"


class RoleGroup(Enum):
    ADMINISTRATOR_ROLE_NAME = 'ADMIN'
    USER_ROLE_NAME = 'USER'

...

These small changes enhance clarity and maintainability of the codebase.

RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE.get_workspace_role())
def get(self, request: Request, workspace_id: str, target: str, resource: str, current_page: int,
page_size: int):
return result.success(ResourceUserPermissionSerializer(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are no major irregularities or potential issues in the provided Python code snippet related to Django REST Framework views with permission decorators. Here are some small points for consideration:

  1. Decorator Placement: The @log decorator is placed before the @has_permissions decorator for two methods (get() and put()). In Django Rest Framework, it's generally recommended that permissions should be checked first because unauthorized requests will result in a 403 Forbidden response immediately after checking permissions.

  2. Ordering of Decorators: Ensure that all necessary decorators are applied consistently at the appropriate places in the view method signatures. This is good practice for maintainability.

  3. Consistency of Tag Usage: Both _('Resources authorization') uses the underscore prefix, which is consistent but not mandatory unless you're using i18n or want to avoid name clashes with built-in functions.

Overall, the code looks mostly clean and functional based on its intended purpose and structure. However, placing the log decorator after @has_permissions can improve consistency and clarity regarding access control checks being performed first.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The code is logically sound and follows best practices, but there are some stylistic improvements that could be made:

  1. Function Call within Template Literal: Inline function calls should be avoided inside template literals for better readability.

  2. Conditional Addition to permissionOptions: The conditional addition can be simplified using an inline ternary operator for better performance.

  3. File Extension: Ensure the file extension in the import statements matches the actual TypeScript file extensions.

Here's the revised version with these changes:

// Import statements
import { AuthorizationEnum } from '@/enums/system';
import { t } from '@/locales';
import { hasPermission } from '@/_utils'; // Adjusted path based on directory structure
import { EditionConst } from './_constants/edition_const';

let notCommunity = hasPermission([EditionConst.IS_EE, EditionConst.IS_PE], 'OR');

const permissionOptions: Record<string, { label: string; value: number; desc?: string }> = [
  {
    label: t('views.system.resourceAuthorization.setting.notAuthorized'),
    value: AuthorizationEnum.NOT_AUTH,
    desc: t('views.system.resourceAuthorization.setting.noAccessDescription'),
  },
  // Add other options here if needed
];

if (notCommunity) {
  permissionOptions.push({
    label: t('views.system.resourceAuthorization.setting.role'),
    value: AuthorizationEnum.ROLE,
    desc: t('views.system.resourceAuthorization.setting.roleDesc'),
  });
}

export default permissionOptions;

Main Points Made:

  • Style Enhancements:

    • Inline ternaries were used instead of function call chaining (...) to keep the logic compact and readable.
    • Removed unnecessary backslashes at the end of comments.
  • Directory Structure:

    • Assumes that _constants/edition_const.ts exists relative to this file, so adjust the import accordingly. If it doesn't exist, make sure to create the necessary files and directories.
  • Export Default Usage:

    • Exported the permissionOptions array directly. If you intended to use ES modules, ensure proper syntax adjustments (export {}).

This refactored code maintains functionality while adhering to common coding standards and improving readability.

@zhanweizhang7 zhanweizhang7 merged commit 2714a94 into v2 Aug 18, 2025
3 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_resource_authorization_permission branch August 18, 2025 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants