From f020aca27f580238c12abce812fdffe577a0db94 Mon Sep 17 00:00:00 2001 From: Phil Weir Date: Thu, 30 May 2024 18:54:59 +0100 Subject: [PATCH] feat: add get_createable_resource_models to allow get_createable_resource_types to remain ID-only --- arches/app/permissions/arches_standard.py | 4 ++-- arches/app/utils/permission_backend.py | 3 +++ arches/app/views/base.py | 7 ++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arches/app/permissions/arches_standard.py b/arches/app/permissions/arches_standard.py index e1e1e1095a9..d2dd968f53e 100644 --- a/arches/app/permissions/arches_standard.py +++ b/arches/app/permissions/arches_standard.py @@ -418,8 +418,8 @@ def get_resource_types_by_perm(self, user: User, perms: str | Iterable[str]) -> graphs = set() nodegroups = self.get_nodegroups_by_perm(user, perms) for node in Node.objects.filter(nodegroup__in=nodegroups).prefetch_related("graph"): - if node.graph.isresource and str(node.graph_id) != settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID: - graphs.add(node.graph) + if node.graph.isresource and str(node.graph_id) != SystemSettings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID: + graphs.add(str(node.graph.pk)) return list(graphs) diff --git a/arches/app/utils/permission_backend.py b/arches/app/utils/permission_backend.py index ce320524c33..dea884eaf1b 100644 --- a/arches/app/utils/permission_backend.py +++ b/arches/app/utils/permission_backend.py @@ -167,6 +167,9 @@ def _get_permission_framework(): _PERMISSION_FRAMEWORK = ArchesStandardPermissionFramework() return _PERMISSION_FRAMEWORK +def get_createable_resource_models(user): + return GraphModel.objects.filter(pk__in=list(get_createable_resource_types(user))).all() + def assign_perm(perm, user_or_group, obj=None): return _get_permission_framework().assign_perm(perm, user_or_group, obj=obj) diff --git a/arches/app/views/base.py b/arches/app/views/base.py index b0c5b4b8028..49813cbd338 100644 --- a/arches/app/views/base.py +++ b/arches/app/views/base.py @@ -26,13 +26,12 @@ from django.views.generic import TemplateView from arches.app.datatypes.datatypes import DataTypeFactory from arches.app.utils.permission_backend import ( - get_createable_resource_types, + get_createable_resource_models, user_is_resource_reviewer, get_editable_resource_types, get_resource_types_by_perm, user_can_read_map_layers, ) -from arches.app.utils.permission_backend import get_createable_resource_types, user_is_resource_reviewer class BaseManagerView(TemplateView): @@ -52,9 +51,7 @@ def get_context_data(self, **kwargs): if self.request.user.has_perm("view_plugin", plugin): context["plugins"].append(plugin) - createable = list( - models.GraphModel.objects.filter(pk__in=list(get_createable_resource_types(self.request.user))).all() - ) + createable = list(get_createable_resource_models(self.request.user)) createable.sort(key=lambda x: x.name.lower()) context["createable_resources"] = JSONSerializer().serialize( createable,