@@ -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