model:person: add Person.is_admin() to simplify authorization checks.
authorW. Trevor King <wking@tremily.us>
Sat, 6 Oct 2012 16:59:51 +0000 (12:59 -0400)
committerW. Trevor King <wking@tremily.us>
Sat, 6 Oct 2012 16:59:51 +0000 (12:59 -0400)
pygrader/handler/get.py
pygrader/handler/grade.py
pygrader/model/person.py

index 8be5b819692186749dca4746b50c81cafbbdc5ec..d3e69cb4065c5fd4d8a56b00a35e1b78c512e646 100644 (file)
@@ -373,7 +373,7 @@ def run(basedir, course, message, person, subject,
             hasattr(message, 'authenticated') and message.authenticated)
     if not authenticated:
         raise _UnsignedMessage()
-    if 'assistants' in person.groups or 'professors' in person.groups:
+    if person.is_admin():
         email = _get_admin_email(
             basedir=basedir, course=course, person=person, subject=subject)
     elif 'students' in person.groups:
index c803371231c0b92c9a6f6cc1bc2d84c5e09bcd2a..891495a06045c968cffc9b5bdbd695427a0b78a1 100644 (file)
@@ -179,9 +179,9 @@ def run(basedir, course, message, person, subject,
             hasattr(message, 'authenticated') and message.authenticated)
     if not authenticated:
         raise _UnsignedMessage()
-    if not ('professors' in person.groups or 'assistants' in person.groups):
+    if not person.is_admin():
         raise _PermissionViolationMessage(
-            person=person, allowed_groups=['professors', 'assistants'])
+            person=person, allowed_groups=person.admin_groups)
     student = _get_subject_student(course=course, subject=subject)
     assignment = _get_subject_assignment(course=course, subject=subject)
     grade = _get_grade(
index 27550526cedd0a47e787e8b7c0a8bc3b6d0e804a..8964d40247d1382e44442c602aa4d444b8152f17 100644 (file)
@@ -15,6 +15,8 @@
 # pygrader.  If not, see <http://www.gnu.org/licenses/>.
 
 class Person (object):
+    admin_groups = ['professors', 'assistants']
+
     def __init__(self, name, emails=None, pgp_key=None, aliases=None,
                  groups=None):
         self.name = name
@@ -42,3 +44,11 @@ class Person (object):
             return self.aliases[0]
         except KeyError:
             return self.name
+
+    def is_admin(self):
+        """Is this person an administrator for this course? True/False.
+        """
+        for group in self.admin_groups:
+            if group in self.groups:
+                return True
+        return False