[Fixes #13965] Assign resource ownership to administrator during resource creation configurable via settings#13970
[Fixes #13965] Assign resource ownership to administrator during resource creation configurable via settings#13970
Conversation
…urce creation configurable via settings
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 addresses issue #13965 by introducing a new feature that allows GeoNode administrators to configure automatic assignment of resource ownership to a designated administrator account during resource creation. This change provides greater control over resource management, while also ensuring that the original uploader maintains necessary permissions to manage their contributions. The implementation includes new settings, a utility function for owner resolution, and a dedicated permission handler to manage access rights effectively. 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 configurable setting to assign resource ownership to an administrator upon creation. The changes are spread across multiple files to handle this new logic. Overall, the implementation is good, but I've found a few issues related to conditional logic that could lead to bugs if the new setting is disabled. I've also identified a potential KeyError in one of the new handlers. My review comments provide specific suggestions to address these points.
| if getattr(settings, "AUTO_ASSIGN_RESOURCE_OWNERSHIP_TO_ADMIN", False): | ||
| _resource.set_default_permissions(owner=resolved_owner, created=True, initial_user=initial_user) |
There was a problem hiding this comment.
The call to _resource.set_default_permissions is conditional on the AUTO_ASSIGN_RESOURCE_OWNERSHIP_TO_ADMIN setting. If this setting is False, no default permissions will be set for newly created resources via resource_manager.create. This is a critical bug. The if condition should be removed, and set_default_permissions should be called unconditionally.
_resource.set_default_permissions(owner=resolved_owner, created=True, initial_user=initial_user)There was a problem hiding this comment.
The condition is needed only for the auto-assign feature (AUTO_ASSIGN_RESOURCE_OWNERSHIP_TO_ADMIN=True) to set uploader manage permissions passing initial_user.
When the setting is False, the normal intial flow still sets default permissions through set_missing_info() -> set_default_permissions(owner=user).
geonode/maps/api/views.py
Outdated
| if getattr(settings, "AUTO_ASSIGN_RESOURCE_OWNERSHIP_TO_ADMIN", False): | ||
| resource_manager.set_permissions( | ||
| instance.uuid, | ||
| instance=instance, | ||
| owner=resolved_owner, | ||
| permissions=None, | ||
| created=True, | ||
| initial_user=self.request.user, | ||
| ) |
There was a problem hiding this comment.
The call to resource_manager.set_permissions is inside a conditional block that checks AUTO_ASSIGN_RESOURCE_OWNERSHIP_TO_ADMIN. This means if the setting is False, no permissions will be set on map creation, which is a bug. This call should be unconditional and should use instance.set_default_permissions for consistency with other parts of the codebase.
instance.set_default_permissions(owner=resolved_owner, created=True, initial_user=self.request.user)There was a problem hiding this comment.
Updated using instance.set_default_permissions, but the condition remains, which is used only when AUTO_ASSIGN_RESOURCE_OWNERSHIP_TO_ADMIN = True to set uploader manage permissions by passing initial_user. When False, it works as default,how permissions were previously handled through _post_change_routines.
Codecov Report❌ Patch coverage is Additional details and impacted files🚀 New features to boost your workflow:
|
Fixes #13965
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.