Skip to content

Conversation

@shaohuzhang1
Copy link
Contributor

feat: Replace source file permission

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Oct 22, 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

f2c-ci-robot bot commented Oct 22, 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

)
RESOURCE_KNOWLEDGE_HIT_TEST = Permission(
group=Group.SYSTEM_RES_KNOWLEDGE_HIT_TEST, operate=Operate.READ, role_list=[RoleConstants.ADMIN],
parent_group=[SystemGroup.RESOURCE_KNOWLEDGE], is_ee=settings.edition == "EE"
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 seems to be well-structured and contains no obvious inconsistencies or errors. However, there are a few minor improvements that can be made:

  1. Consistent Naming: Ensure consistent naming conventions throughout the codebase. This will help maintain readability and consistency.

  2. Comment Documentation: Add more comments explaining the purpose of each Operate value. While existing descriptions are somewhat helpful, they could benefit from additional details.

  3. Code Readability: Break down longer lines into multiple lines if necessary to improve readability.

Here's an adjusted version with these suggestions in mind:

from enum import Enum

class Operate(Enum):
    DOWNLOAD = "READ+DOWNLOAD"  # 下载原始文档
    AUTH = "READ+AUTH"        # 资源授权
    TAG = "READ+TAG"          # 标签设置
    REPLACE = "READ+REPLACE"      # 替换原文档


class RoleGroup(Enum):
    # Define other roles as needed


def get_workspace_role(self):
    return {
        Operate.RELATED.value: _("Relate"),
        Operate.ANNOTATION.value: _("Annotation"),
        Operate.CLEAR_POLICY.value: _("Clear Policy"),
        Operate.DOWNLOAD.value: _('Download Original Document'),  # Use full name instead of abbreviation
        Operate.EMBED.value: _('Embed third party'),
        Operate.ACCESS.value: _('Access restrictions'),
        Operate.DISPLAY.value: _('Display Settings'),
        Operate.ADD_KNOWLEDGE.value: _('Add to Knowledge Base'),
        Operate.AUTH.value: _('Resource Authorization'),
        Operate.TAG.value: _('Tag Setting'),
        Operate.REPLACE.value: _('Replace Original Document')
    }


# Example usage (assuming Permission and Group constants are defined somewhere)
permission_constants = [
    Permission(
        group=Group.KNOWLEDGE_DOCUMENT,
        operate=Operate.REPLACE,
        role_list=[RoleConstants.ADMIN, RoleConstants.USER],
        resource_permission_group_list=[ResourcePermissionConst.KNOWLEDGE_MANGE],
        parent_group=[WorkspaceGroup.KNOWLEDGE, UserGroup.KNOWLEDGE]
    ),
    # Other permissions...
]

Key Changes:

  • Descriptive Comments: Added explanations where possible for better understanding.
  • Simplified Code Structure: Reduced long lines slightly through breaking up parts of statements.

These changes make the code easier to understand and maintain.

),
knowledge_chat_user_read: (source_id:string) => false,
knowledge_chat_user_edit: (source_id:string) =>
hasPermission(
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 are no specific irregularities or major issues present in the code snippet you provided for workspace.doc_replace. However, there is one optimization suggestion:

doc_replace: (source_id:string) =>
  hasPermission([
    new ComplexPermission([RoleConst.USER], [PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(source_id)], [], 'AND'),
    RoleConst.WORKSPACE_MANAGE.getWorkspaceRole(),
    ...[
      PermissionConst.KNOWLEDGE_DOCUMENT_REPLACE.getKnowledgeWorkspaceResourcePermission(source_id),
      PermissionConst.KNOWLEDGE_DOCUMENT_REPLACE.getWorkspacePermissionWorkspaceManageRole(),
    ].filter(Boolean), // Remove falsy values if needed
  ], 'OR');

This ensures that only truthy permission objects are considered during the .filter(Boolean) operation. This can help simplify and avoid runtime errors if some of these permissions might not evaluate to true under certain conditions.

),
problem_create: () =>
hasPermission (
[
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 doc_replace function seems to be correctly defined with the correct condition structure. However, it can be optimized slightly by using destructuring assignment within the function declaration:

const share = {
  // Other existing functions...

  docReplace() {
    return hasPermission([RoleConst.ADMIN, PermissionConst.SHARED_KNOWLEDGE_DOCUMENT_REPLACE], 'OR');
  },
};

This approach is generally cleaner and more concise.

No other potential issues or irregularities were found with the provided code snippet.

Regarding future optimizations for handling shared knowledge documents replace permissions, you might consider implementing caching strategies if performance becomes an issue, especially if this method is called frequently throughout your application. Additionally, ensure that all necessary data access controls (like role checking) are properly validated before executing critical operations like document replacement.

@zhanweizhang7 zhanweizhang7 merged commit 4487964 into v2 Oct 22, 2025
4 of 6 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_replace branch October 22, 2025 03:25
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.

3 participants