@@ -59,12 +59,13 @@ class Media:
5959
6060 def __init__ (self , user , * args , ** kwargs ):
6161 self .user = user
62+ self .fake_person = None
6263 self .person = get_person_for_user (user )
6364 if kwargs .get ('data' , None ):
6465 kwargs ['data' ].update ({'person' : self .person .pk })
6566 if is_secretariat (self .user ) and 'from_fake_user' in kwargs ['data' ].keys ():
66- fake_person = PersonOrOrgInfo .objects .get (pk = kwargs ['data' ]['from_fake_user' ])
67- kwargs ['data' ].update ({'person' : fake_person .pk })
67+ self . fake_person = PersonOrOrgInfo .objects .get (pk = kwargs ['data' ]['from_fake_user' ])
68+ kwargs ['data' ].update ({'person' : self . fake_person .pk })
6869 super (LiaisonForm , self ).__init__ (* args , ** kwargs )
6970 self .hm = IETFHM
7071 self .set_from_field ()
@@ -357,17 +358,21 @@ def clean_organization(self):
357358 if not to_code or not from_code :
358359 return to_code
359360 all_entities = []
360- for i in self .hm .get_entities_for_person (self .person ):
361+ person = self .fake_person or self .person
362+ for i in self .hm .get_entities_for_person (person ):
361363 all_entities += i [1 ]
362364 # If the from entity is one in wich the user has full privileges the to entity could be anyone
363365 if from_code in [i [0 ] for i in all_entities ]:
364366 return to_code
365- sdo_codes = ['sdo_%s' % i .sdo .pk for i in self . person .liaisonmanagers_set .all ().distinct ()]
367+ sdo_codes = ['sdo_%s' % i .sdo .pk for i in person .liaisonmanagers_set .all ().distinct ()]
366368 if to_code in sdo_codes :
367369 return to_code
368370 entity = self .get_to_entity ()
369371 entity_name = entity and entity .name or to_code
370- raise forms .ValidationError ('You are not allowed to send a liaison to: %s' % entity_name )
372+ if self .fake_person :
373+ raise forms .ValidationError ('%s is not allowed to send a liaison to: %s' % (self .fake_person , entity_name ))
374+ else :
375+ raise forms .ValidationError ('You are not allowed to send a liaison to: %s' % entity_name )
371376
372377
373378class EditLiaisonForm (LiaisonForm ):
0 commit comments