Check if the user needs to approval to send a liaison on behalf of an entity.
Ajax queries merged into one. See #353 - Legacy-Id: 2445
This commit is contained in:
parent
84f30b6af9
commit
1a2f1559c4
|
@ -23,6 +23,5 @@ urlpatterns += patterns('django.views.generic.simple',
|
|||
|
||||
urlpatterns += patterns('ietf.liaisons.views',
|
||||
url(r'^add/$', 'add_liaison', name='add_liaison'),
|
||||
url(r'^ajax/get_poc_for_incoming/$', 'get_poc_for_incoming', name='get_poc_for_incoming'),
|
||||
url(r'^ajax/get_cc_for_incoming/$', 'get_cc_for_incoming', name='get_cc_for_incoming'),
|
||||
url(r'^ajax/get_info/$', 'get_info', name='get_info'),
|
||||
)
|
||||
|
|
|
@ -41,6 +41,9 @@ class Entity(object):
|
|||
def get_from_cc(self, person=None):
|
||||
return []
|
||||
|
||||
def needs_approval(self, person=None):
|
||||
return False
|
||||
|
||||
|
||||
class IETFEntity(Entity):
|
||||
|
||||
|
@ -54,6 +57,11 @@ class IETFEntity(Entity):
|
|||
result.append(self.cc)
|
||||
return result
|
||||
|
||||
def needs_approval(self, person=None):
|
||||
if is_ietfchair(person):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class IABEntity(Entity):
|
||||
chair = FakePerson(**IABCHAIR)
|
||||
|
@ -70,6 +78,11 @@ class IABEntity(Entity):
|
|||
result.append(self.director)
|
||||
return result
|
||||
|
||||
def needs_approval(self, person=None):
|
||||
if is_iabchair(person) or is_iab_executive_director(person):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class AreaEntity(Entity):
|
||||
|
||||
|
@ -84,6 +97,12 @@ class AreaEntity(Entity):
|
|||
result.append(FakePerson(**IETFCHAIR))
|
||||
return result
|
||||
|
||||
def needs_approval(self, person=None):
|
||||
# Check if person is an area director
|
||||
if self.obj.areadirector_set.filter(person=person):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class WGEntity(Entity):
|
||||
|
||||
|
@ -105,6 +124,12 @@ class WGEntity(Entity):
|
|||
address = self.obj.email_address))
|
||||
return result
|
||||
|
||||
def needs_approval(self, person=None):
|
||||
# Check if person is director of this wg area
|
||||
if self.obj.area.area.areadirector_set.filter(person=person):
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
class SDOEntity(Entity):
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from ietf.liaisons.utils import IETFHM
|
|||
@can_submit_liaison
|
||||
def add_liaison(request):
|
||||
if request.method == 'POST':
|
||||
form = liaison_form_factory(request, data=request.POST.copy(),
|
||||
form = liaison_form_factory(request, data=request.POST.copy(),
|
||||
files = request.FILES)
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
|
@ -30,36 +30,33 @@ def add_liaison(request):
|
|||
)
|
||||
|
||||
|
||||
@can_submit_liaison
|
||||
def get_poc_for_incoming(request):
|
||||
entity_id = request.GET.get('entity_id', None)
|
||||
if not entity_id:
|
||||
result = {'poc': None, 'error': 'No entity id'}
|
||||
else:
|
||||
entity = IETFHM.get_entity_by_key(entity_id)
|
||||
if not entity:
|
||||
result = {'poc': None, 'error': 'Invalid entity id'}
|
||||
else:
|
||||
result = {'error': False, 'poc': [i.email() for i in entity.get_poc()]}
|
||||
json_result = simplejson.dumps(result)
|
||||
return HttpResponse(json_result, mimetype='text/javascript')
|
||||
|
||||
|
||||
@can_submit_liaison
|
||||
def get_cc_for_incoming(request):
|
||||
entity_id = request.GET.get('to_entity_id', None)
|
||||
from_entity_id = request.GET.get('from_entity_id', None)
|
||||
if not entity_id and not from_entity_id:
|
||||
result = {'cc': [], 'error': 'No entity id and no sdo id'}
|
||||
def get_info(request):
|
||||
person = get_person_for_user(request.user)
|
||||
if entity_id:
|
||||
entity = IETFHM.get_entity_by_key(entity_id)
|
||||
if not entity:
|
||||
result = {'cc': [], 'error': 'Invalid entity id'}
|
||||
else:
|
||||
result = {'error': False, 'cc': [i.email() for i in entity.get_cc()]}
|
||||
|
||||
to_entity_id = request.GET.get('to_entity_id', None)
|
||||
from_entity_id = request.GET.get('from_entity_id', None)
|
||||
|
||||
result = {'poc': [], 'cc': [], 'needs_approval': False}
|
||||
|
||||
to_error = 'Invalid TO entity id'
|
||||
if to_entity_id:
|
||||
to_entity = IETFHM.get_entity_by_key(to_entity_id)
|
||||
if to_entity:
|
||||
to_error = ''
|
||||
|
||||
from_error = 'Invalid FROM entity id'
|
||||
if from_entity_id:
|
||||
from_entity = IETFHM.get_entity_by_key(from_entity_id)
|
||||
result['cc'] += [i.email() for i in from_entity.get_from_cc(person=person)]
|
||||
if from_entity:
|
||||
from_error = ''
|
||||
|
||||
if to_error or from_error:
|
||||
result.update({'error': '\n'.join([to_error, from_error])})
|
||||
else:
|
||||
result.update({'error': False,
|
||||
'cc': [i.email() for i in to_entity.get_cc(person=person)] +\
|
||||
[i.email() for i in from_entity.get_from_cc(person=person)],
|
||||
'poc': [i.email() for i in to_entity.get_poc()],
|
||||
'needs_approval': from_entity.needs_approval(person=person)})
|
||||
json_result = simplejson.dumps(result)
|
||||
return HttpResponse(json_result, mimetype='text/javascript')
|
||||
|
|
|
@ -7,11 +7,16 @@ class FromWidget(Select):
|
|||
def render(self, name, value, attrs=None, choices=()):
|
||||
all_choices = list(self.choices) + list(choices)
|
||||
if len(all_choices)!=1 or \
|
||||
(isinstance(all_choices[0], (list, tuple)) and \
|
||||
(isinstance(all_choices[0][1], (list, tuple)) and \
|
||||
len(all_choices[0][1])!=1):
|
||||
base = super(FromWidget, self).render(name, value, attrs, choices)
|
||||
else:
|
||||
base = u'<input type="hidden" value="%s" />%s' % all_choices[0]
|
||||
option = all_choices[0]
|
||||
if isinstance(option[1], (list, tuple)):
|
||||
option = option[1][0]
|
||||
value = option[0]
|
||||
text = option[1]
|
||||
base = u'<input type="hidden" value="%s" id="id_%s" name="%s" />%s' % (value, name, name, text)
|
||||
base += u' (<a class="from_mailto" href="">' + self.submitter + u'</a>)'
|
||||
return mark_safe(base)
|
||||
|
||||
|
|
|
@ -4,8 +4,7 @@
|
|||
|
||||
<div class="formconfig" style="display: none;">
|
||||
{% block formconfig %}
|
||||
<span class="poc_update_url">{% url get_poc_for_incoming %}</span>
|
||||
<span class="cc_update_url">{% url get_cc_for_incoming %}</span>
|
||||
<span class="info_update_url">{% url get_info %}</span>
|
||||
{% endblock %}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -120,12 +120,12 @@
|
|||
var other_purpose = form.find('#id_purpose_text');
|
||||
var deadline = form.find('#id_deadline_date');
|
||||
var other_organization = form.find('#id_other_organization');
|
||||
var approval = form.find('#id_approval');
|
||||
var config = {};
|
||||
|
||||
var readConfig = function() {
|
||||
var confcontainer = form.find('.formconfig');
|
||||
config.poc_update_url = confcontainer.find('.poc_update_url').text();
|
||||
config.cc_update_url = confcontainer.find('.cc_update_url').text();
|
||||
config.info_update_url = confcontainer.find('.info_update_url').text();
|
||||
};
|
||||
|
||||
var render_mails_into = function(container, person_list) {
|
||||
|
@ -137,29 +137,23 @@
|
|||
container.html(html);
|
||||
};
|
||||
|
||||
var updatePOC = function() {
|
||||
var entity = organization.find('option:selected');
|
||||
var url = config.poc_update_url;
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'GET',
|
||||
cache: false,
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data: {entity_id: entity.val()},
|
||||
success: function(response){
|
||||
if (!response.error) {
|
||||
render_mails_into(poc, response.poc);
|
||||
}
|
||||
}
|
||||
});
|
||||
return false;
|
||||
var toggleApproval = function(needed) {
|
||||
if (!approval.length) {
|
||||
return;
|
||||
}
|
||||
if (needed) {
|
||||
approval.removeAttr('disabled');
|
||||
approval.removeAttr('checked');
|
||||
} else {
|
||||
approval.attr('checked','checked');
|
||||
approval.attr('disabled','disabled');
|
||||
}
|
||||
};
|
||||
|
||||
var updateCC = function() {
|
||||
var entity = organization.find('option:selected');
|
||||
var sdo = from.find('option:selected');
|
||||
var url = config.cc_update_url;
|
||||
var updateInfo = function() {
|
||||
var entity = organization;
|
||||
var to_entity = from;
|
||||
var url = config.info_update_url;
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'GET',
|
||||
|
@ -167,10 +161,12 @@
|
|||
async: true,
|
||||
dataType: 'json',
|
||||
data: {to_entity_id: organization.val(),
|
||||
from_entity_id: sdo.val()},
|
||||
from_entity_id: to_entity.val()},
|
||||
success: function(response){
|
||||
if (!response.error) {
|
||||
render_mails_into(cc, response.cc);
|
||||
render_mails_into(poc, response.poc);
|
||||
toggleApproval(response.needs_approval);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -185,7 +181,7 @@
|
|||
var updatePurpose = function() {
|
||||
var datecontainer = deadline.parents('.field');
|
||||
var othercontainer = other_purpose.parents('.field');
|
||||
var selected_id = purpose.find('option:selected').val();
|
||||
var selected_id = purpose.val();
|
||||
var deadline_required = datecontainer.find('.fieldRequired');
|
||||
|
||||
if (selected_id == '1' || selected_id == '2' || selected_id == '5') {
|
||||
|
@ -206,7 +202,7 @@
|
|||
};
|
||||
|
||||
var checkOtherSDO = function() {
|
||||
var entity = organization.find('option:selected').val();
|
||||
var entity = organization.val();
|
||||
if (entity=='othersdo') {
|
||||
other_organization.parents('.field').show();
|
||||
} else {
|
||||
|
@ -215,18 +211,17 @@
|
|||
};
|
||||
|
||||
var initTriggers = function() {
|
||||
organization.change(updatePOC);
|
||||
organization.change(updateCC);
|
||||
organization.change(updateInfo);
|
||||
organization.change(updateInfo);
|
||||
organization.change(checkOtherSDO);
|
||||
from.change(updateCC);
|
||||
from.change(updateInfo);
|
||||
reply.keyup(updateFrom);
|
||||
purpose.change(updatePurpose);
|
||||
};
|
||||
|
||||
var updateOnInit = function() {
|
||||
updateFrom();
|
||||
updateCC();
|
||||
updatePOC();
|
||||
updateInfo();
|
||||
updatePurpose();
|
||||
checkOtherSDO();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue