- accept role_id_or_name
authorMark Huang <mlhuang@cs.princeton.edu>
Mon, 2 Oct 2006 15:34:16 +0000 (15:34 +0000)
committerMark Huang <mlhuang@cs.princeton.edu>
Mon, 2 Oct 2006 15:34:16 +0000 (15:34 +0000)
PLC/Methods/AdmGrantRoleToPerson.py
PLC/Methods/AdmIsPersonInRole.py

index 09f285f..973d107 100644 (file)
@@ -21,16 +21,22 @@ class AdmGrantRoleToPerson(Method):
         PasswordAuth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
-        Roles.fields['role_id']
+        Mixed(Parameter(int, "Role identifier"),
+              Parameter(str, "Role name"))
         ]
 
     returns = Parameter(int, '1 if successful')
 
-    def call(self, auth, person_id_or_email, role_id):
+    def call(self, auth, person_id_or_email, role_id_or_name):
         # Get all roles
         roles = Roles(self.api)
-        if role_id not in roles:
-            raise PLCInvalidArgument, "Invalid role ID"
+        if role_id_or_name not in roles:
+            raise PLCInvalidArgument, "Invalid role identifier or name"
+
+        if isinstance(role_id_or_name, int):
+            role_id = role_id_or_name
+        else:
+            role_id = roles[role_id_or_name]
 
         # Get account information
         persons = Persons(self.api, [person_id_or_email])
index b5fc97e..ae3e04b 100644 (file)
@@ -21,21 +21,30 @@ class AdmIsPersonInRole(Method):
         PasswordAuth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
-        Roles.fields['role_id']
+        Mixed(Parameter(int, "Role identifier"),
+              Parameter(str, "Role name"))
         ]
 
     returns = Parameter(int, "1 if account has role, 0 otherwise")
 
     status = "useless"
 
-    def call(self, auth, person_id_or_email, role_id):
+    def call(self, auth, person_id_or_email, role_id_or_name):
         # This is a totally fucked up function. I have no idea why it
         # exists or who calls it, but here is how it is supposed to
         # work.
 
         # Only allow PI roles to be checked
         roles = Roles(self.api)
-        if not roles.has_key(role_id) or roles[role_id] != "pi":
+        if role_id_or_name not in roles:
+            raise PLCInvalidArgument, "Invalid role identifier or name"
+
+        if isinstance(role_id_or_name, int):
+            role_id = role_id_or_name
+        else:
+            role_id = roles[role_id_or_name]
+
+        if roles[role_id] != "pi":
             raise PLCInvalidArgument, "Only the PI role may be checked"
 
         # Get account information