Compare commits

..

8 Commits

Author SHA1 Message Date
Yann Weber b6f173800c manager: make agenda's groups foldable (#85616)
gitea/chrono/pipeline/head There was a failure building this commit Details
2024-04-10 17:43:11 +02:00
Benjamin Dauvergne 5fa96e62a8 agendas: fix counting of unlocked bookings with respect to waiting lists (#89266)
gitea/chrono/pipeline/head This commit looks good Details
2024-04-10 10:12:15 +02:00
Lauréline Guérin 7c91b91d89 export_import: post bundle (#89035)
gitea/chrono/pipeline/head This commit looks good Details
2024-04-04 15:49:05 +02:00
Lauréline Guérin a167a91cde export_import: replace APIError by APIErrorBadRequest (#88593) 2024-04-04 15:49:05 +02:00
Lauréline Guérin 56b794468f export_import: remove authent on redirect test (#88593) 2024-04-04 15:49:05 +02:00
Lauréline Guérin 184cf83dd7
translation update
gitea/chrono/pipeline/head This commit looks good Details
2024-04-04 15:41:00 +02:00
Yann Weber 4e6f41c4de tests: remove transactional_db fixture for migrations tests (#89040)
gitea/chrono/pipeline/head This commit looks good Details
2024-04-04 10:29:02 +02:00
Benjamin Dauvergne 42f73e2626 ants_hub: push Place.logo_url to ants-hub (#89020)
gitea/chrono/pipeline/head This commit looks good Details
2024-04-03 14:58:35 +02:00
9 changed files with 166 additions and 44 deletions

View File

@ -2495,13 +2495,15 @@ class Event(WithInspectMixin, models.Model):
'booking',
filter=Q(
booking__cancellation_datetime__isnull=True,
booking__in_waiting_list=False,
)
& ~Q(booking__lease__lock_code=lock_code),
),
unlocked_booked_waiting_list_places=Count(
'booking',
filter=Q(
booking__cancellation_datetime__isnull=False,
booking__cancellation_datetime__isnull=True,
booking__in_waiting_list=True,
)
& ~Q(booking__lease__lock_code=lock_code),
),

View File

@ -208,6 +208,7 @@ class Place(models.Model):
'annulation_url': self.cancel_url,
'plages': list(self.iter_open_dates()),
'rdvs': list(self.iter_predemandes()),
'logo_url': self.logo_url,
}
return payload

View File

@ -14,7 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import io
import json
import tarfile
@ -29,7 +28,7 @@ from rest_framework.generics import GenericAPIView
from rest_framework.response import Response
from chrono.agendas.models import Agenda, Category, EventsType, Resource, UnavailabilityCalendar
from chrono.api.utils import APIError
from chrono.api.utils import APIErrorBadRequest
from chrono.apps.export_import.models import Application, ApplicationElement
from chrono.manager.utils import import_site
@ -237,14 +236,14 @@ def component_redirect(request, component_type, slug):
class BundleCheck(GenericAPIView):
permission_classes = (permissions.IsAdminUser,)
def put(self, request, *args, **kwargs):
tar_io = io.BytesIO(request.read())
def post(self, request, *args, **kwargs):
bundle = request.FILES['bundle']
try:
with tarfile.open(fileobj=tar_io) as tar:
with tarfile.open(fileobj=bundle) as tar:
try:
manifest = json.loads(tar.extractfile('manifest.json').read().decode())
except KeyError:
raise APIError(_('Invalid tar file, missing manifest'))
raise APIErrorBadRequest(_('Invalid tar file, missing manifest'))
application_slug = manifest.get('slug')
application_version = manifest.get('version_number')
if not application_slug or not application_version:
@ -334,7 +333,7 @@ class BundleCheck(GenericAPIView):
}
)
except tarfile.TarError:
raise APIError(_('Invalid tar file'))
raise APIErrorBadRequest(_('Invalid tar file'))
return Response(
{
@ -355,15 +354,15 @@ class BundleImport(GenericAPIView):
permission_classes = (permissions.IsAdminUser,)
install = True
def put(self, request, *args, **kwargs):
tar_io = io.BytesIO(request.read())
def post(self, request, *args, **kwargs):
bundle = request.FILES['bundle']
components = {}
try:
with tarfile.open(fileobj=tar_io) as tar:
with tarfile.open(fileobj=bundle) as tar:
try:
manifest = json.loads(tar.extractfile('manifest.json').read().decode())
except KeyError:
raise APIError(_('Invalid tar file, missing manifest'))
raise APIErrorBadRequest(_('Invalid tar file, missing manifest'))
self.application = Application.update_or_create_from_manifest(
manifest,
tar,
@ -382,7 +381,7 @@ class BundleImport(GenericAPIView):
tar.extractfile('%s/%s' % (element['type'], element['slug'])).read().decode()
)
except KeyError:
raise APIError(
raise APIErrorBadRequest(
_(
'Invalid tar file, missing component %s/%s'
% (element['type'], element['slug'])
@ -390,7 +389,7 @@ class BundleImport(GenericAPIView):
)
components[component_type].append(json.loads(component_content).get('data'))
except tarfile.TarError:
raise APIError(_('Invalid tar file'))
raise APIErrorBadRequest(_('Invalid tar file'))
# init cache of application elements, from manifest
self.application_elements = set()

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: chrono 0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-03-21 13:40+0100\n"
"POT-Creation-Date: 2024-04-04 15:40+0200\n"
"PO-Revision-Date: 2024-02-01 09:50+0100\n"
"Last-Translator: Frederic Peters <fpeters@entrouvert.com>\n"
"Language: French\n"
@ -500,6 +500,11 @@ msgstr "Annulation en cours"
msgid "Bad datetime format \"%s\""
msgstr "Mauvais format pour la date/heure « %s »"
#: agendas/models.py
#, python-format
msgid "Bad time format \"%s\""
msgstr "Mauvais format pour lheure « %s »"
#: agendas/models.py
msgid "Daily"
msgstr "Tous les jours"
@ -1558,10 +1563,12 @@ msgid "Booked"
msgstr "Réservé"
#: api/views.py manager/forms.py
#: manager/templates/chrono/manager_partial_bookings_month_view.html
msgid "Present"
msgstr "Présent"
#: api/views.py manager/forms.py
#: manager/templates/chrono/manager_partial_bookings_month_view.html
msgid "Absent"
msgstr "Absent"
@ -2096,6 +2103,7 @@ msgid "Without booking"
msgstr "Sans réservation"
#: manager/forms.py
#: manager/templates/chrono/manager_partial_bookings_month_view.html
msgid "Not checked"
msgstr "Non pointé"

View File

@ -58,6 +58,7 @@ def test_sync_ants_hub(db, hub, place_agenda, freezer):
'rdvs': [],
'url': '',
'ville': 'Newcity',
'logo_url': '',
}
assert len(payload['collectivites'][0]['lieux'][0]['plages']) == 39
assert payload['collectivites'][0]['lieux'][0]['plages'][0] == {

View File

@ -58,6 +58,7 @@ def ants_setup(db, freezer):
address='2 rue du four',
zipcode='99999',
city_name='Saint-Didier',
logo_url='https://saint-didier.fr/logo.png',
)
annexe = Place.objects.create(
id=2,
@ -525,6 +526,7 @@ def test_export_to_push(ants_setup):
'types_rdv': ['CNI', 'PASSPORT'],
},
],
'logo_url': 'https://saint-didier.fr/logo.png',
},
{
'full': True,
@ -618,6 +620,7 @@ def test_export_to_push(ants_setup):
'types_rdv': ['CNI', 'PASSPORT'],
},
],
'logo_url': '',
},
],
}

