manager: allow filtering services by OU (#54190)

This commit is contained in:
Valentin Deniaud 2021-05-25 17:54:47 +02:00
parent d838ad1fb7
commit d8cd51c065
3 changed files with 31 additions and 1 deletions

View File

@ -594,6 +594,10 @@ class NameSearchForm(CssClass, PrefixFormMixin, FormWithRequest):
return qs
class ServiceSearchForm(OUSearchForm, NameSearchForm):
pass
class RoleEditForm(SlugMixin, HideOUFieldMixin, LimitQuerysetFormMixin, CssClass, forms.ModelForm):
ou = forms.ModelChoiceField(
queryset=get_ou_model().objects, required=True, label=_('Organizational unit')

View File

@ -26,10 +26,15 @@ class ServicesView(views.HideOUColumnMixin, views.BaseTableView):
model = Service
template_name = 'authentic2/manager/services.html'
table_class = tables.ServiceTable
search_form_class = forms.NameSearchForm
search_form_class = forms.ServiceSearchForm
permissions = ['authentic2.search_service']
title = _('Services')
def get_search_form_kwargs(self):
kwargs = super().get_search_form_kwargs()
kwargs['queryset'] = self.get_queryset()
return kwargs
listing = ServicesView.as_view()

View File

@ -31,6 +31,7 @@ from webtest import Upload
from authentic2.a2_rbac.models import MANAGE_MEMBERS_OP
from authentic2.a2_rbac.utils import get_default_ou
from authentic2.apps.journal.models import Event
from authentic2.models import Service
from authentic2.validators import EmailValidator
from django_rbac.models import VIEW_OP
from django_rbac.utils import get_operation, get_ou_model, get_permission_model, get_role_model
@ -1184,3 +1185,23 @@ def test_display_parent_roles_on_role_page(app, superuser, settings):
'ou1 - parent4',
'ou2 - parent3',
]
def test_manager_service_search(app, admin, ou1):
Service.objects.create(ou=ou1, slug='test', name='Test Service')
Service.objects.create(ou=get_default_ou(), slug='example', name='Example Service')
resp = login(app, admin, 'a2-manager-services')
assert 'Test Service' in resp.text
assert 'Example Service' in resp.text
resp.form.set('search-text', 'example')
resp = resp.form.submit()
assert 'Test Service' not in resp.text
assert 'Example Service' in resp.text
resp.form.set('search-text', '')
resp.form.set('search-ou', ou1.pk)
resp = resp.form.submit()
assert 'Test Service' in resp.text
assert 'Example Service' not in resp.text