Projet

Général

Profil

0005-manager-add-ous-export-29162.patch

Benjamin Dauvergne, 18 décembre 2018 15:56

Télécharger (3,88 ko)

Voir les différences:

Subject: [PATCH 5/5] manager: add ous export (#29162)

 src/authentic2/manager/ou_views.py            | 18 ++++++++++++++++
 .../templates/authentic2/manager/ous.html     |  1 +
 src/authentic2/manager/urls.py                |  3 +++
 tests/test_ou_manager.py                      | 21 +++++++++++++++++++
 4 files changed, 43 insertions(+)
 create mode 100644 tests/test_ou_manager.py
src/authentic2/manager/ou_views.py
1
import json
2

  
1 3
from django_rbac.utils import get_ou_model
2 4
from django.http import HttpResponseRedirect
3 5
from django.contrib import messages
4 6
from django.utils.translation import ugettext as _
5 7

  
8
from authentic2 import data_transfer
9

  
6 10
from . import tables, views, forms
7 11

  
8 12

  
......
13 17
    search_form_class = forms.NameSearchForm
14 18
    permissions = ['a2_rbac.search_organizationalunit']
15 19
    title = _('Organizational units')
20
    formats = ['json']
16 21

  
17 22
listing = OrganizationalUnitView.as_view()
18 23

  
......
74 79
                                                                  **kwargs)
75 80

  
76 81
delete = OrganizationalUnitDeleteView.as_view()
82

  
83

  
84
class RolesExportView(views.ExportMixin, OrganizationalUnitView):
85
    def get(self, request, *args, **kwargs):
86
        export = data_transfer.export_site(
87
            data_transfer.ExportContext(
88
                ou_qs=self.get_table_data(),
89
                export_roles=False,
90
                export_ous=True))
91
        return self.export_response(json.dumps(export), 'application/json', 'json')
92

  
93

  
94
export = RolesExportView.as_view()
src/authentic2/manager/templates/authentic2/manager/ous.html
26 26
  {% with row_link=1 %}
27 27
      {% render_table table "authentic2/manager/table.html" %}
28 28
  {% endwith %}
29
  {% include "authentic2/manager/export_include.html" with export_view_name="a2-manager-ou-export" %}
29 30
{% endblock %}
src/authentic2/manager/urls.py
105 105
            name='a2-manager-ou-edit'),
106 106
        url(r'^organizational-units/(?P<pk>\d+)/delete/$', ou_views.delete,
107 107
            name='a2-manager-ou-delete'),
108
        url(r'^organizational-units/export/(?P<format>json)/$',
109
            ou_views.export,
110
            name='a2-manager-ou-export'),
108 111

  
109 112
        # Services
110 113
        url(r'^services/$', service_views.listing,
tests/test_ou_manager.py
1
from utils import login
2

  
3

  
4
def test_manager_ou_export(app, admin, ou1, role_ou1, ou2, role_ou2):
5
    response = login(app, admin, 'a2-manager-ous')
6

  
7
    export_response = response.click('JSON')
8
    export = export_response.json
9

  
10
    assert export.keys() == ['ous']
11
    assert len(export['ous']) == 3
12
    assert set([ou['slug'] for ou in export['ous']]) == set(['default', 'ou1', 'ou2'])
13

  
14
    response.form.set('search-text', 'ou1')
15
    search_response = response.form.submit()
16

  
17
    export_response = search_response.click('JSON')
18
    export = export_response.json
19

  
20
    assert len(export['ous']) == 1
21
    assert export['ous'][0]['slug'] == 'ou1'
0
-