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.Sites import Site, Sites
6 from PLC.Auth import Auth
8 class SetPersonPrimarySite(Method):
10 Makes the specified site the person's primary site. The person
11 must already be a member of the site.
13 Admins may update anyone. All others may only update themselves.
16 roles = ['admin', 'pi', 'user', 'tech']
20 Mixed(Person.fields['person_id'],
21 Person.fields['email']),
22 Mixed(Site.fields['site_id'],
23 Site.fields['login_base'])
26 returns = Parameter(int, '1 if successful')
28 object_type = 'Person'
30 def call(self, auth, person_id_or_email, site_id_or_login_base):
31 # Get account information
32 persons = Persons(self.api, [person_id_or_email])
34 raise PLCInvalidArgument, "No such account"
37 if person['peer_id'] is not None:
38 raise PLCInvalidArgument, "Not a local account"
40 # Authenticated function
41 assert self.caller is not None
43 # Non-admins can only update their own primary site
44 if 'admin' not in self.caller['roles'] and \
45 self.caller['person_id'] != person['person_id']:
46 raise PLCPermissionDenied, "Not allowed to update specified account"
48 # Get site information
49 sites = Sites(self.api, [site_id_or_login_base])
51 raise PLCInvalidArgument, "No such site"
54 if site['peer_id'] is not None:
55 raise PLCInvalidArgument, "Not a local site"
57 if site['site_id'] not in person['site_ids']:
58 raise PLCInvalidArgument, "Not a member of the specified site"
60 person.set_primary_site(site)