Merge remote-tracking branch 'origin/pycurl' into planetlab-4_0-branch
[plcapi.git] / PLC / Methods / AdmIsPersonInRole.py
index 615546d..b32ab03 100644 (file)
@@ -2,7 +2,7 @@ from PLC.Faults import *
 from PLC.Method import Method
 from PLC.Parameter import Parameter, Mixed
 from PLC.Persons import Person, Persons
-from PLC.Auth import PasswordAuth
+from PLC.Auth import Auth
 from PLC.Roles import Role, Roles
 
 class AdmIsPersonInRole(Method):
@@ -20,7 +20,7 @@ class AdmIsPersonInRole(Method):
     roles = ['admin', 'pi', 'user', 'tech']
 
     accepts = [
-        PasswordAuth(),
+        Auth(),
         Mixed(Person.fields['person_id'],
               Person.fields['email']),
         Mixed(Parameter(int, "Role identifier"),
@@ -36,9 +36,9 @@ class AdmIsPersonInRole(Method):
 
         # Only allow PI roles to be checked
         roles = {}
-        for role_id, role in Roles(self.api).iteritems():
-            roles[role_id] = role['name']
-            roles[role['name']] = role_id
+        for role in Roles(self.api):
+            roles[role['role_id']] = role['name']
+            roles[role['name']] = role['role_id']
 
         if role_id_or_name not in roles:
             raise PLCInvalidArgument, "Invalid role identifier or name"
@@ -59,7 +59,7 @@ class AdmIsPersonInRole(Method):
         if not persons:
             return 0
 
-        person = persons.values()[0]
+        person = persons[0]
 
         if role_id in person['role_ids']:
             return 1