manager: use selected ou by default in add roles form (#46643)

This commit is contained in:
Nicolas Roche 2020-10-14 14:24:52 +02:00
parent 8ae42a05d8
commit 8899d25376
3 changed files with 16 additions and 1 deletions

View File

@ -89,6 +89,13 @@ class RoleAddView(views.BaseAddView):
success_view_name = 'a2-manager-role-members'
exclude_fields = ('slug',)
def get_initial(self):
initial = super().get_initial()
search_ou = self.request.GET.get('search-ou')
if search_ou:
initial['ou'] = search_ou
return initial
def get_form_class(self):
form = forms.get_role_form_class()
fields = [x for x in form.base_fields.keys() if x not in self.exclude_fields]

View File

@ -8,7 +8,7 @@
<span class="actions">
<a class="extra-actions-menu-opener"></a>
{% if view.can_add %}
<a href="{% url "a2-manager-role-add" %}" rel="popup">{% trans "Add role" %}</a>
<a href="{% url 'a2-manager-role-add' %}?{{ request.GET.urlencode }}" rel="popup">{% trans "Add role" %}</a>
{% else %}
<a href="#" class="disabled" rel="popup">{% trans "Add role" %}</a>
{% endif %}

View File

@ -197,3 +197,11 @@ def test_manager_role_import_selected_ou(app, admin, ou1, ou2):
response = response.form.submit()
response = response.click('Import')
assert response.pyquery.find('select#id_ou option[selected]')[0].text == 'OU2'
def test_manager_role_add_selected_ou(app, admin, ou1, ou2):
response = login(app, admin, 'a2-manager-roles')
response.form.set('search-ou', ou2.pk)
response = response.form.submit()
response = response.click('Add role')
assert response.pyquery.find('select#id_ou option[selected]')[0].text == 'OU2'