1 from PLC.Faults import *
2 from PLC.Auth import Auth
3 from PLC.Method import Method
4 from PLC.Parameter import Parameter, Mixed
5 from PLC.Sites import Site, Sites
6 from PLC.Persons import Person, Persons
7 from PLC.PersonTags import PersonTags, PersonTag
8 from PLC.Namespace import email_to_hrn
9 from PLC.TagTypes import TagTypes
11 class AddPersonToSite(Method):
13 Adds the specified person to the specified site. If the person is
14 already a member of the site, no errors are returned. Does not
15 change the person's primary site.
17 Returns 1 if successful, faults otherwise.
24 Mixed(Person.fields['person_id'],
25 Person.fields['email']),
26 Mixed(Site.fields['site_id'],
27 Site.fields['login_base'])
30 returns = Parameter(int, '1 if successful')
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 # Get site information
43 sites = Sites(self.api, [site_id_or_login_base])
45 raise PLCInvalidArgument, "No such site"
48 if site['peer_id'] is not None:
49 raise PLCInvalidArgument, "Not a local site"
51 if site['site_id'] not in person['site_ids']:
52 site.add_person(person)
55 self.event_objects = {'Site': [site['site_id']],
56 'Person': [person['person_id']]}
57 self.message = 'Person %d added to site %d' % \
58 (person['person_id'], site['site_id'])
60 # maintain person's hrn
61 # only if at this point we have a single site
62 # which means, there was no site attached to person upon entering this call
64 had_no_site= (len (person['site_ids']) == 0)
66 login_base=site['login_base']
67 root_auth = self.api.config.PLC_HRN_ROOT
68 hrn=email_to_hrn("%s.%s"%(root_auth,login_base),person['email'])
70 tag_type = TagTypes(self.api,{'tagname':tagname})[0]
71 person_tags=PersonTags(self.api,{'tagname':tagname,'person_id':person['person_id']})
73 person_tag = PersonTag(self.api)
74 person_tag['person_id'] = person['person_id']
75 person_tag['tag_type_id'] = tag_type['tag_type_id']
76 person_tag['tagname'] = tagname
77 person_tag['value'] = hrn
80 person_tag = person_tags[0]
81 person_tag['value'] = value
84 print "BEG Warning, cannot maintain person's hrn, %s"%e
87 print "END Warning, cannot maintain person's hrn, %s"%e