Bug fix - notifications audience

* Performers had their notifications publicaly published.
* refacto admin group name
This commit is contained in:
Paul Schneider 2026-10-23 13:32:42 +01:00
commit d476c08046
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
36 changed files with 421 additions and 74 deletions

View file

@ -24,7 +24,7 @@ public sealed class NotificationsApiController : Controller
public async Task<ActionResult<List<Notification>>> GetCurrentUserNotifications()
{
var currentUserId = User.GetUserId();
var isAdmin = User.IsInRole(Constants.AdminGroupName);
var isAdmin = User.IsInRole(Constants.AdminName);
var dismissedIds = string.IsNullOrWhiteSpace(currentUserId)
? new HashSet<long>()

View file

@ -78,7 +78,7 @@ public sealed class ResourceUsageApiController : Controller
[HttpGet(Constants.ResourceUsageAdminRoute)]
public async Task<ActionResult<List<ResourceUsageSummary>>> GetAdminOverview()
{
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
{
return Forbid();
}

View file

@ -7,7 +7,7 @@ using Yavsc.Api.Services;
namespace Yavsc.ApiControllers.Administration;
[ApiController]
[ApiExplorerSettings(GroupName = "administration")]
[ApiExplorerSettings(GroupName = Constants.Administration)]
[Authorize("AdministratorOnly")]
[Route(Constants.APIPrefix + "/administration")]
[Produces("application/json")]

View file

@ -107,7 +107,7 @@ namespace Yavsc.ApiControllers
logger.LogWarning("Got bill ack:"+bill.GetIsAcquitted().ToString());
if (bill is not NominativeServiceCommand { InvoiceEstimateId: not null } invoice)
return Conflict(new { Error = "Create the invoice from a signed estimate first." });
if (User.GetUserId() != invoice.InvoicePerformerId && !User.IsInRole(Constants.AdminGroupName))
if (User.GetUserId() != invoice.InvoicePerformerId && !User.IsInRole(Constants.AdminName))
return Forbid();
return ViewComponent("Bill",new object[] { billingCode, bill, OutputFormat.Pdf, true } );
}

View file

@ -24,12 +24,12 @@ namespace Yavsc.Controllers
}
bool UserIsAdminOrThis(string uid)
{
if (User.IsInRole(Constants.AdminGroupName)) return true;
if (User.IsInRole(Constants.AdminName)) return true;
return uid == User.GetUserId();
}
bool UserIsAdminOrInThese(string oid, string uid)
{
if (User.IsInRole(Constants.AdminGroupName)) return true;
if (User.IsInRole(Constants.AdminName)) return true;
var cuid = User.GetUserId();
return cuid == uid || cuid == oid;
}
@ -79,7 +79,7 @@ namespace Yavsc.Controllers
return BadRequest();
}
var uid = User.GetUserId();
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
{
if (uid != estimate.OwnerId)
{
@ -115,7 +115,7 @@ namespace Yavsc.Controllers
var uid = User.GetUserId();
if (estimate.OwnerId == null) estimate.OwnerId = uid;
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
{
if (uid != estimate.OwnerId)
{
@ -185,7 +185,7 @@ namespace Yavsc.Controllers
return NotFound();
}
var uid = User.GetUserId();
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
{
if (uid != estimate.OwnerId)
{
@ -285,7 +285,7 @@ namespace Yavsc.Controllers
if (estimate == null) return NotFound();
var uid = User.GetUserId();
if (!User.IsInRole(Constants.AdminGroupName) && uid != estimate.OwnerId)
if (!User.IsInRole(Constants.AdminName) && uid != estimate.OwnerId)
return new StatusCodeResult(StatusCodes.Status403Forbidden);
if (body == null || body.FileId <= 0)
@ -319,7 +319,7 @@ namespace Yavsc.Controllers
if (estimate == null) return NotFound();
var uid = User.GetUserId();
if (!User.IsInRole(Constants.AdminGroupName) && uid != estimate.OwnerId)
if (!User.IsInRole(Constants.AdminName) && uid != estimate.OwnerId)
return new StatusCodeResult(StatusCodes.Status403Forbidden);
var link = _context.EstimateAttachedFiles

View file

@ -63,7 +63,7 @@ namespace Yavsc.Controllers
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (estimateTemplate.OwnerId!=uid)
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
return new StatusCodeResult(StatusCodes.Status403Forbidden);
_context.Entry(estimateTemplate).State = EntityState.Modified;
@ -133,7 +133,7 @@ namespace Yavsc.Controllers
}
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (estimateTemplate.OwnerId!=uid)
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
return new StatusCodeResult(StatusCodes.Status403Forbidden);
_context.EstimateTemplates.Remove(estimateTemplate);

View file

@ -86,7 +86,7 @@ namespace Yavsc.ApiControllers
if (estimate is null) return NotFound(new { Error = "no estimate linked to this query" });
var uid = User.GetUserId();
if (!User.IsInRole(Constants.AdminGroupName)
if (!User.IsInRole(Constants.AdminName)
&& uid != estimate.ClientId && uid != estimate.OwnerId)
return Forbid();
@ -117,7 +117,7 @@ namespace Yavsc.ApiControllers
if (estimate is null) return NotFound(new { Error = "no estimate linked to this query" });
var uid = User.GetUserId();
if (!User.IsInRole(Constants.AdminGroupName)
if (!User.IsInRole(Constants.AdminName)
&& uid != estimate.ClientId && uid != estimate.OwnerId)
return Forbid();
@ -403,7 +403,7 @@ namespace Yavsc.ApiControllers
if (isProvider) return (query, ActorRole.Provider, null);
if (isClient) return (query, ActorRole.Client, null);
if (User.IsInRole(Constants.AdminGroupName))
if (User.IsInRole(Constants.AdminName))
return (query, ActorRole.Admin, null);
return (null, ActorRole.None, Forbid());
@ -453,7 +453,7 @@ namespace Yavsc.ApiControllers
if (error is not null) return error;
if (query is null) return BadRequest(new { Error = "query not found" });
if (role != ActorRole.Client && !User.IsInRole(Constants.AdminGroupName))
if (role != ActorRole.Client && !User.IsInRole(Constants.AdminName))
return new StatusCodeResult(StatusCodes.Status403Forbidden);
if (body == null || body.FileId <= 0)
@ -463,7 +463,7 @@ namespace Yavsc.ApiControllers
var file = await dbContext.UploadedFiles
.FirstOrDefaultAsync(f => f.Id == body.FileId, token);
if (file == null) return BadRequest(new { error = "file not found" });
if (file.OwnerId != uid && !User.IsInRole(Constants.AdminGroupName))
if (file.OwnerId != uid && !User.IsInRole(Constants.AdminName))
return new StatusCodeResult(StatusCodes.Status403Forbidden);
var existing = await dbContext.QueryAttachedFiles
@ -490,7 +490,7 @@ namespace Yavsc.ApiControllers
if (error is not null) return error;
if (query is null) return BadRequest(new { Error = "query not found" });
if (role != ActorRole.Client && !User.IsInRole(Constants.AdminGroupName))
if (role != ActorRole.Client && !User.IsInRole(Constants.AdminName))
return new StatusCodeResult(StatusCodes.Status403Forbidden);
var link = await dbContext.QueryAttachedFiles

View file

@ -70,7 +70,7 @@ public class HairCutQueryApiController : Controller
return NotFound();
}
if (query.ClientId != uid && query.PerformerId != uid && !User.IsInRole(Constants.AdminGroupName))
if (query.ClientId != uid && query.PerformerId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -141,7 +141,7 @@ public class HairCutQueryApiController : Controller
}
var uid = User.GetUserId();
if (existing.ClientId != uid && !User.IsInRole(Constants.AdminGroupName))
if (existing.ClientId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -185,7 +185,7 @@ public class HairCutQueryApiController : Controller
return NotFound();
}
if (query.ClientId != uid && !User.IsInRole(Constants.AdminGroupName))
if (query.ClientId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -234,4 +234,4 @@ public class HairCutQueryApiController : Controller
Details = prestation.GetDisplayDetails(),
};
}
}
}

View file

@ -77,7 +77,7 @@ public class HairMultiCutQueryApiController : Controller
return NotFound();
}
if (query.ClientId != uid && query.PerformerId != uid && !User.IsInRole(Constants.AdminGroupName))
if (query.ClientId != uid && query.PerformerId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -152,7 +152,7 @@ public class HairMultiCutQueryApiController : Controller
}
var uid = User.GetUserId();
if (existing.ClientId != uid && !User.IsInRole(Constants.AdminGroupName))
if (existing.ClientId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -200,7 +200,7 @@ public class HairMultiCutQueryApiController : Controller
return NotFound();
}
if (query.ClientId != uid && !User.IsInRole(Constants.AdminGroupName))
if (query.ClientId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -285,4 +285,4 @@ public class HairMultiCutQueryApiController : Controller
return query;
}
}
}

