Skip to content

Commit

Permalink
feat: add get_createable_resource_models to allow get_createable_reso…
Browse files Browse the repository at this point in the history
…urce_types to remain ID-only
  • Loading branch information
philtweir committed May 30, 2024
1 parent fccf567 commit f020aca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions arches/app/permissions/arches_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
3 changes: 3 additions & 0 deletions arches/app/utils/permission_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 2 additions & 5 deletions arches/app/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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,
Expand Down

0 comments on commit f020aca

Please sign in to comment.