Add permission to org pages
This commit is contained in:
parent
82ec9e098d
commit
cae65de1d5
1 changed files with 11 additions and 0 deletions
|
@ -83,6 +83,13 @@ class OrganizationBase(object):
|
||||||
self.request.profile in org if self.request.user.is_authenticated else False
|
self.request.profile in org if self.request.user.is_authenticated else False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def can_access(self, org):
|
||||||
|
if self.request.user.is_superuser:
|
||||||
|
return True
|
||||||
|
if org is None:
|
||||||
|
org = self.object
|
||||||
|
return self.is_member(org) or self.can_edit_organization(org)
|
||||||
|
|
||||||
|
|
||||||
class OrganizationMixin(OrganizationBase):
|
class OrganizationMixin(OrganizationBase):
|
||||||
context_object_name = "organization"
|
context_object_name = "organization"
|
||||||
|
@ -287,6 +294,8 @@ class OrganizationProblems(ProblemList, OrganizationExternalMixin):
|
||||||
ret = super().get_organization_from_url(request, *args, **kwargs)
|
ret = super().get_organization_from_url(request, *args, **kwargs)
|
||||||
if ret:
|
if ret:
|
||||||
return ret
|
return ret
|
||||||
|
if not self.can_access(self.organization):
|
||||||
|
return HttpResponseBadRequest()
|
||||||
self.setup_problem_list(request)
|
self.setup_problem_list(request)
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@ -308,6 +317,8 @@ class OrganizationContests(ContestList, OrganizationExternalMixin):
|
||||||
ret = super().get_organization_from_url(request, *args, **kwargs)
|
ret = super().get_organization_from_url(request, *args, **kwargs)
|
||||||
if ret:
|
if ret:
|
||||||
return ret
|
return ret
|
||||||
|
if not self.can_access(self.organization):
|
||||||
|
return HttpResponseBadRequest()
|
||||||
return super().get(request, *args, **kwargs)
|
return super().get(request, *args, **kwargs)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
Loading…
Reference in a new issue