View file

@ -39,7 +39,7 @@ public sealed class InvoicesController(IInvoicingService invoices, ILogger<Invoi
public Task<ActionResult<InvoiceResponse>> VerifyPayPal(long commandId, VerifyInvoicePayPalRequest request, CancellationToken ct)
=> ExecuteAsync(() => invoices.VerifyPayPalAsync(commandId, request.TransactionId, User.GetUserId(), IsAdmin, ct));
private bool IsAdmin => User.IsInRole(Constants.AdminGroupName);
private bool IsAdmin => User.IsInRole(Constants.AdminName);
private async Task<ActionResult<InvoiceResponse>> ExecuteAsync(Func<Task<InvoiceResponse>> action, bool created = false)
{

View file

@ -62,7 +62,7 @@ public class RdvQueryApiController : Controller
return NotFound();
}
if (query.ClientId != uid && query.PerformerId != uid && !User.IsInRole(Constants.AdminGroupName))
if (query.ClientId != uid && query.PerformerId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -157,7 +157,7 @@ public class RdvQueryApiController : Controller
return NotFound();
}
if (existing.ClientId != uid && !User.IsInRole(Constants.AdminGroupName))
if (existing.ClientId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}
@ -222,7 +222,7 @@ public class RdvQueryApiController : Controller
return NotFound();
}
if (query.ClientId != uid && !User.IsInRole(Constants.AdminGroupName))
if (query.ClientId != uid && !User.IsInRole(Constants.AdminName))
{
return Forbid();
}

