Skip to content

Commit 07c1eea

Browse files
committed
Merged in changes from esanchez@yaco.es, changesets 2790-2791. Refined handling of the To: and From: address lists when the Liaison Manager is also a WG Chair or AD.
- Legacy-Id: 2801
2 parents 63bc9cf + 4dc7533 commit 07c1eea

5 files changed

Lines changed: 80 additions & 11 deletions

File tree

ietf/liaisons/forms.py

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ def set_organization_field(self):
247247

248248
def get_post_only(self):
249249
from_entity = self.get_from_entity()
250-
if self.person.liaisonmanagers_set.filter(sdo=from_entity.obj):
251-
return True
252-
return False
250+
if is_secretariat(self.user) or self.person.sdoauthorizedindividual_set.filter(sdo=from_entity.obj):
251+
return False
252+
return True
253253

254254
def clean(self):
255255
if 'send' in self.data.keys() and self.get_post_only():
@@ -271,15 +271,24 @@ def get_to_entity(self):
271271
return organization
272272

273273
def set_from_field(self):
274-
if is_secretariat(self.user) or is_sdo_liaison_manager(self.person):
274+
if is_secretariat(self.user):
275+
self.fields['from_field'].choices = self.hm.get_all_incoming_entities()
276+
elif is_sdo_liaison_manager(self.person):
275277
self.fields['from_field'].choices = self.hm.get_all_incoming_entities()
278+
all_entities = []
279+
for i in self.hm.get_entities_for_person(self.person):
280+
all_entities += i[1]
281+
if all_entities:
282+
self.fields['from_field'].widget.full_power_on = [i[0] for i in all_entities]
283+
self.fields['from_field'].widget.reduced_to_set = ['sdo_%s' % i.sdo.pk for i in self.person.liaisonmanagers_set.all().distinct()]
276284
else:
277285
self.fields['from_field'].choices = self.hm.get_entities_for_person(self.person)
278286
self.fields['from_field'].widget.submitter = unicode(self.person)
279287
self.fieldsets[0] = ('From', ('from_field', 'replyto', 'approved'))
280288

281289
def set_organization_field(self):
282-
if is_sdo_liaison_manager(self.person):
290+
# If the user is a liaison manager and is nothing more, reduce the To field to his SDOs
291+
if not self.hm.get_entities_for_person(self.person) and is_sdo_liaison_manager(self.person):
283292
sdos = [i.sdo for i in self.person.liaisonmanagers_set.all().distinct()]
284293
self.fields['organization'].choices = [('sdo_%s' % i.pk, i.sdo_name) for i in sdos]
285294
else:
@@ -322,6 +331,24 @@ def clean_to_poc(self):
322331
self.check_email(value)
323332
return value
324333

334+
def clean_organization(self):
335+
to_code = self.cleaned_data.get('organization', None)
336+
from_code = self.cleaned_data.get('from_field', None)
337+
if not to_code or not from_code:
338+
return to_code
339+
all_entities = []
340+
for i in self.hm.get_entities_for_person(self.person):
341+
all_entities += i[1]
342+
# If the from entity is one in wich the user has full privileges the to entity could be anyone
343+
if from_code in [i[0] for i in all_entities]:
344+
return to_code
345+
sdo_codes = ['sdo_%s' % i.sdo.pk for i in self.person.liaisonmanagers_set.all().distinct()]
346+
if to_code in sdo_codes:
347+
return to_code
348+
entity = self.get_to_entity()
349+
entity_name = entity and entity.name or to_code
350+
raise forms.ValidationError('You are not allowed to send a liaison to: %s' % entity_name)
351+
325352

326353
class EditLiaisonForm(LiaisonForm):
327354

ietf/liaisons/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from ietf.idtracker.models import Area, IETFWG
22
from ietf.liaisons.models import SDOs, LiaisonManagers
33
from ietf.liaisons.accounts import (is_ietfchair, is_iabchair, is_iab_executive_director,
4-
get_ietf_chair, get_iab_chair, get_iab_executive_director)
4+
get_ietf_chair, get_iab_chair, get_iab_executive_director,
5+
is_secretariat)
56

