Skip to content

[Fixes #14035] Implementation of a common ResourceManager base class for all resource types#14053

Open
sijandh35 wants to merge 13 commits intomasterfrom
ISSUE_14035
Open

[Fixes #14035] Implementation of a common ResourceManager base class for all resource types#14053
sijandh35 wants to merge 13 commits intomasterfrom
ISSUE_14035

Conversation

@sijandh35
Copy link
Copy Markdown
Contributor

@sijandh35 sijandh35 commented Mar 17, 2026

Fixes #14035

Checklist

Reviewing is a process done by project maintainers, mostly on a volunteer basis. We try to keep the overhead as small as possible and appreciate if you help us to do so by completing the following items. Feel free to ask in a comment if you have troubles with any of them.

For all pull requests:

  • Confirm you have read the contribution guidelines
  • You have sent a Contribution Licence Agreement (CLA) as necessary (not required for small changes, e.g., fixing typos in the documentation)
  • Make sure the first PR targets the master branch, eventual backports will be managed later. This can be ignored if the PR is fixing an issue that only happens in a specific branch, but not in newer ones.

The following are required only for core and extension modules (they are welcomed, but not required, for contrib modules):

  • There is a ticket in https://github.com/GeoNode/geonode/issues describing the issue/improvement/feature (a notable exemption is, changes not visible to end-users)
  • The issue connected to the PR must have Labels and Milestone assigned
  • PR for bug fixes and small new features are presented as a single commit
  • PR title must be in the form "[Fixes #<issue_number>] Title of the PR"
  • New unit tests have been added covering the changes, unless there is an explanation on why the tests are not necessary/implemented

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.

@cla-bot cla-bot bot added the cla-signed CLA Bot: community license agreement signed label Mar 17, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 significantly refactors the application's resource management system by introducing a registry pattern and type-specific resource managers. This change centralizes the handling of different resource types, making the codebase more modular and easier to extend with new resource types or custom behaviors. It streamlines how resources are created, updated, and managed across the platform, enhancing overall maintainability and reducing boilerplate code in various application components.

Highlights

  • Refactored Resource Management: The core resource management logic has been refactored to use a new ResourceManagerRegistry pattern, replacing direct calls to a global resource_manager instance with type-specific manager lookups.
  • Introduced Type-Specific Resource Managers: Dedicated resource manager classes (e.g., DocumentResourceManager, GeoAppResourceManager, MapResourceManager, DatasetResourceManager) have been added, inheriting from a new BaseResourceManager to encapsulate type-specific logic.
  • Centralized Manager Lookup: A ResourceManagerRegistry is now responsible for dynamically resolving and providing the correct resource manager based on the resource's model instance, class, or type string, improving modularity and extensibility.
  • Streamlined Resource Operations: API views and other modules now delegate resource creation, updates, deletions, permission handling, and thumbnail generation to the appropriate manager retrieved from the registry, simplifying their internal logic.

🧠 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
  • geonode/assets/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for resource operations.
  • geonode/base/admin.py
    • Updated delete_queryset to use resource_manager_registry for resource deletion.
  • geonode/base/api/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry and patched specific resource managers for tests.
  • geonode/base/api/views.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for setting thumbnails.
  • geonode/base/models.py
    • Updated delete method to use resource_manager_registry for permission removal.
  • geonode/base/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/base/views.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for resource updates, permissions, and thumbnail setting.
  • geonode/documents/admin.py
    • Updated delete_queryset to use resource_manager_registry for document deletion.
  • geonode/documents/api/views.py
    • Removed direct StorageManager and metadata_manager calls, simplified perform_create by delegating to DocumentResourceManager, and updated imports.
  • geonode/documents/manager.py
    • Added DocumentResourceManager class to handle document-specific creation logic, including file storage and thumbnail generation.
  • geonode/documents/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/documents/views.py
    • Simplified form_valid logic by delegating resource creation and updates to resource_manager_registry, and removed direct calls to resource_manager.resolve_creation_owner and finalize_creation_permissions.
  • geonode/geoapps/admin.py
    • Updated delete_queryset to use resource_manager_registry for GeoApp deletion.
  • geonode/geoapps/api/serializers.py
    • Simplified _create_and_update method to use resource_manager_registry for GeoApp creation and updates.
  • geonode/geoapps/api/views.py
    • Simplified perform_create by delegating to the serializer's save method, which now uses the resource manager.
  • geonode/geoapps/manager.py
    • Added GeoAppResourceManager class to handle GeoApp-specific creation and update logic.
  • geonode/geoapps/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/geoapps/views.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for GeoApp updates, permissions, and thumbnail setting.
  • geonode/geoserver/createlayer/utils.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for dataset creation, updates, and thumbnail setting.
  • geonode/geoserver/helpers.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for layer creation, permission setting, updates, and thumbnail setting.
  • geonode/geoserver/manager.py
    • Renamed ResourceManager to BaseResourceManager and updated internal references to _get_instance.
  • geonode/harvesting/harvesters/base.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for resource creation and updates.
  • geonode/harvesting/harvesters/wms.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for thumbnail setting.
  • geonode/layers/admin.py
    • Updated delete_queryset to use resource_manager_registry for dataset deletion.
  • geonode/layers/api/views.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for dataset updates and time series information.
  • geonode/layers/manager.py
    • Added DatasetResourceManager class.
  • geonode/layers/tasks.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for dataset deletion.
  • geonode/layers/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/layers/utils.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for setting dataset permissions.
  • geonode/maps/admin.py
    • Updated delete_queryset to use resource_manager_registry for map deletion.
  • geonode/maps/api/views.py
    • Simplified perform_create and perform_update by delegating to MapResourceManager and updated imports.
  • geonode/maps/manager.py
    • Added MapResourceManager class to handle map-specific creation and update logic, including map layers and thumbnail generation.
  • geonode/maps/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/metadata/handlers/contact.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for transferring ownership.
  • geonode/people/api/views.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for transferring resource ownership.
  • geonode/resource/api/tasks.py
    • Updated imports and modified resouce_service_dispatcher to use resource_manager_registry to get the appropriate manager.
  • geonode/resource/apps.py
    • Added run_setup_hooks to initialize resource_manager_registry when the app is ready.
  • geonode/resource/manager.py
    • Renamed ResourceManager to BaseResourceManager and updated internal references.
    • Removed the global resource_manager instance.
  • geonode/resource/registry.py
    • Added ResourceManagerRegistry class to register and retrieve specific resource managers based on model class, instance, type string, or UUID.
  • geonode/resource/settings.py
    • Added RESOURCE_MANAGERS tuple to list the paths of the new resource manager classes.
  • geonode/resource/tests.py
    • Updated imports and references to ResourceManager to BaseResourceManager.
  • geonode/security/models.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for setting default permissions.
  • geonode/security/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/services/tests.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for service-related dataset operations.
  • geonode/thumbs/tests/test_integration.py
    • Updated imports and references to ResourceManager to resource_manager_registry.
  • geonode/thumbs/tests/test_unit.py
    • Updated imports and calls to resource_manager to use resource_manager_registry in tests.
  • geonode/upload/handlers/common/raster.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for resource creation, updates, and thumbnail setting.
  • geonode/upload/handlers/common/remote.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for resource creation, updates, and thumbnail setting.
  • geonode/upload/handlers/common/vector.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for resource creation, updates, and thumbnail setting.
  • geonode/upload/handlers/remote/wms.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for thumbnail setting.
  • geonode/upload/handlers/sld/handler.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for setting styles.
  • geonode/upload/handlers/xml/handler.py
    • Updated imports and calls to resource_manager to use resource_manager_registry for updating XML files.
  • geonode/upload/utils.py
    • Updated imports and references to ResourceManager to BaseResourceManager.
Activity
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is an excellent and extensive refactoring that introduces a ResourceManagerRegistry and specialized manager classes for different resource types. This greatly improves the architecture by promoting separation of concerns, making the system more extensible and testable. The logic has been consistently moved from views and serializers into the new manager classes across the codebase.

My main feedback is on the implementation of the create methods in the new MapResourceManager and GeoAppResourceManager. They seem to replicate a pre-existing but inefficient pattern of calling update immediately after create, leading to redundant database operations. I've left specific comments with suggestions for simplification.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 17, 2026

Codecov Report

❌ Patch coverage is 83.89662% with 81 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.65%. Comparing base (15d278b) to head (1541d6a).
⚠️ Report is 5 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #14053      +/-   ##
==========================================
+ Coverage   74.58%   74.65%   +0.07%     
==========================================
  Files         951      958       +7     
  Lines       57245    57755     +510     
  Branches     7771     7857      +86     
==========================================
+ Hits        42694    43115     +421     
- Misses      12833    12885      +52     
- Partials     1718     1755      +37     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@mattiagiupponi mattiagiupponi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the resouce_registr has different method but few of them accept the same kind of input which makes confusing which one is responsible of what.
I think is better to divide a bit the methods to have something like:
get_for_instance
get_for_model
get_for_type

in this way it makes obvious which method to use and how.

I would be great also to have some type hint

@mattiagiupponi mattiagiupponi requested review from nrjadkry and removed request for Gpetrak March 25, 2026 09:28
@sijandh35 sijandh35 requested a review from nrjadkry April 2, 2026 06:47
@mattiagiupponi
Copy link
Copy Markdown
Contributor

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the resource management system by introducing a ResourceManagerRegistry and specialized managers for Datasets, Documents, Maps, and GeoApps. The previous global resource_manager is replaced with type-specific managers to centralize logic and improve extensibility. Feedback highlights a logic error in BaseResourceManager where default values were incorrectly assigned to the user object, redundant assignments in the GeoApp manager, and concerns regarding the use of QuerySet.update() bypassing model signals. Additionally, it is recommended to refine exception handling in the registry's lazy loader to avoid masking configuration issues.

for field in instance.ROLE_BASED_MANAGED_FIELDS:
if not user.can_change_resource_field(instance, field):
logger.debug("User can perform the action, the default value is set")
setattr(user, field, getattr(ResourceBase, field).field.default)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There is a logic error here. The code is attempting to set the default value of a field on the user object instead of the instance (the resource being managed). This will likely cause a crash or unexpected behavior since user objects typically do not have these resource-specific fields.

Suggested change
setattr(user, field, getattr(ResourceBase, field).field.default)
setattr(instance, field, getattr(ResourceBase, field).field.default)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed CLA Bot: community license agreement signed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implementation of a common ResourceManager base class for all resource types

4 participants