Allow the secretariat to send liaisons on behalf of another user. Fixes #578
- Legacy-Id: 2787
This commit is contained in:
parent
53fae6e4c5
commit
5684bc324d
|
@ -8,6 +8,7 @@ from django.forms.util import ErrorList
|
|||
from django.forms.fields import email_re
|
||||
from django.template.loader import render_to_string
|
||||
|
||||
from ietf.idtracker.models import PersonOrOrgInfo
|
||||
from ietf.liaisons.accounts import (can_add_outgoing_liaison, can_add_incoming_liaison,
|
||||
get_person_for_user, is_secretariat, is_sdo_liaison_manager)
|
||||
from ietf.liaisons.models import LiaisonDetail, Uploads, OutgoingLiaisonApproval, SDOs
|
||||
|
@ -61,6 +62,9 @@ class LiaisonForm(forms.ModelForm):
|
|||
self.person = get_person_for_user(user)
|
||||
if kwargs.get('data', None):
|
||||
kwargs['data'].update({'person': self.person.pk})
|
||||
if is_secretariat(self.user) and 'from_fake_user' in kwargs['data'].keys():
|
||||
fake_person = PersonOrOrgInfo.objects.get(pk=kwargs['data']['from_fake_user'])
|
||||
kwargs['data'].update({'person': fake_person.pk})
|
||||
super(LiaisonForm, self).__init__(*args, **kwargs)
|
||||
self.hm = IETFHM
|
||||
self.set_from_field()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from ietf.idtracker.models import Area, IETFWG
|
||||
from ietf.liaisons.models import SDOs
|
||||
from ietf.liaisons.accounts import is_ietfchair, is_iabchair, is_iab_executive_director
|
||||
from ietf.liaisons.models import SDOs, LiaisonManagers
|
||||
from ietf.liaisons.accounts import (is_ietfchair, is_iabchair, is_iab_executive_director,
|
||||
get_ietf_chair, get_iab_chair, get_iab_executive_director)
|
||||
|
||||
IETFCHAIR = {'name': u'The IETF Chair', 'address': u'chair@ietf.org'}
|
||||
IESG = {'name': u'The IESG', 'address': u'iesg@ietf.org'}
|
||||
|
@ -9,6 +10,10 @@ IABCHAIR = {'name': u'The IAB Chair', 'address': u'iab-chair@iab.org'}
|
|||
IABEXECUTIVEDIRECTOR = {'name': u'The IAB Executive Director', 'address': u'execd@iab.org'}
|
||||
|
||||
|
||||
def get_all_sdo_managers():
|
||||
return [i.person for i in LiaisonManagers.objects.all().distinct()]
|
||||
|
||||
|
||||
class FakePerson(object):
|
||||
|
||||
def __init__(self, name, address):
|
||||
|
@ -50,6 +55,9 @@ class Entity(object):
|
|||
def post_only(self, person):
|
||||
return False
|
||||
|
||||
def full_user_list(self):
|
||||
return False
|
||||
|
||||
|
||||
class IETFEntity(Entity):
|
||||
|
||||
|
@ -71,6 +79,11 @@ class IETFEntity(Entity):
|
|||
def can_approve(self):
|
||||
return [self.poc]
|
||||
|
||||
def full_user_list(self):
|
||||
result = get_all_sdo_managers()
|
||||
result.append(get_ietf_chair())
|
||||
return result
|
||||
|
||||
|
||||
class IABEntity(Entity):
|
||||
chair = FakePerson(**IABCHAIR)
|
||||
|
@ -95,6 +108,11 @@ class IABEntity(Entity):
|
|||
def can_approve(self):
|
||||
return [self.chair]
|
||||
|
||||
def full_user_list(self):
|
||||
result = get_all_sdo_managers()
|
||||
result += [get_iab_chair(), get_iab_executive_director()]
|
||||
return result
|
||||
|
||||
|
||||
class AreaEntity(Entity):
|
||||
|
||||
|
@ -118,6 +136,11 @@ class AreaEntity(Entity):
|
|||
def can_approve(self):
|
||||
return self.get_poc()
|
||||
|
||||
def full_user_list(self):
|
||||
result = get_all_sdo_managers()
|
||||
result += self.get_poc()
|
||||
return result
|
||||
|
||||
|
||||
class WGEntity(Entity):
|
||||
|
||||
|
@ -148,6 +171,11 @@ class WGEntity(Entity):
|
|||
def can_approve(self):
|
||||
return [i.person for i in self.obj.area.area.areadirector_set.all()]
|
||||
|
||||
def full_user_list(self):
|
||||
result = get_all_sdo_managers()
|
||||
result += self.get_poc()
|
||||
return result
|
||||
|
||||
|
||||
class SDOEntity(Entity):
|
||||
|
||||
|
@ -169,6 +197,11 @@ class SDOEntity(Entity):
|
|||
def post_only(self, person):
|
||||
return bool(self.obj.liaisonmanagers_set.filter(person=person))
|
||||
|
||||
def full_user_list(self):
|
||||
result = [i.person for i in self.obj.liaisonmanagers_set.all().distinct()]
|
||||
result += [i.person for i in self.obj.sdoauthorizedindividual_set.all().distinct()]
|
||||
return result
|
||||
|
||||
|
||||
class EntityManager(object):
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.views.generic.list_detail import object_list, object_detail
|
|||
from ietf.liaisons.accounts import (get_person_for_user, can_add_outgoing_liaison,
|
||||
can_add_incoming_liaison, LIAISON_EDIT_GROUPS,
|
||||
is_ietfchair, is_iabchair, is_iab_executive_director,
|
||||
can_edit_liaison)
|
||||
can_edit_liaison, is_secretariat)
|
||||
from ietf.liaisons.decorators import can_submit_liaison
|
||||
from ietf.liaisons.forms import liaison_form_factory
|
||||
from ietf.liaisons.models import LiaisonDetail, OutgoingLiaisonApproval
|
||||
|
@ -53,7 +53,7 @@ def get_info(request):
|
|||
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, 'post_only': False}
|
||||
result = {'poc': [], 'cc': [], 'needs_approval': False, 'post_only': False, 'full_list': []}
|
||||
|
||||
to_error = 'Invalid TO entity id'
|
||||
if to_entity_id:
|
||||
|
@ -76,6 +76,11 @@ def get_info(request):
|
|||
'poc': [i.email() for i in to_entity.get_poc()],
|
||||
'needs_approval': from_entity.needs_approval(person=person),
|
||||
'post_only': from_entity.post_only(person=person)})
|
||||
if is_secretariat(request.user):
|
||||
full_list = [(i.pk, i.email()) for i in from_entity.full_user_list()]
|
||||
full_list.sort(lambda x,y: cmp(x[1], y[1]))
|
||||
full_list = [(person.pk, person.email())] + full_list
|
||||
result.update({'full_list': full_list})
|
||||
json_result = simplejson.dumps(result)
|
||||
return HttpResponse(json_result, mimetype='text/javascript')
|
||||
|
||||
|
|
|
@ -180,6 +180,30 @@
|
|||
}
|
||||
};
|
||||
|
||||
var updateReplyTo = function() {
|
||||
var select = form.find('select[name=from_fake_user]');
|
||||
var option = select.find('option:selected');
|
||||
reply.val(option.attr('title'));
|
||||
updateFrom();
|
||||
}
|
||||
|
||||
var userSelect = function(user_list) {
|
||||
if (!user_list) {
|
||||
return;
|
||||
}
|
||||
var link = form.find('a.from_mailto');
|
||||
var select = form.find('select[name=from_fake_user]');
|
||||
var options = '';
|
||||
link.hide();
|
||||
$.each(user_list, function(index, person) {
|
||||
options += '<option value="' + person[0] + '" title="' + person[1][1] + '">'+ person[1][0] + ' <' + person[1][1] + '></option>';
|
||||
});
|
||||
select.remove();
|
||||
link.after('<select name="from_fake_user">' + options +'</select>')
|
||||
form.find('select[name=from_fake_user]').change(updateReplyTo);
|
||||
updateReplyTo();
|
||||
};
|
||||
|
||||
var updateInfo = function() {
|
||||
var entity = organization;
|
||||
var to_entity = from;
|
||||
|
@ -198,6 +222,7 @@
|
|||
render_mails_into(poc, response.poc);
|
||||
toggleApproval(response.needs_approval);
|
||||
checkPostOnly(response.post_only);
|
||||
userSelect(response.full_list);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue