manager: add ous export (#29162)
This commit is contained in:
parent
6f2b7f63bc
commit
8efca74775
|
@ -1,8 +1,12 @@
|
||||||
|
import json
|
||||||
|
|
||||||
from django_rbac.utils import get_ou_model
|
from django_rbac.utils import get_ou_model
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
|
from authentic2 import data_transfer
|
||||||
|
|
||||||
from . import tables, views, forms
|
from . import tables, views, forms
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,6 +17,7 @@ class OrganizationalUnitView(views.BaseTableView):
|
||||||
search_form_class = forms.NameSearchForm
|
search_form_class = forms.NameSearchForm
|
||||||
permissions = ['a2_rbac.search_organizationalunit']
|
permissions = ['a2_rbac.search_organizationalunit']
|
||||||
title = _('Organizational units')
|
title = _('Organizational units')
|
||||||
|
formats = ['json']
|
||||||
|
|
||||||
listing = OrganizationalUnitView.as_view()
|
listing = OrganizationalUnitView.as_view()
|
||||||
|
|
||||||
|
@ -74,3 +79,16 @@ class OrganizationalUnitDeleteView(views.BaseDeleteView):
|
||||||
**kwargs)
|
**kwargs)
|
||||||
|
|
||||||
delete = OrganizationalUnitDeleteView.as_view()
|
delete = OrganizationalUnitDeleteView.as_view()
|
||||||
|
|
||||||
|
|
||||||
|
class RolesExportView(views.ExportMixin, OrganizationalUnitView):
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
export = data_transfer.export_site(
|
||||||
|
data_transfer.ExportContext(
|
||||||
|
ou_qs=self.get_table_data(),
|
||||||
|
export_roles=False,
|
||||||
|
export_ous=True))
|
||||||
|
return self.export_response(json.dumps(export), 'application/json', 'json')
|
||||||
|
|
||||||
|
|
||||||
|
export = RolesExportView.as_view()
|
||||||
|
|
|
@ -26,4 +26,5 @@
|
||||||
{% with row_link=1 %}
|
{% with row_link=1 %}
|
||||||
{% render_table table "authentic2/manager/table.html" %}
|
{% render_table table "authentic2/manager/table.html" %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
{% include "authentic2/manager/export_include.html" with export_view_name="a2-manager-ou-export" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -105,6 +105,9 @@ urlpatterns = required(
|
||||||
name='a2-manager-ou-edit'),
|
name='a2-manager-ou-edit'),
|
||||||
url(r'^organizational-units/(?P<pk>\d+)/delete/$', ou_views.delete,
|
url(r'^organizational-units/(?P<pk>\d+)/delete/$', ou_views.delete,
|
||||||
name='a2-manager-ou-delete'),
|
name='a2-manager-ou-delete'),
|
||||||
|
url(r'^organizational-units/export/(?P<format>json)/$',
|
||||||
|
ou_views.export,
|
||||||
|
name='a2-manager-ou-export'),
|
||||||
|
|
||||||
# Services
|
# Services
|
||||||
url(r'^services/$', service_views.listing,
|
url(r'^services/$', service_views.listing,
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
from utils import login
|
||||||
|
|
||||||
|
|
||||||
|
def test_manager_ou_export(app, admin, ou1, role_ou1, ou2, role_ou2):
|
||||||
|
response = login(app, admin, 'a2-manager-ous')
|
||||||
|
|
||||||
|
export_response = response.click('JSON')
|
||||||
|
export = export_response.json
|
||||||
|
|
||||||
|
assert export.keys() == ['ous']
|
||||||
|
assert len(export['ous']) == 3
|
||||||
|
assert set([ou['slug'] for ou in export['ous']]) == set(['default', 'ou1', 'ou2'])
|
||||||
|
|
||||||
|
response.form.set('search-text', 'ou1')
|
||||||
|
search_response = response.form.submit()
|
||||||
|
|
||||||
|
export_response = search_response.click('JSON')
|
||||||
|
export = export_response.json
|
||||||
|
|
||||||
|
assert len(export['ous']) == 1
|
||||||
|
assert export['ous'][0]['slug'] == 'ou1'
|
Loading…
Reference in New Issue