api: send a correct management_url to /api/appointments (#89529)
gitea/ants-hub/pipeline/head This commit looks good Details

This commit is contained in:
Benjamin Dauvergne 2024-04-14 12:53:45 +02:00
parent 66c218ce4d
commit a8553f0c72
5 changed files with 23 additions and 13 deletions

View File

@ -68,7 +68,7 @@ class APIDoublon:
identifiant_predemande = rdv.identifiant_predemande.upper()
params = [
('application_id', identifiant_predemande),
('management_url', rdv.gestion_url),
('management_url', rdv.get_gestion_url_for_ants()),
('meeting_point', rdv.lieu.nom),
('meeting_point_id', str(rdv.lieu.id)),
('appointment_date', localtime(rdv.date).strftime('%Y-%m-%d %H:%M:%S')),
@ -147,7 +147,7 @@ def push_rdv(rdv):
delete = True
create = True
elif existing:
if existing[0]['management_url'] != rdv.gestion_url:
if existing[0]['management_url'] != rdv.get_gestion_url_for_ants():
# L'URL de gestion a changé, on supprime le RdV existant
delete = True
create = True

View File

@ -282,8 +282,8 @@ def search_application_ids(request):
{
'meeting_point': rdv.lieu.nom,
'datetime': format_date_ants(rdv.date),
'management_url': request.build_absolute_uri(rdv.make_gestion_url()),
'cancel_url': request.build_absolute_uri(rdv.make_annulation_url()),
'management_url': rdv.get_gestion_url_for_ants(),
'cancel_url': rdv.get_annulation_url_for_ants(),
}
)
rdv_count += 1

View File

@ -8,6 +8,7 @@ import typing
import uuid
from django import forms
from django.conf import settings
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
@ -415,8 +416,10 @@ class RendezVous(models.Model):
natural_key.dependencies = ['data.lieu']
def make_gestion_url(self):
return reverse(
def get_gestion_url_for_ants(self):
if not self.get_gestion_url():
return ''
return settings.ANTS_HUB_BASE_URL + reverse(
'gestion-redirect',
kwargs={
'collectivite_pk': self.lieu.collectivite.pk,
@ -439,8 +442,10 @@ class RendezVous(models.Model):
or self.lieu.collectivite.url
)
def make_annulation_url(self):
return reverse(
def get_annulation_url_for_ants(self):
if not self.get_annulation_url():
return
return settings.ANTS_HUB_BASE_URL + reverse(
'annulation-redirect',
kwargs={
'collectivite_pk': self.lieu.collectivite.pk,

View File

@ -118,6 +118,8 @@ ANTS_HUB_API_URL = 'https://%s:@ants-hub.entrouvert.org/api/chrono/'
ANTS_HUB_BUSY_BACKOFF = 0.5
ANTS_HUB_BASE_URL = 'https://ants-hub.entrouvert.org'
if 'ANTS_HUB_SETTINGS_FILE' in os.environ:
with open(os.environ['ANTS_HUB_SETTINGS_FILE']) as fd:

View File

@ -242,20 +242,20 @@ class TestEndpoints:
assert response.json == {
'123456': [
{
'cancel_url': 'http://testserver/rdv/saint-didier-1/mairie-1/2023-04-11T11:00:00+02:00/'
'cancel_url': 'https://ants-hub.entrouvert.org/rdv/saint-didier-1/mairie-1/2023-04-11T11:00:00+02:00/'
'annulation/7621a90a-2dd3-44e5-9df7-879abddeaad5/',
'datetime': '2023-04-11T11:00:00Z',
'management_url': 'http://testserver/rdv/saint-didier-1/mairie-1/2023-04-11T11:00:00+02:00/'
'management_url': 'https://ants-hub.entrouvert.org/rdv/saint-didier-1/mairie-1/2023-04-11T11:00:00+02:00/'
'gestion/7621a90a-2dd3-44e5-9df7-879abddeaad5/',
'meeting_point': 'Mairie',
}
],
'abCD123456': [
{
'cancel_url': 'http://testserver/rdv/saint-didier-1/mairie-1/2023-04-03T12:15:00+02:00/'
'cancel_url': 'https://ants-hub.entrouvert.org/rdv/saint-didier-1/mairie-1/2023-04-03T12:15:00+02:00/'
'annulation/7cace277-9157-4fbc-9705-45522984805d/',
'datetime': '2023-04-03T12:15:00Z',
'management_url': 'http://testserver/rdv/saint-didier-1/mairie-1/2023-04-03T12:15:00+02:00/'
'management_url': 'https://ants-hub.entrouvert.org/rdv/saint-didier-1/mairie-1/2023-04-03T12:15:00+02:00/'
'gestion/7cace277-9157-4fbc-9705-45522984805d/',
'meeting_point': 'Mairie',
}
@ -419,7 +419,10 @@ class TestAPIV2Push:
}
assert called_qs == [
('application_id', 'ABCD123456'),
('management_url', ''),
(
'management_url',
'https://ants-hub.entrouvert.org/rdv/saint-didier-1/mairie-1/2023-04-03T12:15:00+02:00/gestion/7cace277-9157-4fbc-9705-45522984805d/',
),
('meeting_point', 'Mairie'),
('meeting_point_id', '1'),
('appointment_date', '2023-04-03 12:15:00'),