Skip to content

Commit a12df18

Browse files
committed
sources/collections/concepts/mappings urls have mandatory parent/owner scopes
1 parent e8864c7 commit a12df18

6 files changed

Lines changed: 111 additions & 88 deletions

File tree

core/collections/views.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ class CollectionBaseView(BaseAPIView):
5757
permission_classes = (CanViewConceptDictionary,)
5858
queryset = Collection.objects.filter(is_active=True)
5959

60+
def verify_scope(self):
61+
has_owner_scope = self.has_owner_scope()
62+
has_no_kwargs = self.has_no_kwargs()
63+
if has_no_kwargs:
64+
if self.request.method not in ['GET', 'HEAD']:
65+
raise Http404()
66+
elif not has_owner_scope:
67+
raise Http404()
68+
6069
def set_parent_resource(self):
6170
from core.orgs.models import Organization
6271
from core.users.models import UserProfile

core/common/views.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class BaseAPIView(generics.GenericAPIView, PathWalkerMixin):
5151
facet_class = None
5252
total_count = 0
5353

54+
def has_no_kwargs(self):
55+
return len(self.kwargs.values()) == 0
56+
57+
def has_owner_scope(self):
58+
kwargs = self.kwargs.keys()
59+
return 'org' in kwargs or 'user' in kwargs
60+
61+
def has_concept_container_scope(self):
62+
kwargs = self.kwargs.keys()
63+
return 'source' in kwargs or 'collection' in kwargs
64+
65+
def has_parent_scope(self):
66+
return self.has_owner_scope() and self.has_concept_container_scope()
67+
5468
def _should_exclude_retired_from_search_results(self):
5569
if self.is_owner_document_model():
5670
return False
@@ -69,8 +83,12 @@ def is_verbose(self):
6983
def is_brief(self):
7084
return self.request.query_params.get(BRIEF_PARAM, False) in ['true', True]
7185

86+
def verify_scope(self):
87+
pass
88+
7289
def initial(self, request, *args, **kwargs):
7390
super().initial(request, *args, **kwargs)
91+
self.verify_scope()
7492
self.initialize(request, request.path_info, **kwargs)
7593

7694
def initialize(self, request, path_info_segment, **kwargs): # pylint: disable=unused-argument
@@ -577,6 +595,15 @@ def initial(self, request, *args, **kwargs):
577595
super().initial(request, *args, **kwargs)
578596
self.__set_params()
579597

598+
def verify_scope(self):
599+
has_parent_scope = self.has_parent_scope()
600+
has_no_kwargs = self.has_no_kwargs()
601+
if has_no_kwargs:
602+
if self.request.method not in ['GET', 'HEAD']:
603+
raise Http404()
604+
elif not has_parent_scope:
605+
raise Http404()
606+
580607
def get_filter_params(self):
581608
if self.params:
582609
return self.params

0 commit comments

Comments
 (0)