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 ins 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 PLCCheckLocalPerson(person,"SetPersonPrimarySite")
37 # Authenticated function
38 assert self.caller is not None
40 # Non-admins can only update their own primary site
41 if 'admin' not in self.caller['roles'] and \
42 self.caller['person_id'] != person['person_id']:
43 raise PLCPermissionDenied, "Not allowed to update specified account"
45 # Get site information
46 sites = Sites(self.api, [site_id_or_login_base])
48 raise PLCInvalidArgument, "No such site"
51 PLCCheckLocalSite(site,"SetPersonPrimarySite")
53 if site['site_id'] not in person['site_ids']:
54 raise PLCInvalidArgument, "Not a member of the specified site"
56 person.set_primary_site(site)