Securite
- RequireAppKey : filtre qui exige une cle d'API valide ou un utilisateur du
manager. Pose sur les routes de contenu consommees par les apps visiteur
(Configuration, Section, Resource, SectionMap, SectionEvent, SectionAgenda,
SectionParcours, SectionQuiz, ApplicationInstance). Un [Authorize] d'action
ne peut pas assouplir celui de la classe ; seul [AllowAnonymous] le
court-circuite, et le filtre redevient le controle d'acces. Il ferme
l'enumeration par identifiant, pas la confidentialite : la cle s'obtient
par le slug ou le pincode.
- Instance/slug/{slug} rendait le pinCode, l'adresse de facturation, la TVA et
les quotas a qui lit l'URL du site visiteur. StripCommercialFields est
desormais applique sur slug et byPin ; isTrialActive reste expose pour le
filigrane d'essai.
- Device.Create et Device/{id}/detail repondaient 403 a toute tablette depuis
a452f4a (13/03) : la classe exige InstanceAdmin, une cle ne porte que
AppRead. Ouverts a la cle, le cloisonnement par instance etait deja ecrit.
Canal VR
- Device.AppType (defaut Tablet, backfill a 1) ; Create resout
l'ApplicationInstance sur ce type au lieu de Tablet en dur.
- Get filtre optionnellement par appType ; DeviceDetailDTO expose appVersion
et lastSeen.
- PUT Device/{id}/heartbeat : batterie, version, connexion. Volontairement
etroit, une app ne peut ni se renommer ni changer d'instance.
- ApiKeyAppType.VrApp en fin d'enum.
Contenu immersif
- ResourceType : Image360 (11), Video360 (12), Model3D (13), en fin d'enum.
- Section Scene3D : un modele GLB et ses points d'interet, en objet manipule
ou en decor habite. Les points sont des GeoPoint, avec une LocalTransform
en jsonb (convention glTF) ; CRUD dans SectionScene3DController.
- Instance.HasImmersiveContent : l'add-on ajoute 100 Go au quota de stockage,
repose apres un changement de plan et retire a la desactivation.
- ImmersiveBackground (owned) sur Configuration et ApplicationInstance, avec
une image de repli pour les canaux qui ne rendent pas l'immersif.
Export de configuration
- exportVersion (1) et generatedAt : le JSON devient un contrat, lu tel quel
par l'app Unity.
- Section.ToDTO() n'etant pas virtuelle, l'export ne portait aucun champ
specifique de sous-type. Passe par SectionFactory.ToDTO, et charge les
points des Map et des Scene3D.
- Le fond immersif et son repli partent avec les ressources, URL resolues.
Migrations : AddAppTypeToDevice, AddScene3DSectionAndImmersiveAddon,
AddImmersiveBackground.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
266 lines
11 KiB
C#
266 lines
11 KiB
C#
using ManagerService.Data;
|
|
using ManagerService.Data.SubSection;
|
|
using ManagerService.Services;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using ManagerService.Security;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Logging;
|
|
using NSwag.Annotations;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System;
|
|
using ManagerService.DTOs;
|
|
using ManagerService.Helpers;
|
|
|
|
namespace ManagerService.Controllers
|
|
{
|
|
[Authorize(Policy = ManagerService.Service.Security.Policies.ContentEditor)]
|
|
[ApiController, Route("api/[controller]")]
|
|
[OpenApiTag("Section agenda", Description = "Section agenda management")]
|
|
public class SectionAgendaController : ControllerBase
|
|
{
|
|
private readonly MyInfoMateDbContext _myInfoMateDbContext;
|
|
|
|
private readonly ILogger<SectionAgendaController> _logger;
|
|
private readonly IConfiguration _configuration;
|
|
IHexIdGeneratorService idService = new HexIdGeneratorService();
|
|
|
|
public SectionAgendaController(IConfiguration configuration, ILogger<SectionAgendaController> logger, MyInfoMateDbContext myInfoMateDbContext)
|
|
{
|
|
_logger = logger;
|
|
_configuration = configuration;
|
|
_myInfoMateDbContext = myInfoMateDbContext;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get all event from section
|
|
/// </summary>
|
|
/// <param name="sectionAgendaId">Section id</param>
|
|
[AllowAnonymous]
|
|
[RequireAppKey]
|
|
[ProducesResponseType(typeof(List<EventAgendaDTO>), 200)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpGet("{sectionAgendaId}/events")]
|
|
public ObjectResult GetAllEventAgendaFromSection(string sectionAgendaId)
|
|
{
|
|
try
|
|
{
|
|
SectionAgenda sectionAgenda = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).ThenInclude(sa => sa.Resource).FirstOrDefault(sa => sa.Id == sectionAgendaId);
|
|
|
|
if (sectionAgenda == null)
|
|
throw new KeyNotFoundException("Section agenda does not exist");
|
|
|
|
/*List<ProgrammeBlock> programmeBlocks = new List<ProgrammeBlock>();
|
|
foreach (var program in sectionEvent.Programme)
|
|
{
|
|
foreach (var mapAnnotation in program.MapAnnotations) {
|
|
var resource = _myInfoMateDbContext.Resources.FirstOrDefault(r => r.Id == mapAnnotation.IconResourceId);
|
|
if (resource != null)
|
|
{
|
|
mapAnnotation.IconResource = resource; // TO check.. use DTO instead ?
|
|
}
|
|
}
|
|
}*/
|
|
|
|
return new OkObjectResult(sectionAgenda.EventAgendas.Select(ea => ea.ToDTO()));
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new NotFoundObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get upcoming events from section (dateFrom >= today)
|
|
/// </summary>
|
|
/// <param name="sectionAgendaId">Section id</param>
|
|
[AllowAnonymous]
|
|
[RequireAppKey]
|
|
[ProducesResponseType(typeof(List<EventAgendaDTO>), 200)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpGet("{sectionAgendaId}/events/upcoming")]
|
|
public ObjectResult GetUpcomingEventAgendas(string sectionAgendaId, [FromQuery] string? language = null)
|
|
{
|
|
try
|
|
{
|
|
SectionAgenda sectionAgenda = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).ThenInclude(sa => sa.Resource).FirstOrDefault(sa => sa.Id == sectionAgendaId);
|
|
|
|
if (sectionAgenda == null)
|
|
throw new KeyNotFoundException("Section agenda does not exist");
|
|
|
|
var today = DateTime.Today;
|
|
var upcoming = sectionAgenda.EventAgendas
|
|
.Where(ea => ea.DateFrom == null || ea.DateFrom >= today)
|
|
.Where(ea => language == null || ea.Label.Any(l => l.language == language))
|
|
.OrderBy(ea => ea.DateFrom)
|
|
.Select(ea => ea.ToDTO());
|
|
|
|
return new OkObjectResult(upcoming);
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new NotFoundObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create new event
|
|
/// </summary>
|
|
/// <param name="sectionAgendaId">Section agenda Id</param>
|
|
/// <param name="eventAgendaDTO">EventAgenda</param>
|
|
[ProducesResponseType(typeof(EventAgendaDTO), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(typeof(string), 409)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpPost("{sectionAgendaId}/event")]
|
|
public ObjectResult CreateEventAgenda(string sectionAgendaId, [FromBody] EventAgendaDTO eventAgendaDTO)
|
|
{
|
|
try
|
|
{
|
|
if (sectionAgendaId == null)
|
|
throw new ArgumentNullException("Section param is null");
|
|
|
|
if (eventAgendaDTO == null)
|
|
throw new ArgumentNullException("EventAgenda param is null");
|
|
|
|
var existingSection = _myInfoMateDbContext.Sections.OfType<SectionAgenda>().Include(sa => sa.EventAgendas).FirstOrDefault(sa => sa.Id == sectionAgendaId);
|
|
if (existingSection == null)
|
|
throw new KeyNotFoundException("Section agenda does not exist");
|
|
|
|
EventAgenda eventAgenda = new EventAgenda().FromDTO(eventAgendaDTO);
|
|
_myInfoMateDbContext.EventAgendas.Add(eventAgenda);
|
|
_myInfoMateDbContext.SaveChanges();
|
|
|
|
return new OkObjectResult(eventAgenda.ToDTO());
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
return new BadRequestObjectResult(ex.Message) { };
|
|
}
|
|
catch (InvalidOperationException ex)
|
|
{
|
|
return new ConflictObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Update an event agenda
|
|
/// </summary>
|
|
/// <param name="eventAgendaDTO">EventAgenda to update</param>
|
|
[ProducesResponseType(typeof(EventAgendaDTO), 200)]
|
|
[ProducesResponseType(typeof(string), 400)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpPut("event")]
|
|
public ObjectResult UpdateEventAgenda([FromBody] EventAgendaDTO eventAgendaDTO)
|
|
{
|
|
try
|
|
{
|
|
if (eventAgendaDTO == null)
|
|
throw new ArgumentNullException("EventAgenda param is null");
|
|
|
|
var existing = _myInfoMateDbContext.EventAgendas.FirstOrDefault(ea => ea.Id == eventAgendaDTO.id);
|
|
if (existing == null)
|
|
throw new KeyNotFoundException("EventAgenda does not exist");
|
|
|
|
existing.Label = eventAgendaDTO.label;
|
|
existing.Description = eventAgendaDTO.description;
|
|
existing.Type = eventAgendaDTO.type;
|
|
existing.DateAdded = eventAgendaDTO.dateAdded;
|
|
existing.DateFrom = eventAgendaDTO.dateFrom;
|
|
existing.DateTo = eventAgendaDTO.dateTo;
|
|
existing.Website = eventAgendaDTO.website;
|
|
existing.ResourceId = eventAgendaDTO.resourceId;
|
|
existing.Phone = eventAgendaDTO.phone;
|
|
existing.Email = eventAgendaDTO.email;
|
|
existing.SectionAgendaId = eventAgendaDTO.sectionAgendaId;
|
|
existing.SectionEventId = eventAgendaDTO.sectionEventId;
|
|
|
|
if (eventAgendaDTO.address != null)
|
|
{
|
|
existing.Address = new EventAddress
|
|
{
|
|
Address = eventAgendaDTO.address.address,
|
|
StreetNumber = eventAgendaDTO.address.streetNumber,
|
|
StreetName = eventAgendaDTO.address.streetName,
|
|
City = eventAgendaDTO.address.city,
|
|
State = eventAgendaDTO.address.state,
|
|
PostCode = eventAgendaDTO.address.postCode,
|
|
Country = eventAgendaDTO.address.country,
|
|
Geometry = eventAgendaDTO.address.geometry,
|
|
PolyColor = eventAgendaDTO.address.polyColor,
|
|
Zoom = eventAgendaDTO.address.zoom.GetValueOrDefault()
|
|
};
|
|
}
|
|
|
|
_myInfoMateDbContext.SaveChanges();
|
|
|
|
return new OkObjectResult(existing.ToDTO());
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
return new BadRequestObjectResult(ex.Message) { };
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new NotFoundObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Delete an eventAgenda
|
|
/// </summary>
|
|
/// <param name="eventAgendaId">Id of the eventAgenda to delete</param>
|
|
[ProducesResponseType(typeof(string), 202)]
|
|
[ProducesResponseType(typeof(string), 404)]
|
|
[ProducesResponseType(typeof(string), 500)]
|
|
[HttpDelete("event/{eventAgendaId}")]
|
|
public ObjectResult DeleteEventAgenda(int eventAgendaId)
|
|
{
|
|
try
|
|
{
|
|
var eventAgenda = _myInfoMateDbContext.EventAgendas.FirstOrDefault(ea => ea.Id == eventAgendaId);
|
|
if (eventAgenda == null)
|
|
throw new KeyNotFoundException("EventAgenda does not exist");
|
|
|
|
_myInfoMateDbContext.Remove(eventAgenda);
|
|
_myInfoMateDbContext.SaveChanges();
|
|
|
|
return new ObjectResult("The eventAgenda has been deleted") { StatusCode = 202 };
|
|
}
|
|
catch (ArgumentNullException ex)
|
|
{
|
|
return new BadRequestObjectResult(ex.Message) { };
|
|
}
|
|
catch (KeyNotFoundException ex)
|
|
{
|
|
return new NotFoundObjectResult(ex.Message) { };
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
return new ObjectResult(ex.Message) { StatusCode = 500 };
|
|
}
|
|
}
|
|
}
|
|
}
|