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 def call(self, auth, person_id_or_email, site_id_or_login_base):
29 # Get account information
30 persons = Persons(self.api, [person_id_or_email])
32 raise PLCInvalidArgument, "No such account"
35 if person['peer_id'] is not None:
36 raise PLCInvalidArgument, "Not a local account"
38 # Authenticated function
39 assert self.caller is not None
41 # Non-admins can only update their own primary site
42 if 'admin' not in self.caller['roles'] and \
43 self.caller['person_id'] != person['person_id']:
44 raise PLCPermissionDenied, "Not allowed to update specified account"
46 # Get site information
47 sites = Sites(self.api, [site_id_or_login_base])
49 raise PLCInvalidArgument, "No such site"
52 if site['peer_id'] is not None:
53 raise PLCInvalidArgument, "Not a local site"
55 if site['site_id'] not in person['site_ids']:
56 raise PLCInvalidArgument, "Not a member of the specified site"
58 person.set_primary_site(site)