3 from PLC.Faults import *
4 from PLC.Method import Method
5 from PLC.Parameter import Parameter, Mixed
6 from PLC.Persons import Person, Persons
7 from PLC.Auth import Auth
8 from PLC.Roles import Role, Roles
10 class DeleteRoleFromPerson(Method):
12 Deletes the specified role from the person.
14 PIs can only revoke the tech and user roles from users and techs
15 at their sites. ins can revoke any role from any user.
17 Returns 1 if successful, faults otherwise.
20 roles = ['admin', 'pi']
24 Mixed(Role.fields['role_id'],
26 Mixed(Person.fields['person_id'],
27 Person.fields['email']),
30 returns = Parameter(int, '1 if successful')
32 def call(self, auth, role_id_or_name, person_id_or_email):
34 roles = Roles(self.api, [role_id_or_name])
36 raise PLCInvalidArgument, "Invalid role '%s'" % unicode(role_id_or_name)
39 # Get account information
40 persons = Persons(self.api, [person_id_or_email])
42 raise PLCInvalidArgument, "No such account"
45 if person['peer_id'] is not None:
46 raise PLCInvalidArgument, "Not a local account"
48 # Authenticated function
49 assert self.caller is not None
51 # Check if we can update this account
52 if not self.caller.can_update(person):
53 raise PLCPermissionDenied, "Not allowed to update specified account"
55 # Can only revoke lesser (higher) roles from others
56 if 'admin' not in self.caller['roles'] and \
57 role['role_id'] <= min(self.caller['role_ids']):
58 raise PLCPermissionDenied, "Not allowed to revoke that role"
60 if role['role_id'] in person['role_ids']:
61 person.remove_role(role)
64 self.event_objects = {'Person': [person['person_id']],
65 'Role': [role['role_id']]}
66 self.message = "Role %d revoked from person %d" % \
67 (role['role_id'], person['person_id'])