0001-manager-use-selected-ou-by-default-in-import-roles-f.patch
src/authentic2/manager/role_views.py | ||
---|---|---|
515 | 515 | |
516 | 516 |
class RolesImportView(views.PermissionMixin, views.TitleMixin, views.MediaMixin, views.FormNeedsRequest, |
517 | 517 |
FormView): |
518 | 518 |
form_class = forms.RolesImportForm |
519 | 519 |
model = get_role_model() |
520 | 520 |
template_name = 'authentic2/manager/import_form.html' |
521 | 521 |
title = _('Roles Import') |
522 | 522 | |
523 |
def get_initial(self): |
|
524 |
result = super().get_initial() |
|
525 |
selected_ou = self.request.GET.get('search-ou') |
|
526 |
if selected_ou: |
|
527 |
result.update({'ou': selected_ou}) |
|
528 |
return result |
|
529 | ||
523 | 530 |
def post(self, request, *args, **kwargs): |
524 | 531 |
if not self.can_add: |
525 | 532 |
raise PermissionDenied |
526 | 533 |
return super().post(request, *args, **kwargs) |
527 | 534 | |
528 | 535 |
def form_valid(self, form): |
529 | 536 |
self.ou = form.cleaned_data['ou'] |
530 | 537 |
try: |
src/authentic2/manager/templates/authentic2/manager/roles.html | ||
---|---|---|
10 | 10 |
{% if view.can_add %} |
11 | 11 |
<a href="{% url "a2-manager-role-add" %}" rel="popup">{% trans "Add role" %}</a> |
12 | 12 |
{% else %} |
13 | 13 |
<a href="#" class="disabled" rel="popup">{% trans "Add role" %}</a> |
14 | 14 |
{% endif %} |
15 | 15 |
<ul class="extra-actions-menu"> |
16 | 16 |
<li><a download href="{% url 'a2-manager-roles-export' format="json" %}?{{ request.GET.urlencode }}">{% trans 'Export' %}</a></li> |
17 | 17 |
{% if view.can_add %} |
18 |
<li><a href="{% url 'a2-manager-roles-import' %}" rel="popup">{% trans 'Import' %}</a></li> |
|
18 |
<li><a href="{% url 'a2-manager-roles-import' %}?{{ request.GET.urlencode }}" rel="popup">{% trans 'Import' %}</a></li>
|
|
19 | 19 |
{% endif %} |
20 | 20 |
</ul> |
21 | 21 |
</span> |
22 | 22 |
{% endblock %} |
23 | 23 | |
24 | 24 |
{% block sidebar %} |
25 | 25 |
<aside id="sidebar"> |
26 | 26 |
{% include "authentic2/manager/search_form.html" %} |
tests/test_role_manager.py | ||
---|---|---|
156 | 156 |
assert Role.objects.filter(ou=ou1).count() == 4 |
157 | 157 | |
158 | 158 |
# in case ous are present in export file, they must not be imported |
159 | 159 |
export['ous'] = [{ |
160 | 160 |
"uuid": "27255f404cb140df9a577da76b59f285", |
161 | 161 |
"slug": "should_not_exist", |
162 | 162 |
"name": "should_not_exist", |
163 | 163 |
}] |
164 |
resp = app.get('/manage/roles/') # unselect ou1 |
|
164 | 165 |
resp = resp.click('Import') |
165 | 166 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json') |
166 | 167 |
resp = resp.form.submit().follow() |
167 | 168 | |
168 | 169 |
assert not OrganizationalUnit.objects.filter(slug="should_not_exist").exists() |
169 | 170 | |
170 | 171 | |
171 | 172 |
def test_manager_role_import_single_ou(app, admin, simple_role): |
... | ... | |
183 | 184 |
assert not 'Organizational unit' in resp.text |
184 | 185 |
assert resp.form['ou'].attrs['type'] == 'hidden' |
185 | 186 | |
186 | 187 |
resp.form['site_json'] = Upload('export.json', json.dumps(export).encode(), 'application/json') |
187 | 188 |
resp = resp.form.submit().follow() |
188 | 189 | |
189 | 190 |
imported_role = Role.objects.get(slug=simple_role.slug) |
190 | 191 |
assert imported_role.ou == simple_role.ou |
192 | ||
193 | ||
194 |
def test_manager_role_import_selected_ou(app, admin, ou1, ou2): |
|
195 |
response = login(app, admin, 'a2-manager-roles') |
|
196 |
response.form.set('search-ou', ou2.pk) |
|
197 |
response = response.form.submit() |
|
198 |
response = response.click('Import') |
|
199 |
assert response.pyquery.find('select#id_ou option[selected]')[0].text == 'OU2' |
|
191 |
- |