[Fixes #13976] auto-assign group permissions to the resource creator groups#13986
[Fixes #13976] auto-assign group permissions to the resource creator groups#13986
Conversation
Summary of ChangesHello @sijandh35, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a new feature that automatically assigns permissions to the groups of a resource creator when a new resource is created. This is achieved through a new permissions handler and associated settings, enhancing the security model by automating permission assignments. The PR also includes unit tests to ensure the new functionality works as expected. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new permissions handler, ResourceCreatorGroupsPermissionsHandler, which automatically assigns configured permissions to all groups of a resource creator upon resource creation. This is a useful feature for organizations that want to ensure team members have immediate access to resources created by their peers. The implementation includes the handler logic, necessary settings for configuration, and unit tests. My feedback focuses on improving the robustness of the permission assignment logic to prevent accidental overwriting of existing permissions, optimizing resource type detection to avoid unnecessary database queries, and ensuring the handler is correctly ordered within the processing pipeline to respect advanced security workflows.
| extended_permissions = set(_to_extended_perms("view", _resource_type, _resource_subtype) or []) | ||
|
|
||
| for user_group in get_user_groups(owner): | ||
| payload["groups"][user_group] = sorted(extended_permissions) |
There was a problem hiding this comment.
The current implementation overwrites any existing permissions for the group in the payload. If another handler has already assigned permissions to one of the creator's groups, those changes will be lost. It is safer to perform a union of the new permissions with any existing ones.
| payload["groups"][user_group] = sorted(extended_permissions) | |
| payload["groups"][user_group] = sorted(set(payload["groups"].get(user_group, [])) | extended_permissions) |
| "geonode.security.handlers.GroupManagersPermissionsHandler", | ||
| "geonode.security.handlers.SpecialGroupsPermissionsHandler", | ||
| "geonode.security.handlers.AdvancedWorkflowPermissionsHandler", | ||
| "geonode.security.handlers.ResourceCreatorGroupsPermissionsHandler", |
There was a problem hiding this comment.
The ResourceCreatorGroupsPermissionsHandler is currently placed at the end of the PERMISSIONS_HANDLERS list. This means it runs after the AdvancedWorkflowPermissionsHandler. In GeoNode, the advanced workflow handler is responsible for enforcing strict security policies (e.g., making a resource private until it is approved). If the creator groups handler runs after it, it might grant permissions that the workflow explicitly intended to restrict. To ensure that workflow policies are respected, this handler should be placed before AdvancedWorkflowPermissionsHandler.
"geonode.security.handlers.ResourceCreatorGroupsPermissionsHandler",
"geonode.security.handlers.GroupManagersPermissionsHandler",
"geonode.security.handlers.SpecialGroupsPermissionsHandler",
"geonode.security.handlers.AdvancedWorkflowPermissionsHandler",| payload.setdefault("users", {}) | ||
| payload.setdefault("groups", {}) | ||
|
|
||
| _resource_type = getattr(instance, "resource_type", None) or instance.polymorphic_ctype.name |
There was a problem hiding this comment.
Accessing instance.polymorphic_ctype.name can trigger an additional database query if the polymorphic_ctype relation hasn't been prefetched. Since fixup_perms is often called in performance-sensitive paths, it's more efficient to use instance._meta.model_name as a fallback for the resource type.
| _resource_type = getattr(instance, "resource_type", None) or instance.polymorphic_ctype.name | |
| _resource_type = getattr(instance, "resource_type", None) or instance._meta.model_name |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #13986 +/- ##
==========================================
+ Coverage 74.07% 74.27% +0.20%
==========================================
Files 950 950
Lines 56826 56873 +47
Branches 7719 7710 -9
==========================================
+ Hits 42093 42245 +152
+ Misses 13044 12927 -117
- Partials 1689 1701 +12 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
@sijandh35 I'm testing branch https://github.com/GeoNode/geonode/tree/ISSUE_13976_and_13965 with the following settings in a project:
AUTO_ASSIGN_RESOURCE_CREATOR_GROUPS_PERMISSIONS = True
RESOURCE_CREATOR_GROUPS_PERMISSIONS = "download"
Groups are assigned view permissions, although download is configured.
Fixes #13976
Note: This PR should pull the changes of PR: #13970 after the merge of the PR.
Checklist
For all pull requests:
The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):
Submitting the PR does not require you to check all items, but by the time it gets merged, they should be either satisfied or inapplicable.