Bulk-Commit: Darft: Anmeldetool.

Interface Definition: done
Server-Side-Implementation: partly done (CR missing, potential Refactor, ...)
Client-Side-Implementation: started: (UI: done, Service: started, but works with SSR)
Missing: Permissions / Roles to restrict access to an event.
Missing: Fields on Event.
Missing: Good Styling
Time-Took: about 12 Hours.
Learning: Commit in smaller packets, rest will be discussed at CR
This commit is contained in:
Konstantin Hintermayer
2025-05-14 20:40:10 +02:00
parent e45fce2e65
commit 38c5bef225
17 changed files with 508 additions and 92 deletions

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Oqtane.Enums;
using Oqtane.Extensions;
using Oqtane.Infrastructure;
using Oqtane.Models;
using Oqtane.Security;
@ -14,15 +15,17 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
{
public class ServerEventRegistrationService : IEventRegistrationService
{
private readonly IEventRepository _EventRegistrationRepository;
private readonly IEventRepository _EventRepository;
private readonly IResponseRepository _ResponseRepository;
private readonly IUserPermissions _userPermissions;
private readonly ILogManager _logger;
private readonly IHttpContextAccessor _accessor;
private readonly Alias _alias;
public ServerEventRegistrationService(IEventRepository EventRegistrationRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
public ServerEventRegistrationService(IEventRepository EventRepository, IResponseRepository ResponseRepository, IUserPermissions userPermissions, ITenantManager tenantManager, ILogManager logger, IHttpContextAccessor accessor)
{
_EventRegistrationRepository = EventRegistrationRepository;
_EventRepository = EventRepository;
_ResponseRepository = ResponseRepository;
_userPermissions = userPermissions;
_logger = logger;
_accessor = accessor;
@ -33,7 +36,7 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, NewEvent.ModuleId, PermissionNames.Edit))
{
NewEvent = _EventRegistrationRepository.AddEvent(NewEvent);
NewEvent = _EventRepository.AddEvent(NewEvent);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {NewEvent}", NewEvent);
}
else
@ -44,32 +47,90 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
return Task.FromResult(NewEvent);
}
public Task<Response> AddOrUpdateResponseAsync(int EventId, int ModuleId, bool ResponseType)
public Task<Response> AddResponseAsync(Response Response)
{
throw new System.NotImplementedException();
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, Response.ModuleId, PermissionNames.View))
{
Response = _ResponseRepository.AddResponse(Response);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {NewEvent}", Response);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Add Attempt {NewEvent}", Response);
Response = null;
}
return Task.FromResult(Response);
}
public Task<Response> UpdateResponseAsync(Response Response)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, Response.ModuleId, PermissionNames.View))
{
Response = _ResponseRepository.UpdateResponse(Response);
_logger.Log(LogLevel.Information, this, LogFunction.Create, "EventRegistration Added {NewEvent}", Response);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Add Attempt {NewEvent}", Response);
Response = null;
}
return Task.FromResult(Response);
}
public Task DeleteEventAsync(int EventId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
{
_EventRegistrationRepository.DeleteEvent(EventId);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "EventRegistration Deleted {EventId}", EventId);
_EventRepository.DeleteEvent(EventId);
_logger.Log(LogLevel.Information, this, LogFunction.Delete, "Event Deleted {EventId}", EventId);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Delete Attempt {EventId} {ModuleId}", EventId, ModuleId);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Delete Attempt {EventId} {ModuleId}", EventId, ModuleId);
}
return Task.CompletedTask;
}
public Task<Event> GetEventAsync(int EventId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_EventRepository.GetEvent(EventId, true));
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Get Attempt {ModuleId}", ModuleId);
return null;
}
}
public Task<(Event, Response)> GetEventDetails(int EventId, int ModuleId)
{
throw new System.NotImplementedException();
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
Event currentEvent = _EventRepository.GetEvent(EventId);
Response rsvp = _ResponseRepository.GetResponse(EventId, _accessor.HttpContext.User.UserId());
return Task.FromResult((currentEvent, rsvp));
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Get Attempt {ModuleId}", ModuleId);
return null;
}
}
public Task<List<Response>> GetEventResponses(int EventId, int ModuleId)
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.Edit))
{
return Task.FromResult(_ResponseRepository.GetResponses(EventId, ModuleId).ToList());
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Response Get Attempt {ModuleId}", ModuleId);
return null;
}
throw new System.NotImplementedException();
}
@ -77,11 +138,11 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, ModuleId, PermissionNames.View))
{
return Task.FromResult(_EventRegistrationRepository.GetEvents(ModuleId).ToList());
return Task.FromResult(_EventRepository.GetEvents(ModuleId).ToList());
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Get Attempt {ModuleId}", ModuleId);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Events Get Attempt {ModuleId}", ModuleId);
return null;
}
}
@ -90,17 +151,19 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
{
if (_userPermissions.IsAuthorized(_accessor.HttpContext.User, _alias.SiteId, EntityNames.Module, NewEvent.ModuleId, PermissionNames.Edit))
{
NewEvent = _EventRegistrationRepository.UpdateEvent(NewEvent);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "EventRegistration Updated {NewEvent}", NewEvent);
NewEvent = _EventRepository.UpdateEvent(NewEvent);
_logger.Log(LogLevel.Information, this, LogFunction.Update, "Event Updated {NewEvent}", NewEvent);
}
else
{
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized EventRegistration Update Attempt {NewEvent}", NewEvent);
_logger.Log(LogLevel.Error, this, LogFunction.Security, "Unauthorized Event Update Attempt {NewEvent}", NewEvent);
NewEvent = null;
}
return Task.FromResult(NewEvent);
}
// TODO: Implement the methods for EventResponses
/*
public Task<Models.Event> GetEventRegistrationAsync(int EventRegistrationId, int ModuleId)
@ -147,5 +210,8 @@ namespace SZUAbsolventenverein.Module.EventRegistration.Services
}
}*/
}
}