Skip to content
Merged
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
5 changes: 5 additions & 0 deletions ui/src/utils/permission/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ const PermissionConst = {
RESOURCE_MODEL_READ: new Permission('SYSTEM_RESOURCE_MODEL:READ'),
RESOURCE_MODEL_EDIT: new Permission('SYSTEM_RESOURCE_MODEL:READ+EDIT'),
RESOURCE_MODEL_DELETE: new Permission('SYSTEM_RESOURCE_MODEL:READ+DELETE'),

RESOURCE_MODEL_AUTH: new Permission('SYSTEM_RESOURCE_MODEL:READ+AUTH'),
RESOURCE_APPLICATION_AUTH: new Permission('SYSTEM_RESOURCE_APPLICATION:READ+AUTH'),
RESOURCE_KNOWLEDGE_AUTH: new Permission('SYSTEM_RESOURCE_AUTH:READ+AUTH'),
RESOURCE_TOOL_AUTH: new Permission('SYSTEM_RESOURCE_TOOL:READ+AUTH'),

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.

The provided code snippet looks generally clean, but there are a few suggestions to improve it:

  1. Consistent Property Naming: Ensure that all permission keys use consistent naming conventions (e.g., RESOURCE_MODEL_READ, RESOURC_AUTH).

  2. Optional Properties: Since permissions might not always require certain parts of them, consider creating optional properties for components like read/edit/delete.

  3. Security Measures: Include comments explaining the reasons behind each permission level.

Here is a more optimized version with these considerations in mind:

const PermissionConst = {
  // Base permission levels
  READ: 'READ',
  WRITE: 'WRITE',

  // Resource model-related permissions
  RESOURCE_MODEL_BASIC: [Permission.READ],
  RESOURCE_MODEL_EXTENDED: [...PermissionBase, ..., Permission.WRITE], // Example extend base

  // Application-specific permissions
  RESOURCE_APPLICATION_READ: PermissionConst.READ,
  RESOURCE_APPLICATION_WRITE: PermissionConst.WRITE,

  // Knowledge hub permissions
  RESOURCE_KNOWLEDGE_READ: PermissionConst.READ,
  RESOURCE_KNOWLEDGE_WRITE: PermissionConst.WRITE,

  // Tool functionality permissions
  RESOURCE_TOOL_READ: PermissionConst.READ,
  RESOURCE_TOOL_WRITE: PermissionConst.WRITE,

  // Settings permissions
  APPEARANCE_SETTINGS_READ: PermissionConst.READ,
  APPEARANCE_SETTINGS_WRITE: PermissionConst.WRITE,
};

// Helper function to combine multiple permissions into one array
function combinePermissions(...permissions) {
  return Array.from(new Set(permissions));
}

console.log(Object.keys(PermissionConst)).map(key => console.log(`${key}: ${typeof PermissionConst[key]}`));

Explanation:

  • Consistently Named Permissions: The property names now follow a consistent pattern, making it easier to understand their purpose.

  • Optional Properties: Added helper functions or object destructuring to handle case where some permissions might be omitted.

  • Security Comments: Left commented out for clarity, if you need to ensure specific security rules align with business needs.

These changes will make the configuration more maintainable and scalable. Make sure to adjust according to project requirements and team processes.

Expand Down
Loading