1 from PLC.Faults import *
2 from PLC.Method import Method
3 from PLC.Parameter import Parameter, Mixed
4 from PLC.Persons import Person, Persons
5 from PLC.Auth import Auth
6 from PLC.Roles import Role, Roles
8 class DeleteRoleFromPerson(Method):
10 Deletes the specified role from the person.
12 PIs can only revoke the tech and user roles from users and techs
13 at their sites. ins can revoke any role from any user.
15 Returns 1 if successful, faults otherwise.
18 roles = ['admin', 'pi']
22 Mixed(Role.fields['role_id'],
24 Mixed(Person.fields['person_id'],
25 Person.fields['email']),
28 returns = Parameter(int, '1 if successful')
31 def call(self, auth, role_id_or_name, person_id_or_email):
34 for role in Roles(self.api):
35 roles[role['role_id']] = role['name']
36 roles[role['name']] = role['role_id']
38 if role_id_or_name not in roles:
39 raise PLCInvalidArgument, "Invalid role identifier or name"
41 if isinstance(role_id_or_name, int):
42 role_id = role_id_or_name
44 role_id = roles[role_id_or_name]
46 # Get account information
47 persons = Persons(self.api, [person_id_or_email])
49 raise PLCInvalidArgument, "No such account"
52 PLCCheckLocalPerson(person,"DeleteRoleFromPerson")
54 # Authenticated function
55 assert self.caller is not None
57 # Check if we can update this account
58 if not self.caller.can_update(person):
59 raise PLCPermissionDenied, "Not allowed to update specified account"
61 # Can only revoke lesser (higher) roles from others
62 if 'admin' not in self.caller['roles'] and \
63 role_id <= min(self.caller['role_ids']):
64 raise PLCPermissionDenied, "Not allowed to revoke that role"
66 if role_id in person['role_ids']:
67 person.remove_role(role_id)
69 self.object_ids = [person['person_id']]