X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAdmIsPersonInRole.py;h=b32ab03528624d2f9657346326a1748d7a4b1fbd;hb=0395bfd9e88b0f5fbfcbfd91c95fa5baaa9e7fe0;hp=ae3e04bc68e93e39e363640ca700d908e308e325;hpb=00847d961ad66a4cd8e83a659e7f83d19d01ff29;p=plcapi.git diff --git a/PLC/Methods/AdmIsPersonInRole.py b/PLC/Methods/AdmIsPersonInRole.py index ae3e04b..b32ab03 100644 --- a/PLC/Methods/AdmIsPersonInRole.py +++ b/PLC/Methods/AdmIsPersonInRole.py @@ -1,24 +1,26 @@ -from types import StringTypes - 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.Roles import Roles +from PLC.Auth import Auth +from PLC.Roles import Role, Roles class AdmIsPersonInRole(Method): """ + Deprecated. Functionality can be implemented with GetPersons. + Returns 1 if the specified account has the specified role, 0 otherwise. This function differs from AdmGetPersonRoles() in that any authorized user can call it. It is currently restricted to verifying PI roles. """ + status = "deprecated" + roles = ['admin', 'pi', 'user', 'tech'] accepts = [ - PasswordAuth(), + Auth(), Mixed(Person.fields['person_id'], Person.fields['email']), Mixed(Parameter(int, "Role identifier"), @@ -27,15 +29,17 @@ class AdmIsPersonInRole(Method): returns = Parameter(int, "1 if account has role, 0 otherwise") - status = "useless" - 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) + roles = {} + 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" @@ -55,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