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
7 import sys ##################################soners
8 sys.path.append('../../../../util')
9 from pl_to_geni import *
13 class AddRoleToPerson(Method):
15 Grants the specified role to the person.
17 PIs can only grant the tech and user roles to users and techs at
18 their sites. Admins can grant any role to any user.
20 Returns 1 if successful, faults otherwise.
23 roles = ['admin', 'pi']
27 Mixed(Role.fields['role_id'],
29 Mixed(Person.fields['person_id'],
30 Person.fields['email']),
33 returns = Parameter(int, '1 if successful')
35 def call(self, auth, role_id_or_name, person_id_or_email):
37 roles = Roles(self.api, [role_id_or_name])
39 raise PLCInvalidArgument, "Invalid role '%s'" % unicode(role_id_or_name)
42 # Get account information
43 persons = Persons(self.api, [person_id_or_email])
45 raise PLCInvalidArgument, "No such account"
48 if person['peer_id'] is not None:
49 raise PLCInvalidArgument, "Not a local account"
51 # Authenticated function
52 assert self.caller is not None
54 # Check if we can update this account
55 if not self.caller.can_update(person):
56 raise PLCPermissionDenied, "Not allowed to update specified account"
58 # Can only grant lesser (higher) roles to others
59 if 'admin' not in self.caller['roles'] and \
60 role['role_id'] <= min(self.caller['role_ids']):
61 raise PLCInvalidArgument, "Not allowed to grant that role"
63 if role['role_id'] not in person['role_ids']:
66 self.event_objects = {'Person': [person['person_id']],
67 'Role': [role['role_id']]}
68 self.message = "Role %d granted to person %d" % \
69 (role['role_id'], person['person_id'])
71 #erase the GENI rights so that PL will not be imcompatible with GENI ############################soners
72 (global_sr_tree, global_cr_tree) = get_tree_globals()
74 site_ids = cnx.query("SELECT site_id FROM person_slice WHERE person_id = "+person['person_id'])
76 (site_id, site_hrn) = site_to_auth(sid)
77 dbinfo = determine_dbinfo(site_hrn, global_sr_tree)
79 raise PLCInvalidArgument, "No GENI authority corresponding to the site"
83 querystr = "UPDATE "+tablename+" SET rights = '' WHERE pointer = "+person['person_id']