Skip to content

Commit 1a2f155

Browse files
committed
Check if the user needs to approval to send a liaison on behalf of an entity.
Ajax queries merged into one. See ietf-tools#353 - Legacy-Id: 2445
1 parent 84f30b6 commit 1a2f155

6 files changed

Lines changed: 85 additions & 65 deletions

File tree

ietf/liaisons/urls.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,5 @@
2323

2424
urlpatterns += patterns('ietf.liaisons.views',
2525
url(r'^add/$', 'add_liaison', name='add_liaison'),
26-
url(r'^ajax/get_poc_for_incoming/$', 'get_poc_for_incoming', name='get_poc_for_incoming'),
27-
url(r'^ajax/get_cc_for_incoming/$', 'get_cc_for_incoming', name='get_cc_for_incoming'),
26+
url(r'^ajax/get_info/$', 'get_info', name='get_info'),
2827
)

ietf/liaisons/utils.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ def get_cc(self, person=None):
4141
def get_from_cc(self, person=None):
4242
return []
4343

44+
def needs_approval(self, person=None):
45+
return False
46+
4447

4548
class IETFEntity(Entity):
4649

@@ -54,6 +57,11 @@ def get_from_cc(self, person):
5457
result.append(self.cc)
5558
return result
5659

60+
def needs_approval(self, person=None):
61+
if is_ietfchair(person):
62+
return False
63+
return True
64+
5765

5866
class IABEntity(Entity):
5967
chair = FakePerson(**IABCHAIR)
@@ -70,6 +78,11 @@ def get_from_cc(self, person):
7078
result.append(self.director)
7179
return result
7280

81+
def needs_approval(self, person=None):
82+
if is_iabchair(person) or is_iab_executive_director(person):
83+
return False
84+
return True
85+
7386

7487
class AreaEntity(Entity):
7588

@@ -84,6 +97,12 @@ def get_from_cc(self, person):
8497
result.append(FakePerson(**IETFCHAIR))
8598
return result
8699

100+
def needs_approval(self, person=None):
101+
# Check if person is an area director
102+
if self.obj.areadirector_set.filter(person=person):
103+
return False
104+
return True
105+
87106

88107
class WGEntity(Entity):
89108

@@ -105,6 +124,12 @@ def get_from_cc(self, person):
105124
address = self.obj.email_address))
106125
return result
107126

127+
def needs_approval(self, person=None):
128+
# Check if person is director of this wg area
129+
if self.obj.area.area.areadirector_set.filter(person=person):
130+
return False
131+
return True
132+
108133

109134
class SDOEntity(Entity):
110135

ietf/liaisons/views.py

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@can_submit_liaison
1616
def add_liaison(request):
1717
if request.method == 'POST':
18-
form = liaison_form_factory(request, data=request.POST.copy(),
18+
form = liaison_form_factory(request, data=request.POST.copy(),
1919
files = request.FILES)
2020
if form.is_valid():
2121
form.save()
@@ -30,36 +30,33 @@ def add_liaison(request):
3030
)
3131

3232

33-
@can_submit_liaison
34-
def get_poc_for_incoming(request):
35-
entity_id = request.GET.get('entity_id', None)
36-
if not entity_id:
37-
result = {'poc': None, 'error': 'No entity id'}
38-
else:
39-
entity = IETFHM.get_entity_by_key(entity_id)
40-
if not entity:
41-
result = {'poc': None, 'error': 'Invalid entity id'}
42-
else:
43-
result = {'error': False, 'poc': [i.email() for i in entity.get_poc()]}
44-
json_result = simplejson.dumps(result)
45-
return HttpResponse(json_result, mimetype='text/javascript')
46-
33+
def get_info(request):
34+
person = get_person_for_user(request.user)
4735

48-
@can_submit_liaison
49-
def get_cc_for_incoming(request):
50-
entity_id = request.GET.get('to_entity_id', None)
36+
to_entity_id = request.GET.get('to_entity_id', None)
5137
from_entity_id = request.GET.get('from_entity_id', None)
52-
if not entity_id and not from_entity_id:
53-
result = {'cc': [], 'error': 'No entity id and no sdo id'}
54-
person = get_person_for_user(request.user)
55-
if entity_id:
56-
entity = IETFHM.get_entity_by_key(entity_id)
57-
if not entity:
58-
result = {'cc': [], 'error': 'Invalid entity id'}
59-
else:
60-
result = {'error': False, 'cc': [i.email() for i in entity.get_cc()]}
38+
39+
result = {'poc': [], 'cc': [], 'needs_approval': False}
40+
41+
to_error = 'Invalid TO entity id'
42+
if to_entity_id:
43+
to_entity = IETFHM.get_entity_by_key(to_entity_id)
44+
if to_entity:
45+
to_error = ''
46+
47+
from_error = 'Invalid FROM entity id'
6148
if from_entity_id:
6249
from_entity = IETFHM.get_entity_by_key(from_entity_id)
63-
result['cc'] += [i.email() for i in from_entity.get_from_cc(person=person)]
50+
if from_entity:
51+
from_error = ''
52+
53+
if to_error or from_error:
54+
result.update({'error': '\n'.join([to_error, from_error])})
55+
else:
56+
result.update({'error': False,
57+
'cc': [i.email() for i in to_entity.get_cc(person=person)] +\
58+
[i.email() for i in from_entity.get_from_cc(person=person)],
59+
'poc': [i.email() for i in to_entity.get_poc()],
60+
'needs_approval': from_entity.needs_approval(person=person)})
6461
json_result = simplejson.dumps(result)
6562
return HttpResponse(json_result, mimetype='text/javascript')

