-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add handler for permissions workflow
- Loading branch information
1 parent
5d5a99a
commit 5738b29
Showing
5 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
######################################################################### | ||
# | ||
# Copyright (C) 2024 OSGeo | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
######################################################################### | ||
from abc import ABC | ||
|
||
from geonode.security.utils import AdvancedSecurityWorkflowManager | ||
|
||
|
||
class BasePermissionsHandler(ABC): | ||
""" | ||
Abstract permissions handler. | ||
This is the base class, all the permissions instances should | ||
inherit from this class. | ||
All the flows that touches the permissions will use this class | ||
(example advanced workflow) | ||
""" | ||
|
||
@staticmethod | ||
def fixup_perms(instance, perms_payload, *args, **kwargs): | ||
return perms_payload | ||
|
||
|
||
class AdvancedWorkflowPermissionsHandler(BasePermissionsHandler): | ||
""" | ||
Handler that takes care of adjusting the permissions for the advanced workflow | ||
""" | ||
|
||
@staticmethod | ||
def fixup_perms(instance, perms_payload, *args, **kwargs): | ||
# Fixup Advanced Workflow permissions | ||
return AdvancedSecurityWorkflowManager.get_permissions( | ||
instance.uuid, | ||
instance=instance, | ||
permissions=perms_payload, | ||
created=kwargs.get("created"), | ||
approval_status_changed=kwargs.get("approval_status_changed"), | ||
group_status_changed=kwargs.get("group_status_changed"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
######################################################################### | ||
# | ||
# Copyright (C) 2024 OSGeo | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
######################################################################### | ||
from django.conf import settings | ||
from django.utils.module_loading import import_string | ||
from geonode.security.handlers import BasePermissionsHandler | ||
|
||
|
||
class PermissionsHandlerRegistry: | ||
|
||
REGISTRY = [] | ||
|
||
def init_registry(self): | ||
self._register() | ||
self.sanity_checks() | ||
|
||
def add(self, module_path): | ||
item = import_string(module_path)() | ||
self.__check_item(item) | ||
self.REGISTRY.append(item) | ||
|
||
def _register(self): | ||
for module_path in settings.PERMISSIONS_HANDLERS: | ||
self.add(module_path) | ||
|
||
def sanity_checks(self): | ||
for item in self.REGISTRY: | ||
self.__check_item(item) | ||
|
||
def __check_item(self, item): | ||
""" | ||
Ensure that the handler is a subclass of BasePermissionsHandler | ||
""" | ||
if not isinstance(item, BasePermissionsHandler): | ||
raise Exception(f"Handler {item} is not a subclass of BasePermissionsHandler") | ||
|
||
def fixup_perms(self, instance, payload, *args, **kwargs): | ||
for handler in self.REGISTRY: | ||
payload = handler.fixup_perms(instance, payload, *args, **kwargs) | ||
return payload | ||
|
||
@classmethod | ||
def get_registry(cls): | ||
return PermissionsHandlerRegistry.REGISTRY | ||
|
||
|
||
permissions_registry = PermissionsHandlerRegistry() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters