-
Jean-Sébastien Caux authoredbed39b80
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
permissions.py 1.02 KiB
__copyright__ = "Copyright © Stichting SciPost (SciPost Foundation)"
__license__ = "AGPL v3"
from django.contrib.auth.decorators import user_passes_test
from django.core.exceptions import PermissionDenied
def fellowship_required():
"""Require user to have any Fellowship or Administrational permissions."""
def test(u):
if u.is_authenticated:
if hasattr(u, 'contributor') and u.contributor.fellowships.exists():
# Fellow
return True
raise PermissionDenied
return user_passes_test(test)
def fellowship_or_admin_required():
"""Require user to have any Fellowship or Administrational permissions."""
def test(u):
if u.is_authenticated:
if hasattr(u, 'contributor') and u.contributor.fellowships.exists():
# Fellow
return True
if u.has_perm('scipost.can_oversee_refereeing'):
# Administrator
return True
raise PermissionDenied
return user_passes_test(test)