View File

@ -859,3 +859,82 @@ def test_api_events_fillslots_with_lock_code_expiration(app, user, freezer):
assert response.json['data'][0]['places']['reserved'] == 0
assert response.json['data'][1]['places']['available'] == 2
assert response.json['data'][1]['places']['reserved'] == 0
def test_waitin_list_places_using_lock_code(app, user, freezer):
agenda = build_event_agenda(
events={
'Event 1': {
'start_datetime': now() + datetime.timedelta(days=1),
'places': 2,
'waiting_list_places': 3,
}
}
)
# setup authorization
app.authorization = ('Basic', ('john.doe', 'password'))
# list events
resp = app.get(agenda.get_datetimes_url())
slot = resp.json['data'][0]
assert slot['places']['available'] == 2
assert slot['places']['full'] is False
# book first one
fillslot_url = slot['api']['fillslot_url']
datas = [app.post_json(fillslot_url, params={'lock_code': f'MYLOCK{i}'}).json for i in range(4)]
assert all(data['err'] == 0 for data in datas), 'Not all responses are ok'
# cancel second booking (in main list)
resp = app.post_json(datas[1]['api']['cancel_url'])
assert resp.json['err'] == 0
# cancel fourth booking (in waiting list)
resp = app.post_json(datas[3]['api']['cancel_url'])
assert resp.json['err'] == 0
# list events without lock code
resp = app.get(agenda.get_datetimes_url())
places = resp.json['data'][0]['places']
assert places == {
'total': 2,
'reserved': 1,
'available': 1,
'full': False,
'has_waiting_list': True,
'waiting_list_total': 3,
'waiting_list_reserved': 1,
'waiting_list_available': 2,
'waiting_list_activated': True,
}
# list events with lock code of first booking (in main list)
resp = app.get(agenda.get_datetimes_url(), params={'lock_code': 'MYLOCK0', 'hide_disabled': 'true'})
places = resp.json['data'][0]['places']
assert places == {
'total': 2,
'reserved': 0,
'available': 2,
'full': False,
'has_waiting_list': True,
'waiting_list_total': 3,
'waiting_list_reserved': 1,
'waiting_list_available': 2,
'waiting_list_activated': True,
}
# list events with lock code of third booking (in waiting list)
resp = app.get(agenda.get_datetimes_url(), params={'lock_code': 'MYLOCK2', 'hide_disabled': 'true'})
places = resp.json['data'][0]['places']
assert places == {
'total': 2,
'reserved': 1,
'available': 1,
'full': False,
'has_waiting_list': True,
'waiting_list_total': 3,
'waiting_list_reserved': 0,
'waiting_list_available': 3,
'waiting_list_activated': False,
}

