Skip to content

feat: Front permission #3764

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2025
Merged

feat: Front permission #3764

merged 1 commit into from
Jul 29, 2025

Conversation

shaohuzhang1
Copy link
Contributor

feat: Front permission

Copy link

f2c-ci-robot bot commented Jul 29, 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.

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.

Copy link

f2c-ci-robot bot commented Jul 29, 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.

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_MODEL_EDIT: new Permission('SYSTEM_RESOURCE_MODEL:READ+EDIT'),
RESOURCE_MODEL_DELETE: new Permission('SYSTEM_RESOURCE_MODEL:READ+DELETE'),

APPEARANCE_SETTINGS_READ: new Permission('APPEARANCE_SETTINGS:READ'),
APPEARANCE_SETTINGS_EDIT: new Permission('APPEARANCE_SETTINGS:READ+EDIT'),

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 several optimizations and improvements that can be made to the code snippet you provided:

  1. Reduce Redundancy: The Permission class could be modified to allow specifying both read (r) and create (c), edit (e), sync (s), vector (v), generate (g), and delete (d) permissions using a constructor that takes an object of these properties.

  2. Error Handling: Implement error handling in methods like toString() if necessary, especially during permission string generation.

  3. Validation: Add validation checks for null or undefined input when creating a new instance of Permission. Ensure that only valid strings are used as identifiers.

  4. Cache Mechanism: Consider adding caching mechanisms if this will save performance in repetitive access scenarios.

  5. Logging and Debugging: Provide logging options or a debugger to track the behavior of permission instances and their usage within the application.

  6. Documentation: Enhance documentation with more detailed comments explaining each property and method purpose.

Here is a simplified example of how the Permission class could be optimized:

class Permission {
  constructor(params) {
    const read = params.read || false;
    const create = params.create || false;
    // ... add other flags

    return { r: read, c: create, e: true /* default */, s: true, v: true, g: false, d: false };
  }

  toString() {
    let result = 'RESOURCE_';
    ['KNOWLEDGE', 'DOCUMENT'].forEach(type => this[`RESOURCE_${type}_`].keys().forEach(permission => {
      if (this[permission]) {
        result += `${permission.toUpperCase('')}`;
      }
    }));

    return result.trim();
  }

  hasPermission(property) {
    // Check if a specific permission exists within the permission set
    switch (property) {
      case 'READ':
        // Default to read permission since it's always available unless explicitly denied
        return this.r;
      case 'CREATE':
        return this.c && !this.d; // Create allowed except if DELETE flag is also set
      case 'EDIT':
        return this.e && !this.d;
      case 'SYNC':
        return this.s;
      case 'VECTOR':
        return this.v;
      case 'GENERATE':
        return this.g;
      case 'DELETE':
        return this.d;
      default:
        throw new Error(`Unknown property: ${property}`);
    }
  }
}

// Usage
const KnowledgePermissions = new Permission({
  read: true,
  create: true,
  edit: true,
  sync: true,
  vector: true,
  generate: true,
});

console.log(KnowledgePermissions.toString()); // Output: RESOURCE_KNOWLEDGE_READ CREATE EDIT SYNC VECTOR GENERATE

These changes aim to reduce redundancy, improve clarity, introduce useful features for managing and checking permissions, and potentially enhance overall modularity and reusability.

@zhanweizhang7 zhanweizhang7 merged commit 139473e into v2 Jul 29, 2025
3 of 5 checks passed
@zhanweizhang7 zhanweizhang7 deleted the pr@v2@feat_front_permission branch July 29, 2025 03:07
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