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