View File

@ -375,8 +375,7 @@ def test_unknown_compoment_type_dependencies(app, admin_user):
app.get('/api/export-import/unknown/foo/dependencies/', status=404)
def test_redirect(app, user):
app.authorization = ('Basic', ('john', 'doe'))
def test_redirect(app):
agenda = Agenda.objects.create(label='Rdv', slug='rdv', kind='meetings')
category = Category.objects.create(slug='cat', label='Category')
resource = Resource.objects.create(slug='foo', label='Foo')
@ -541,7 +540,7 @@ def test_bundle_import(app, admin_user):
EventsType.objects.all().delete()
UnavailabilityCalendar.objects.all().delete()
resp = app.put('/api/export-import/bundle-import/', bundles[0])
resp = app.post('/api/export-import/bundle-import/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert Agenda.objects.all().count() == 4
assert resp.json['err'] == 0
assert Application.objects.count() == 1
@ -576,7 +575,7 @@ def test_bundle_import(app, admin_user):
)
# check update
resp = app.put('/api/export-import/bundle-import/', bundles[1])
resp = app.post('/api/export-import/bundle-import/', upload_files=[('bundle', 'bundle.tar', bundles[1])])
assert Agenda.objects.all().count() == 4
assert resp.json['err'] == 0
assert Application.objects.count() == 1
@ -599,7 +598,9 @@ def test_bundle_import(app, admin_user):
assert last_snapshot.application_version == '42.1'
# bad file format
resp = app.put('/api/export-import/bundle-import/', b'garbage')
resp = app.post(
'/api/export-import/bundle-import/', upload_files=[('bundle', 'bundle.tar', b'garbage')], status=400
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file'
@ -610,7 +611,11 @@ def test_bundle_import(app, admin_user):
tarinfo = tarfile.TarInfo('foo.json')
tarinfo.size = len(foo_fd.getvalue())
tar.addfile(tarinfo, fileobj=foo_fd)
resp = app.put('/api/export-import/bundle-import/', tar_io.getvalue())
resp = app.post(
'/api/export-import/bundle-import/',
upload_files=[('bundle', 'bundle.tar', tar_io.getvalue())],
status=400,
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file, missing manifest'
@ -626,7 +631,11 @@ def test_bundle_import(app, admin_user):
tarinfo = tarfile.TarInfo('manifest.json')
tarinfo.size = len(manifest_fd.getvalue())
tar.addfile(tarinfo, fileobj=manifest_fd)
resp = app.put('/api/export-import/bundle-import/', tar_io.getvalue())
resp = app.post(
'/api/export-import/bundle-import/',
upload_files=[('bundle', 'bundle.tar', tar_io.getvalue())],
status=400,
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file, missing component agendas/foo'
@ -635,7 +644,7 @@ def test_bundle_declare(app, admin_user):
app.authorization = ('Basic', ('admin', 'admin'))
bundle = create_bundle(app, admin_user, visible=False)
resp = app.put('/api/export-import/bundle-declare/', bundle)
resp = app.post('/api/export-import/bundle-declare/', upload_files=[('bundle', 'bundle.tar', bundle)])
assert Agenda.objects.all().count() == 4
assert resp.json['err'] == 0
assert Application.objects.count() == 1
@ -662,14 +671,16 @@ def test_bundle_declare(app, admin_user):
# and remove agendas to have unknown references in manifest
Agenda.objects.all().delete()
resp = app.put('/api/export-import/bundle-declare/', bundle)
resp = app.post('/api/export-import/bundle-declare/', upload_files=[('bundle', 'bundle.tar', bundle)])
assert Application.objects.count() == 1
application = Application.objects.latest('pk')
assert application.visible is True
assert ApplicationElement.objects.count() == 4 # category, events_type, unavailability_calendar, resource
# bad file format
resp = app.put('/api/export-import/bundle-declare/', b'garbage')
resp = app.post(
'/api/export-import/bundle-declare/', upload_files=[('bundle', 'bundle.tar', b'garbage')], status=400
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file'
@ -680,7 +691,11 @@ def test_bundle_declare(app, admin_user):
tarinfo = tarfile.TarInfo('foo.json')
tarinfo.size = len(foo_fd.getvalue())
tar.addfile(tarinfo, fileobj=foo_fd)
resp = app.put('/api/export-import/bundle-declare/', tar_io.getvalue())
resp = app.post(
'/api/export-import/bundle-declare/',
upload_files=[('bundle', 'bundle.tar', tar_io.getvalue())],
status=400,
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file, missing manifest'
@ -696,7 +711,11 @@ def test_bundle_declare(app, admin_user):
tarinfo = tarfile.TarInfo('manifest.json')
tarinfo.size = len(manifest_fd.getvalue())
tar.addfile(tarinfo, fileobj=manifest_fd)
resp = app.put('/api/export-import/bundle-declare/', tar_io.getvalue())
resp = app.post(
'/api/export-import/bundle-declare/',
upload_files=[('bundle', 'bundle.tar', tar_io.getvalue())],
status=400,
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file, missing component agendas/foo'
@ -779,13 +798,17 @@ def test_bundle_check(app, admin_user):
incomplete_bundles.append(tar_io.getvalue())
# incorrect bundles, missing information
resp = app.put('/api/export-import/bundle-check/', incomplete_bundles[0])
resp = app.post(
'/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', incomplete_bundles[0])]
)
assert resp.json == {'data': {}}
resp = app.put('/api/export-import/bundle-check/', incomplete_bundles[1])
resp = app.post(
'/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', incomplete_bundles[1])]
)
assert resp.json == {'data': {}}
# not yet imported
resp = app.put('/api/export-import/bundle-check/', bundles[0])
resp = app.post('/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert resp.json == {
'data': {
'differences': [],
@ -805,13 +828,13 @@ def test_bundle_check(app, admin_user):
}
# import bundle
resp = app.put('/api/export-import/bundle-import/', bundles[0])
resp = app.post('/api/export-import/bundle-import/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert Application.objects.count() == 1
assert ApplicationElement.objects.count() == 8
# remove application links
Application.objects.all().delete()
resp = app.put('/api/export-import/bundle-check/', bundles[0])
resp = app.post('/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert resp.json == {
'data': {
'differences': [],
@ -871,12 +894,12 @@ def test_bundle_check(app, admin_user):
}
# import bundle again, recreate links
resp = app.put('/api/export-import/bundle-import/', bundles[0])
resp = app.post('/api/export-import/bundle-import/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert Application.objects.count() == 1
assert ApplicationElement.objects.count() == 8
# no changes since last import
resp = app.put('/api/export-import/bundle-check/', bundles[0])
resp = app.post('/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert resp.json == {
'data': {
'differences': [],
@ -901,7 +924,7 @@ def test_bundle_check(app, admin_user):
)
# and check
resp = app.put('/api/export-import/bundle-check/', bundles[0])
resp = app.post('/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', bundles[0])])
assert resp.json == {
'data': {
'differences': [
@ -993,10 +1016,10 @@ def test_bundle_check(app, admin_user):
}
# update bundle
resp = app.put('/api/export-import/bundle-import/', bundles[1])
resp = app.post('/api/export-import/bundle-import/', upload_files=[('bundle', 'bundle.tar', bundles[1])])
# and check
resp = app.put('/api/export-import/bundle-check/', bundles[1])
resp = app.post('/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', bundles[1])])
assert resp.json == {
'data': {
'differences': [],
@ -1008,7 +1031,7 @@ def test_bundle_check(app, admin_user):
# snapshots without application info
AgendaSnapshot.objects.update(application_slug=None, application_version=None)
resp = app.put('/api/export-import/bundle-check/', bundles[1])
resp = app.post('/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', bundles[1])])
assert resp.json == {
'data': {
'differences': [],
@ -1024,7 +1047,9 @@ def test_bundle_check(app, admin_user):
}
# bad file format
resp = app.put('/api/export-import/bundle-check/', b'garbage')
resp = app.post(
'/api/export-import/bundle-check/', upload_files=[('bundle', 'bundle.tar', b'garbage')], status=400
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file'
@ -1035,6 +1060,10 @@ def test_bundle_check(app, admin_user):
tarinfo = tarfile.TarInfo('foo.json')
tarinfo.size = len(foo_fd.getvalue())
tar.addfile(tarinfo, fileobj=foo_fd)
resp = app.put('/api/export-import/bundle-check/', tar_io.getvalue())
resp = app.post(
'/api/export-import/bundle-check/',
upload_files=[('bundle', 'bundle.tar', tar_io.getvalue())],
status=400,
)
assert resp.json['err']
assert resp.json['err_desc'] == 'Invalid tar file, missing manifest'

View File

@ -195,7 +195,7 @@ def test_meeting_event_exclusion_constraint():
)
def test_clean_time_period_exceptions(transactional_db):
def test_clean_time_period_exceptions():
app = 'agendas'
migrate_from = [(app, '0065_unavailability_calendar')]
@ -297,7 +297,7 @@ def test_clean_time_period_exceptions(transactional_db):
@override_settings(LANGUAGE_CODE='fr-fr')
def test_translate_holidays_exceptions(transactional_db):
def test_translate_holidays_exceptions():
app = 'agendas'
migrate_from = [(app, '0068_remove_timeperiodexception_external')]
@ -344,7 +344,7 @@ def test_translate_holidays_exceptions(transactional_db):
assert desk.timeperiodexception_set.filter(label='Jour de lAn').count() == 1
def test_migration_convert_week_days(transactional_db):
def test_migration_convert_week_days():
app = 'agendas'
migrate_from = [(app, '0156_update_dow_index')]
@ -392,7 +392,7 @@ def test_migration_convert_week_days(transactional_db):
assert SharedCustodyRule.objects.get().days == [1, 5, 7]
def test_migration_booking_check_data(transactional_db):
def test_migration_booking_check_data():
app = 'agendas'
migrate_from = [(app, '0161_add_booking_check_model')]