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 AddPersonToSite(Method):
10 Adds the specified person to the specified site. If the person is
11 already a member of the site, no errors are returned. Does not
12 change the person's primary site.
14 Returns 1 if successful, faults otherwise.
21 Mixed(Person.fields['person_id'],
22 Person.fields['email']),
23 Mixed(Site.fields['site_id'],
24 Site.fields['login_base'])
27 returns = Parameter(int, '1 if successful')
29 def call(self, auth, person_id_or_email, site_id_or_login_base):
30 # Get account information
31 persons = Persons(self.api, [person_id_or_email])
33 raise PLCInvalidArgument, "No such account"
36 if person['peer_id'] is not None:
37 raise PLCInvalidArgument, "Not a local account"
39 # Get site information
40 sites = Sites(self.api, [site_id_or_login_base])
42 raise PLCInvalidArgument, "No such site"
45 if site['peer_id'] is not None:
46 raise PLCInvalidArgument, "Not a local site"
48 if site['site_id'] not in person['site_ids']:
49 site.add_person(person)
52 self.event_objects = {'Site': [site['site_id']],
53 'Person': [person['person_id']]}
54 self.message = 'Person %d added to site %d' % \
55 (person['person_id'], site['site_id'])