api: display roles on agenda details (#57103)
This commit is contained in:
parent
8d83d525f1
commit
b7811f5235
|
@ -353,6 +353,8 @@ def get_agenda_detail(request, agenda, check_events=False):
|
|||
'kind': agenda.kind,
|
||||
'minimal_booking_delay': agenda.minimal_booking_delay,
|
||||
'maximal_booking_delay': agenda.maximal_booking_delay,
|
||||
'edit_role': agenda.edit_role.name if agenda.edit_role else None,
|
||||
'view_role': agenda.view_role.name if agenda.view_role else None,
|
||||
}
|
||||
|
||||
if agenda.kind == 'meetings':
|
||||
|
@ -723,7 +725,7 @@ class Agendas(APIView):
|
|||
continue
|
||||
agendas.append(get_agenda_detail(request, agenda))
|
||||
|
||||
return Response({'data': agendas})
|
||||
return Response({'err': 0, 'data': agendas})
|
||||
|
||||
|
||||
agendas = Agendas.as_view()
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import datetime
|
||||
|
||||
import pytest
|
||||
from django.contrib.auth.models import Group
|
||||
from django.db import connection
|
||||
from django.test.utils import CaptureQueriesContext
|
||||
from django.utils.timezone import localtime, now
|
||||
|
@ -22,28 +23,40 @@ pytestmark = pytest.mark.django_db
|
|||
|
||||
|
||||
def test_agendas_api(app):
|
||||
edit_group = Group.objects.create(name='Edit')
|
||||
view_group = Group.objects.create(name='View')
|
||||
category_a = Category.objects.create(label='Category A')
|
||||
category_b = Category.objects.create(label='Category B')
|
||||
group = AbsenceReasonGroup.objects.create(label='Foo')
|
||||
reason = AbsenceReason.objects.create(group=group, label='Foo bar')
|
||||
reason2 = AbsenceReason.objects.create(group=group, label='Foo bar baz')
|
||||
event_agenda = Agenda.objects.create(label='Foo bar', category=category_a, absence_reasons_group=group)
|
||||
event_agenda = Agenda.objects.create(
|
||||
label='Foo bar', category=category_a, absence_reasons_group=group, edit_role=edit_group
|
||||
)
|
||||
Desk.objects.create(agenda=event_agenda, slug='_exceptions_holder')
|
||||
event_agenda2 = Agenda.objects.create(label='Foo bar 2', category=category_a)
|
||||
Desk.objects.create(agenda=event_agenda2, slug='_exceptions_holder')
|
||||
event_agenda3 = Agenda.objects.create(label='Foo bar 3', absence_reasons_group=group)
|
||||
Desk.objects.create(agenda=event_agenda3, slug='_exceptions_holder')
|
||||
meetings_agenda1 = Agenda.objects.create(label='Foo bar Meeting', kind='meetings', category=category_b)
|
||||
meetings_agenda1 = Agenda.objects.create(
|
||||
label='Foo bar Meeting', kind='meetings', category=category_b, view_role=view_group
|
||||
)
|
||||
Agenda.objects.create(label='Foo bar Meeting 2', kind='meetings')
|
||||
resource1 = Resource.objects.create(label='Resource 1', description='Foo bar Resource 1')
|
||||
resource2 = Resource.objects.create(label='Resource 2', description='Foo bar Resource 2')
|
||||
Resource.objects.create(label='Resource 3')
|
||||
meetings_agenda1.resources.add(resource1, resource2)
|
||||
Agenda.objects.create(
|
||||
label='Virtual Agenda', kind='virtual', minimal_booking_delay=1, maximal_booking_delay=56
|
||||
label='Virtual Agenda',
|
||||
kind='virtual',
|
||||
minimal_booking_delay=1,
|
||||
maximal_booking_delay=56,
|
||||
edit_role=edit_group,
|
||||
view_role=view_group,
|
||||
)
|
||||
resp = app.get('/api/agenda/')
|
||||
assert resp.json == {
|
||||
'err': 0,
|
||||
'data': [
|
||||
{
|
||||
'text': 'Foo bar',
|
||||
|
@ -52,6 +65,8 @@ def test_agendas_api(app):
|
|||
'kind': 'events',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'edit_role': 'Edit',
|
||||
'view_role': None,
|
||||
'absence_reasons': [
|
||||
{'id': reason.slug, 'slug': reason.slug, 'text': reason.label, 'label': reason.label},
|
||||
{'id': reason2.slug, 'slug': reason2.slug, 'text': reason2.label, 'label': reason2.label},
|
||||
|
@ -68,6 +83,8 @@ def test_agendas_api(app):
|
|||
'slug': 'foo-bar-2',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'edit_role': None,
|
||||
'view_role': None,
|
||||
'api': {
|
||||
'datetimes_url': 'http://testserver/api/agenda/foo-bar-2/datetimes/',
|
||||
'fillslots_url': 'http://testserver/api/agenda/foo-bar-2/fillslots/',
|
||||
|
@ -80,6 +97,8 @@ def test_agendas_api(app):
|
|||
'slug': 'foo-bar-3',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'edit_role': None,
|
||||
'view_role': None,
|
||||
'absence_reasons': [
|
||||
{'id': reason.slug, 'slug': reason.slug, 'text': reason.label, 'label': reason.label},
|
||||
{'id': reason2.slug, 'slug': reason2.slug, 'text': reason2.label, 'label': reason2.label},
|
||||
|
@ -95,6 +114,8 @@ def test_agendas_api(app):
|
|||
'slug': 'foo-bar-meeting',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'edit_role': None,
|
||||
'view_role': 'View',
|
||||
'kind': 'meetings',
|
||||
'resources': [
|
||||
{'id': 'resource-1', 'text': 'Resource 1', 'description': 'Foo bar Resource 1'},
|
||||
|
@ -113,6 +134,8 @@ def test_agendas_api(app):
|
|||
'slug': 'foo-bar-meeting-2',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'edit_role': None,
|
||||
'view_role': None,
|
||||
'kind': 'meetings',
|
||||
'resources': [],
|
||||
'api': {
|
||||
|
@ -128,6 +151,8 @@ def test_agendas_api(app):
|
|||
'slug': 'virtual-agenda',
|
||||
'minimal_booking_delay': 1,
|
||||
'maximal_booking_delay': 56,
|
||||
'edit_role': 'Edit',
|
||||
'view_role': 'View',
|
||||
'kind': 'virtual',
|
||||
'api': {
|
||||
'meetings_url': 'http://testserver/api/agenda/virtual-agenda/meetings/',
|
||||
|
@ -135,7 +160,7 @@ def test_agendas_api(app):
|
|||
'fillslots_url': 'http://testserver/api/agenda/virtual-agenda/fillslots/',
|
||||
},
|
||||
},
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
resp = app.get('/api/agenda/', params={'q': 'foo'})
|
||||
|
@ -147,10 +172,10 @@ def test_agendas_api(app):
|
|||
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = app.get('/api/agenda/')
|
||||
assert len(ctx.captured_queries) == 4
|
||||
assert len(ctx.captured_queries) == 8
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = app.get('/api/agenda/', params={'q': 'MEET'})
|
||||
assert len(ctx.captured_queries) == 2
|
||||
assert len(ctx.captured_queries) == 3
|
||||
|
||||
resp = app.get('/api/agenda/', params={'with_open_events': '1'})
|
||||
assert len(resp.json['data']) == 0
|
||||
|
@ -257,7 +282,7 @@ def test_agendas_api(app):
|
|||
|
||||
with CaptureQueriesContext(connection) as ctx:
|
||||
resp = app.get('/api/agenda/', params={'with_open_events': '1'})
|
||||
assert len(ctx.captured_queries) == 8
|
||||
assert len(ctx.captured_queries) == 9
|
||||
|
||||
|
||||
def test_agendas_meetingtypes_api(app, some_data, meetings_agenda):
|
||||
|
@ -475,6 +500,8 @@ def test_virtual_agenda_detail(app, virtual_meetings_agenda):
|
|||
'slug': 'virtual-agenda',
|
||||
'minimal_booking_delay': None,
|
||||
'maximal_booking_delay': None,
|
||||
'edit_role': None,
|
||||
'view_role': None,
|
||||
'kind': 'virtual',
|
||||
'api': {
|
||||
'meetings_url': 'http://testserver/api/agenda/%s/meetings/' % virtual_meetings_agenda.slug,
|
||||
|
|
Loading…
Reference in New Issue