manager: use selected ou by default in import roles form (#46642)
This commit is contained in:
parent
9cb195bd11
commit
3ba066a70a
|
@ -520,6 +520,13 @@ class RolesImportView(views.PermissionMixin, views.TitleMixin, views.MediaMixin,
|
||||||
template_name = 'authentic2/manager/import_form.html'
|
template_name = 'authentic2/manager/import_form.html'
|
||||||
title = _('Roles Import')
|
title = _('Roles Import')
|
||||||
|
|
||||||
|
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 post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
if not self.can_add:
|
if not self.can_add:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<ul class="extra-actions-menu">
|
<ul class="extra-actions-menu">
|
||||||
<li><a download href="{% url 'a2-manager-roles-export' format="json" %}?{{ request.GET.urlencode }}">{% trans 'Export' %}</a></li>
|
<li><a download href="{% url 'a2-manager-roles-export' format="json" %}?{{ request.GET.urlencode }}">{% trans 'Export' %}</a></li>
|
||||||
{% if view.can_add %}
|
{% if view.can_add %}
|
||||||
<li><a href="{% url 'a2-manager-roles-import' %}" rel="popup">{% trans 'Import' %}</a></li>
|
<li><a href="{% url 'a2-manager-roles-import' %}?{{ request.GET.urlencode }}" rel="popup">{% trans 'Import' %}</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -161,6 +161,7 @@ def test_manager_role_import(app, admin, ou1, role_ou1, ou2, role_ou2):
|
||||||
"slug": "should_not_exist",
|
"slug": "should_not_exist",
|
||||||
"name": "should_not_exist",
|
"name": "should_not_exist",
|
||||||
}]
|
}]
|
||||||
|
resp = app.get('/manage/roles/') # unselect ou1
|
||||||
resp = resp.click('Import')
|
resp = resp.click('Import')
|
||||||
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json')
|
||||||
resp = resp.form.submit().follow()
|
resp = resp.form.submit().follow()
|
||||||
|
@ -188,3 +189,11 @@ def test_manager_role_import_single_ou(app, admin, simple_role):
|
||||||
|
|
||||||
imported_role = Role.objects.get(slug=simple_role.slug)
|
imported_role = Role.objects.get(slug=simple_role.slug)
|
||||||
assert imported_role.ou == simple_role.ou
|
assert imported_role.ou == simple_role.ou
|
||||||
|
|
||||||
|
|
||||||
|
def test_manager_role_import_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('Import')
|
||||||
|
assert response.pyquery.find('select#id_ou option[selected]')[0].text == 'OU2'
|
||||||
|
|
Loading…
Reference in New Issue