2 from PLC.Faults import *
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Persons import Person, Persons
6 from PLC.Auth import Auth
7 from PLC.Roles import Role, Roles
9 class DeleteRoleFromPerson(Method):
11 Deletes the specified role from the person.
13 PIs can only revoke the tech and user roles from users and techs
14 at their sites. ins can revoke any role from any user.
16 Returns 1 if successful, faults otherwise.
19 roles = ['admin', 'pi']
23 Mixed(Role.fields['role_id'],
25 Mixed(Person.fields['person_id'],
26 Person.fields['email']),
29 returns = Parameter(int, '1 if successful')
31 def call(self, auth, role_id_or_name, person_id_or_email):
33 roles = Roles(self.api, [role_id_or_name])
35 raise PLCInvalidArgument, "Invalid role '%s'" % unicode(role_id_or_name)
38 # Get account information
39 persons = Persons(self.api, [person_id_or_email])
41 raise PLCInvalidArgument, "No such account"
44 if person['peer_id'] is not None:
45 raise PLCInvalidArgument, "Not a local account"
47 # Authenticated function
48 assert self.caller is not None
50 # Check if we can update this account
51 if not self.caller.can_update(person):
52 raise PLCPermissionDenied, "Not allowed to update specified account"
54 # Can only revoke lesser (higher) roles from others
55 if 'admin' not in self.caller['roles'] and \
56 role['role_id'] <= min(self.caller['role_ids']):
57 raise PLCPermissionDenied, "Not allowed to revoke that role"
59 if role['role_id'] in person['role_ids']:
60 person.remove_role(role)
63 self.event_objects = {'Person': [person['person_id']],
64 'Role': [role['role_id']]}
65 self.message = "Role %d revoked from person %d" % \
66 (role['role_id'], person['person_id'])