old_contents: # Copyright (c) 2011-2014 Berkeley Model United Nations. All rights reserved.
  # Use of this source code is governed by a BSD License (see LICENSE).
  
  from rest_framework import permissions
  
  
  class IsSuperuserOrReadOnly(permissions.BasePermission):
      '''Allow writes if superuser, read-only otherwise.'''
  
      def has_permission(self, request, view):
          return (request.user.is_superuser or
                  request.method in permissions.SAFE_METHODS)
  
  
  class IsUserOrSuperuser(permissions.BasePermission):
      '''Accept only the users themselves or superusers.'''
  
      def has_object_permission(self, request, view, obj):
          return request.user.is_superuser or request.user == obj
  
  
  class IsAdvisorOrSuperuser(permissions.BasePermission):
      '''Accept only the school's advisor or superusers.'''
  
      def has_object_permission(self, request, view, obj):
          return request.user.is_superuser or request.user == obj.advisor
  
  
  class IsPostOrSuperuserOnly(permissions.BasePermission):
      '''Accept POST (create) requests, superusers-only otherwise.'''
  
      def has_object_permissions(self, request, view, obj):
          return request.method == 'POST' or request.user.is_superuser
  
new_contents: # Copyright (c) 2011-2014 Berkeley Model United Nations. All rights reserved.
  # Use of this source code is governed by a BSD License (see LICENSE).
  
  from rest_framework import permissions
  
  
  class IsSuperuserOrReadOnly(permissions.BasePermission):
      '''Allow writes if superuser, read-only otherwise.'''
  
      def has_permission(self, request, view):
          return (request.user.is_superuser or
                  request.method in permissions.SAFE_METHODS)
  
  
  class IsUserOrSuperuser(permissions.BasePermission):
      '''Accept only the users themselves or superusers.'''
  
      def has_object_permission(self, request, view, obj):
          return request.user.is_superuser or request.user == obj
  
  
  class IsAdvisorOrSuperuser(permissions.BasePermission):
      '''Accept only the school's advisor or superusers.'''
  
      def has_object_permission(self, request, view, obj):
          return request.user.is_superuser or request.user == obj.advisor
  
  
  class IsPostOrSuperuserOnly(permissions.BasePermission):
      '''Accept POST (create) requests, superusers-only otherwise.'''
  
      def has_permission(self, request, view):
          return request.method == 'POST' or request.user.is_superuser
  
subject: Make IsPostOrSuperuserOnly a non-object-level permission.