From 00847d961ad66a4cd8e83a659e7f83d19d01ff29 Mon Sep 17 00:00:00 2001 From: Mark Huang Date: Mon, 2 Oct 2006 15:34:16 +0000 Subject: [PATCH] - accept role_id_or_name --- PLC/Methods/AdmGrantRoleToPerson.py | 14 ++++++++++---- PLC/Methods/AdmIsPersonInRole.py | 15 ++++++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/PLC/Methods/AdmGrantRoleToPerson.py b/PLC/Methods/AdmGrantRoleToPerson.py index 09f285fb..973d107a 100644 --- a/PLC/Methods/AdmGrantRoleToPerson.py +++ b/PLC/Methods/AdmGrantRoleToPerson.py @@ -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]) diff --git a/PLC/Methods/AdmIsPersonInRole.py b/PLC/Methods/AdmIsPersonInRole.py index b5fc97e8..ae3e04bc 100644 --- a/PLC/Methods/AdmIsPersonInRole.py +++ b/PLC/Methods/AdmIsPersonInRole.py @@ -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 -- 2.47.0