ietf/liaisons/widgets.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ class FromWidget(Select):
77
def render(self, name, value, attrs=None, choices=()):
88
all_choices = list(self.choices) + list(choices)
99
if len(all_choices)!=1 or \
10-
(isinstance(all_choices[0], (list, tuple)) and \
10+
(isinstance(all_choices[0][1], (list, tuple)) and \
1111
len(all_choices[0][1])!=1):
1212
base = super(FromWidget, self).render(name, value, attrs, choices)
1313
else:
14-
base = u'<input type="hidden" value="%s" />%s' % all_choices[0]
14+
option = all_choices[0]
15+
if isinstance(option[1], (list, tuple)):
16+
option = option[1][0]
17+
value = option[0]
18+
text = option[1]
19+
base = u'<input type="hidden" value="%s" id="id_%s" name="%s" />%s' % (value, name, name, text)
1520
base += u' (<a class="from_mailto" href="">' + self.submitter + u'</a>)'
1621
return mark_safe(base)
1722

ietf/templates/liaisons/liaisonform.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
<div class="formconfig" style="display: none;">
66
{% block formconfig %}
7-
<span class="poc_update_url">{% url get_poc_for_incoming %}</span>
8-
<span class="cc_update_url">{% url get_cc_for_incoming %}</span>
7+
<span class="info_update_url">{% url get_info %}</span>
98
{% endblock %}
109
</div>
1110

static/js/liaisons.js

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,12 @@
120120
var other_purpose = form.find('#id_purpose_text');
121121
var deadline = form.find('#id_deadline_date');
122122
var other_organization = form.find('#id_other_organization');
123+
var approval = form.find('#id_approval');
123124
var config = {};
124125

125126
var readConfig = function() {
126127
var confcontainer = form.find('.formconfig');
127-
config.poc_update_url = confcontainer.find('.poc_update_url').text();
128-
config.cc_update_url = confcontainer.find('.cc_update_url').text();
128+
config.info_update_url = confcontainer.find('.info_update_url').text();
129129
};
130130

131131
var render_mails_into = function(container, person_list) {
@@ -137,40 +137,36 @@
137137
container.html(html);
138138
};
139139

140-
var updatePOC = function() {
141-
var entity = organization.find('option:selected');
142-
var url = config.poc_update_url;
143-
$.ajax({
144-
url: url,
145-
type: 'GET',
146-
cache: false,
147-
async: true,
148-
dataType: 'json',
149-
data: {entity_id: entity.val()},
150-
success: function(response){
151-
if (!response.error) {
152-
render_mails_into(poc, response.poc);
153-
}
154-
}
155-
});
156-
return false;
140+
var toggleApproval = function(needed) {
141+
if (!approval.length) {
142+
return;
143+
}
144+
if (needed) {
145+
approval.removeAttr('disabled');
146+
approval.removeAttr('checked');
147+
} else {
148+
approval.attr('checked','checked');
149+
approval.attr('disabled','disabled');
150+
}
157151
};
158152

159-
var updateCC = function() {
160-
var entity = organization.find('option:selected');
161-
var sdo = from.find('option:selected');
162-
var url = config.cc_update_url;
153+
var updateInfo = function() {
154+
var entity = organization;
155+
var to_entity = from;
156+
var url = config.info_update_url;
163157
$.ajax({
164158
url: url,
165159
type: 'GET',
166160
cache: false,
167161
async: true,
168162
dataType: 'json',
169163
data: {to_entity_id: organization.val(),
170-
from_entity_id: sdo.val()},
164+
from_entity_id: to_entity.val()},
171165
success: function(response){
172166
if (!response.error) {
173167
render_mails_into(cc, response.cc);
168+
render_mails_into(poc, response.poc);
169+
toggleApproval(response.needs_approval);
174170
}
175171
}
176172
});
@@ -185,7 +181,7 @@
185181
var updatePurpose = function() {
186182
var datecontainer = deadline.parents('.field');
187183
var othercontainer = other_purpose.parents('.field');
188-
var selected_id = purpose.find('option:selected').val();
184+
var selected_id = purpose.val();
189185
var deadline_required = datecontainer.find('.fieldRequired');
190186

191187
if (selected_id == '1' || selected_id == '2' || selected_id == '5') {
@@ -206,7 +202,7 @@
206202
};
207203

208204
var checkOtherSDO = function() {
209-
var entity = organization.find('option:selected').val();
205+
var entity = organization.val();
210206
if (entity=='othersdo') {
211207
other_organization.parents('.field').show();
212208
} else {
@@ -215,18 +211,17 @@
215211
};
216212

217213
var initTriggers = function() {
218-
organization.change(updatePOC);
219-
organization.change(updateCC);
214+
organization.change(updateInfo);
215+
organization.change(updateInfo);
220216
organization.change(checkOtherSDO);
221-
from.change(updateCC);
217+
from.change(updateInfo);
222218
reply.keyup(updateFrom);
223219
purpose.change(updatePurpose);
224220
};
225221

226222
var updateOnInit = function() {
227223
updateFrom();
228-
updateCC();
229-
updatePOC();
224+
updateInfo();
230225
updatePurpose();
231226
checkOtherSDO();
232227
};

0 commit comments

Comments
 (0)