View file

@ -35,7 +35,7 @@ namespace Yavsc.Controllers
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (blogpost.AuthorId!=uid)
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
return BadRequest();
_context.SaveChanges(User.GetUserId());

View file

@ -49,7 +49,7 @@ namespace Yavsc.Controllers
{
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != blackListed.OwnerId)
if (!User.IsInRole(Constants.AdminGroupName))
if (!User.IsInRole(Constants.AdminName))
if (!User.IsInRole(Constants.FrontOfficeGroupName))
return false;
return true;

View file

@ -46,7 +46,7 @@ namespace Yavsc.Controllers
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
if (uid != chatRoomAccess.UserId && uid != chatRoomAccess.Room.OwnerId
&& ! User.IsInMsRole(Constants.AdminGroupName))
&& ! User.IsInMsRole(Constants.AdminName))
{
ModelState.AddModelError("UserId","get refused");
@ -72,7 +72,7 @@ namespace Yavsc.Controllers
}
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
if (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName))
if (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminName))
{
ModelState.AddModelError("ChannelName", "access put refused");
return BadRequest(ModelState);
@ -110,7 +110,7 @@ namespace Yavsc.Controllers
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminGroupName)))
if (room == null || (uid != room.OwnerId && ! User.IsInMsRole(Constants.AdminName)))
{
ModelState.AddModelError("ChannelName", "access post refused");
return BadRequest(ModelState);
@ -154,7 +154,7 @@ namespace Yavsc.Controllers
var uid = User.FindFirstValue(ClaimTypes.NameIdentifier);
var room = _context.ChatRoom.First(channel => channel.Name == chatRoomAccess.ChannelName );
if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(Constants.AdminGroupName)))
if (room == null || (uid != room.OwnerId && chatRoomAccess.UserId != uid && ! User.IsInMsRole(Constants.AdminName)))
{
ModelState.AddModelError("UserId", "access drop refused");
return BadRequest(ModelState);

View file

@ -136,7 +136,7 @@ namespace Yavsc.Controllers
if (User.GetUserId() != chatRoom.OwnerId )
{
if (!User.IsInMsRole(Constants.AdminGroupName))
if (!User.IsInMsRole(Constants.AdminName))
return BadRequest(new {error = "OwnerId"});
}