67
IETFCHAIR = {'name': u'The IETF Chair', 'address': u'chair@ietf.org'}
78
IESG = {'name': u'The IESG', 'address': u'iesg@ietf.org'}
@@ -194,8 +195,10 @@ def get_from_cc(self, person=None):
194195
return [manager.person]
195196
return []
196197

197-
def post_only(self, person):
198-
return bool(self.obj.liaisonmanagers_set.filter(person=person))
198+
def post_only(self, person, user):
199+
if is_secretariat(user) or person.sdoauthorizedindividual_set.filter(sdo=self.obj):
200+
return False
201+
return True
199202

200203
def full_user_list(self):
201204
result = [i.person for i in self.obj.liaisonmanagers_set.all().distinct()]

ietf/liaisons/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def get_info(request):
7575
[i.email() for i in from_entity.get_from_cc(person=person)],
7676
'poc': [i.email() for i in to_entity.get_poc()],
7777
'needs_approval': from_entity.needs_approval(person=person),
78-
'post_only': from_entity.post_only(person=person)})
78+
'post_only': from_entity.post_only(person=person, user=request.user)})
7979
if is_secretariat(request.user):
8080
full_list = [(i.pk, i.email()) for i in from_entity.full_user_list()]
8181
full_list.sort(lambda x,y: cmp(x[1], y[1]))

ietf/liaisons/widgets.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
class FromWidget(Select):
99

10+
def __init__(self, *args, **kwargs):
11+
super(FromWidget, self).__init__(*args, **kwargs)
12+
self.full_power_on = []
13+
self.reduced_to_set = []
14+
1015
def render(self, name, value, attrs=None, choices=()):
1116
all_choices = list(self.choices) + list(choices)
1217
if len(all_choices)!=1 or \
@@ -21,6 +26,13 @@ def render(self, name, value, attrs=None, choices=()):
2126
text = option[1]
2227
base = u'<input type="hidden" value="%s" id="id_%s" name="%s" />%s' % (value, name, name, text)
2328
base += u' (<a class="from_mailto" href="">' + self.submitter + u'</a>)'
29+
if self.full_power_on:
30+
base += '<div style="display: none;" class="reducedToOptions">'
31+
for from_code in self.full_power_on:
32+
base += '<span class="full_power_on_%s"></span>' % from_code
33+
for to_code in self.reduced_to_set:
34+
base += '<span class="reduced_to_set_%s"></span>' % to_code
35+
base += '</div>'
2436
return mark_safe(base)
2537

2638

static/js/liaisons.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,37 @@
317317
return false;
318318
};
319319

320+
var checkFrom = function() {
321+
var reduce_options = form.find('.reducedToOptions');
322+
if (!reduce_options.length) {
323+
updateInfo();
324+
return;
325+
}
326+
var to_select = organization;
327+
var from_entity = from.val();
328+
if (!reduce_options.find('.full_power_on_' + from_entity).length) {
329+
to_select.find('optgroup').eq(1).hide();
330+
to_select.find('option').each(function() {
331+
if (!reduce_options.find('.reduced_to_set_' + $(this).val()).length) {
332+
$(this).hide();
333+
} else {
334+
$(this).show();
335+
}
336+
});
337+
if (!to_select.find('option:selected').is(':visible')) {
338+
to_select.find('option:selected').removeAttr('selected');
339+
}
340+
} else {
341+
to_select.find('optgroup').show();
342+
to_select.find('option').show();
343+
}
344+
updateInfo();
345+
};
346+
320347
var initTriggers = function() {
321348
organization.change(updateInfo);
322349
organization.change(checkOtherSDO);
323-
from.change(updateInfo);
350+
from.change(checkFrom);
324351
reply.keyup(updateFrom);
325352
purpose.change(updatePurpose);
326353
cancel.click(cancelForm);
@@ -330,7 +357,7 @@
330357

331358
var updateOnInit = function() {
332359
updateFrom();
333-
updateInfo();
360+
checkFrom();
334361
updatePurpose();
335362
checkOtherSDO();
336363
};

0 commit comments

Comments
 (0)