-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat: Front end permissions for resource authorization #3878
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,16 @@ const workspace = { | |
| ], | ||
| 'OR', | ||
| ), | ||
| auth: (source_id:string) => | ||
| hasPermission( | ||
| [ | ||
| new ComplexPermission([RoleConst.USER],[PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(source_id)],[],'AND'), | ||
| RoleConst.WORKSPACE_MANAGE.getWorkspaceRole, | ||
| PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getKnowledgeWorkspaceResourcePermission(source_id), | ||
| PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole, | ||
| ], | ||
| 'OR', | ||
| ), | ||
| folderEdit: () => | ||
| hasPermission( | ||
| [ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The provided JavaScript code defines an object Here's a summary of the issues, potential improvements, and some suggestions: Issues:
Potential Improvements/Cleanups:
Example Refactored Snippet:const { RoleConst, PermissionConst } = require('./constants');
const workspace = {
search: () => hasPermission([
// ... (existing permission array)
]),
delete: () => hasPermission([
// ... (existing permission array)
]),
view: () => hasPermission([
// ... (existing permission array)
]),
};
// Utility Function for Creating Complex Permissions
function makeComplexPermission(roleOrRoles, permissions, exclusions = [], conjunction = 'AND') {
return { roleOrRoles, permissions, exclusions, conjunction };
}
// Example Usage in 'auth'
workspace.auth = (sourceId) => {
if (!sourceId) throw new Error("source_id is required");
const permissions = [makeComplexPermission(RoleConst.USER, [
PermissionConst.KNOWLEDGE.getKnowledgeWorkspaceResourcePermission(sourceId),
], [])];
permissions.push(RoleConst.WORKSPACE_MANAGE.getWorkspaceRole);
permissions.push(PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getKnowledgeWorkspaceResourcePermission(sourceId));
permissions.push(PermissionConst.KNOWLEDGE_RESOURCE_AUTHORIZATION.getWorkspacePermissionWorkspaceManageRole);
return hasPermission(permissions, 'OR');
};In this refactored version:
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided TypeScript code snippet appears to be part of an API definition that defines several permission checks within a
workspaceobject. Some key points to consider:Code Structure: The structure is clear with multiple function definitions and permissions, but it looks like there might not be any actual logic implemented for these functions yet.
Function Names:
auth: This suggests this function should return a boolean value indicating if the user/auth source has the necessary permissions.folderEdit: Similarily, this function should also return a boolean value indicating permission for editing folders.Permissions:
hasPermission,ComplexPermission,RoleConst, andPermissionConst.Documentation and Comments: There seems to be some intended documentation or comments around these methods, but they are incomplete (
//at the end of lines).Suggested Improvements:
checkUserAuth,canEditFolder).Here’s a revised version with added comments and improved clarity:
This revision includes comments, docstrings, and placeholders for the implementation of the
hasPermissionfunction, which could include more complex logic based on your application's permission system.