-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Resource authorization permission #3873
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 |
|---|---|---|
|
|
@@ -89,6 +89,10 @@ class Page(APIView): | |
| responses=UserResourcePermissionPageAPI.get_response(), | ||
| tags=[_('Resources authorization')] # type: ignore | ||
| ) | ||
| @has_permissions( | ||
| lambda r, kwargs: Permission(group=Group(kwargs.get('resource') + '_WORKSPACE_USER_RESOURCE_PERMISSION'), | ||
| operate=Operate.READ), | ||
| RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE.get_workspace_role()) | ||
| def get(self, request: Request, workspace_id: str, user_id: str, resource: str, current_page: str, | ||
| page_size: str): | ||
| return result.success(UserResourcePermissionSerializer( | ||
|
|
@@ -109,6 +113,10 @@ class WorkspaceResourceUserPermissionView(APIView): | |
| responses=ResourceUserPermissionAPI.get_response(), | ||
| tags=[_('Resources authorization')] # type: ignore | ||
| ) | ||
| @has_permissions( | ||
| lambda r, kwargs: Permission(group=Group(kwargs.get('resource') + '_RESOURCE_AUTHORIZATION'), | ||
| operate=Operate.AUTH), | ||
| RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE.get_workspace_role()) | ||
| def get(self, request: Request, workspace_id: str, target: str, resource: str): | ||
| return result.success(ResourceUserPermissionSerializer( | ||
| data={'workspace_id': workspace_id, "target": target, 'auth_target_type': resource, | ||
|
|
@@ -127,6 +135,13 @@ def get(self, request: Request, workspace_id: str, target: str, resource: str): | |
| responses=ResourceUserPermissionEditAPI.get_response(), | ||
| tags=[_('Resources authorization')] # type: ignore | ||
| ) | ||
| @log(menu='System', operate='Edit user authorization status of resource', | ||
| get_operation_object=lambda r, k: get_user_operation_object(k.get('user_id')) | ||
| ) | ||
| @has_permissions( | ||
| lambda r, kwargs: Permission(group=Group(kwargs.get('resource') + '_RESOURCE_AUTHORIZATION'), | ||
| operate=Operate.AUTH), | ||
| RoleConstants.ADMIN, RoleConstants.WORKSPACE_MANAGE.get_workspace_role()) | ||
| def put(self, request: Request, workspace_id: str, target: str, resource: str): | ||
| return result.success(ResourceUserPermissionSerializer( | ||
| data={'workspace_id': workspace_id, "target": target, 'auth_target_type': resource, }) | ||
|
|
@@ -144,6 +159,10 @@ class Page(APIView): | |
| responses=ResourceUserPermissionPageAPI.get_response(), | ||
| tags=[_('Resources authorization')] # type: ignore | ||
| ) | ||
| @has_permissions( | ||
| lambda r, kwargs: Permission(group=Group(kwargs.get('resource') + '_RESOURCE_AUTHORIZATION'), | ||
| operate=Operate.AUTH), | ||
| 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( | ||
|
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. 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:
Overall, the code looks mostly clean and functional based on its intended purpose and structure. However, placing the log decorator after |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| import { AuthorizationEnum } from '@/enums/system' | ||
| import { t } from '@/locales' | ||
| import { hasPermission } from '@/utils/permission' | ||
| import { EditionConst } from '@/utils/permission/data' | ||
|
|
||
| export const permissionOptions = [ | ||
| const notCommunity = hasPermission([EditionConst.IS_EE,EditionConst.IS_PE],'OR') | ||
|
|
||
| const permissionOptions = [ | ||
| { | ||
| label: t('views.system.resourceAuthorization.setting.notAuthorized'), | ||
| value: AuthorizationEnum.NOT_AUTH, | ||
|
|
@@ -17,9 +21,16 @@ export const permissionOptions = [ | |
| value: AuthorizationEnum.MANAGE, | ||
| desc: t('views.system.resourceAuthorization.setting.managementDesc'), | ||
| }, | ||
| { | ||
| ] | ||
|
|
||
| if (notCommunity) { | ||
| permissionOptions.push( | ||
| { | ||
| label: t('views.system.resourceAuthorization.setting.role'), | ||
| value: AuthorizationEnum.ROLE, | ||
| desc: t('views.system.resourceAuthorization.setting.roleDesc'), | ||
| }, | ||
| ] | ||
| ) | ||
| } | ||
|
|
||
| export {permissionOptions} | ||
|
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 code is logically sound and follows best practices, but there are some stylistic improvements that could be made:
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:
This refactored code maintains functionality while adhering to common coding standards and improving readability. |
||
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 code looks clean and well-organized. However, there are a few minor improvements you can make:
Consistent Spacing: Ensure that spaces between operators (+) in
Operateenum values align consistently.Comments Formatting: Maintain consistent comment formatting across the file.
Whitespace Between Enum Values: Keep whitespace around enum values to improve readability.
Here is the corrected version of your code with these minor adjustments:
These small changes enhance clarity and maintainability of the codebase.