X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=PLC%2FMethods%2FAddPersonToSite.py;h=64c5261e8589bf7a9d4deefca996c0858a5ba76a;hb=465305e5d5738d3fde3121a8d92d31db6c77871b;hp=595399f52cdb3efcffe7f58f8ef73e8e18326996;hpb=e58db379e1197b73d3b6f014d5afd51ce852b43c;p=plcapi.git diff --git a/PLC/Methods/AddPersonToSite.py b/PLC/Methods/AddPersonToSite.py index 595399f..64c5261 100644 --- a/PLC/Methods/AddPersonToSite.py +++ b/PLC/Methods/AddPersonToSite.py @@ -1,11 +1,12 @@ -# $Id$ -# $URL$ from PLC.Faults import * +from PLC.Auth import Auth from PLC.Method import Method from PLC.Parameter import Parameter, Mixed -from PLC.Persons import Person, Persons from PLC.Sites import Site, Sites -from PLC.Auth import Auth +from PLC.Persons import Person, Persons +from PLC.PersonTags import PersonTags, PersonTag +from PLC.Namespace import email_to_hrn +from PLC.TagTypes import TagTypes class AddPersonToSite(Method): """ @@ -56,4 +57,34 @@ class AddPersonToSite(Method): self.message = 'Person %d added to site %d' % \ (person['person_id'], site['site_id']) + # maintain person's hrn + # only if at this point we have a single site + # which means, there was no site attached to person upon entering this call + try: + had_no_site= (len (person['site_ids']) == 0) + if had_no_site: + login_base=site['login_base'] + root_auth = self.api.config.PLC_HRN_ROOT + hrn=email_to_hrn("%s.%s"%(root_auth,login_base),person['email']) + tagname='hrn' + tag_type = TagTypes(self.api,{'tagname':tagname})[0] + person_tags=PersonTags(self.api,{'tagname':tagname,'person_id':person['person_id']}) + if not person_tags: + person_tag = PersonTag(self.api) + person_tag['person_id'] = person['person_id'] + person_tag['tag_type_id'] = tag_type['tag_type_id'] + person_tag['tagname'] = tagname + person_tag['value'] = hrn + person_tag.sync() + else: + person_tag = person_tags[0] + person_tag['value'] = value + person_tag.sync() + except Exception,e: + print "BEG Warning, cannot maintain person's hrn, %s"%e + import traceback + traceback.print_exc() + print "END Warning, cannot maintain person's hrn, %s"%e + + return 1