apply fix on Webinars Provider ...

This commit is contained in:
2025-11-06 07:12:31 +03:30
parent e5b7314f9b
commit 4c8b43a243
3 changed files with 206 additions and 130 deletions
+190 -34
View File
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
@@ -6,6 +7,7 @@ using Microsoft.Extensions.Logging;
using xCommons.Configurations;
using xCommons.Extensions;
using xCommons.Providers;
using xExceptions.Constants;
using xIdentityService.Controllers;
using xIdentityService.Interfaces;
using xModels.Dtos;
@@ -60,6 +62,19 @@ namespace xWebinarService.Controller
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Check Owner ...
if (item.OwnerId.IsNullOrEmpty())
{
item.OwnerId = userId;
}
//
var result = await WebinarProvider
.CreateWebinar(item);
@@ -90,6 +105,20 @@ namespace xWebinarService.Controller
// Do ...
try
{
//
// Retrieve User Info ...
var userInfo = await GetUserInfo();
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Check Permission ...
bool has = item.OwnerId == userId || isAdmin;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.UpdateWebinar(item);
@@ -208,16 +237,31 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has = entity.OwnerId == userId || isAdmin;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.RemoveWebinar(
webinarId: webinarId,
requesterUserSelectByParam: requesterId
);
.RemoveWebinar(webinarId);
//
return Ok(result.
@@ -251,16 +295,36 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has =
isAdmin ||
entity.OwnerId == userId ||
entity.Type == Constants.XWebinarType.Public;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.Subscribe(
webinarId: webinarId,
subscriberId: subscriberId,
requesterUserSelectByParam: requesterId
subscriberId: subscriberId
);
//
@@ -292,9 +356,29 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has =
isAdmin ||
entity.OwnerId == userId;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
@@ -332,16 +416,36 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has =
isAdmin ||
subscriberId == userId ||
entity.OwnerId == userId;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.Unsubscribe(
webinarId: webinarId,
subscriberId: subscriberId,
requesterUserSelectByParam: requesterId
subscriberId: subscriberId
);
//
@@ -365,7 +469,7 @@ namespace xWebinarService.Controller
[HttpGet("GetSubscriber")]
public virtual async Task<ActionResult<XWebinarSubscriberDto>> GetSubscriber(
[FromQuery] Guid webinarId,
[FromQuery] string subscriberId
[FromQuery] string subscriberId
)
{
//
@@ -373,16 +477,35 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has =
isAdmin ||
entity.OwnerId == userId;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.GetSubscriber(
webinarId: webinarId,
subscriberId: subscriberId,
requesterUserSelectByParam: requesterId
subscriberId: subscriberId
);
//
@@ -412,16 +535,33 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has =
isAdmin ||
entity.OwnerId == userId;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.GetSubscribers(
webinarId: webinarId,
requesterUserSelectByParam: requesterId
);
.GetSubscribers(webinarId);
//
return Ok(result.
@@ -452,16 +592,35 @@ namespace xWebinarService.Controller
try
{
//
// Retrieve UserInfo ...
// Retrieve User Info ...
var userInfo = await GetUserInfo();
var requesterId = userInfo.UserId;
bool isAdmin = userInfo.Roles.Any(r => r.ToNormalString() == "admin");
var userId = userInfo.UserId;
//
// Retrieve Entity ...
var entity = await WebinarProvider.GetWebinar(webinarId);
bool has = !entity.IsNullOrDefault();
if (!has)
{
XException.NotFound.Throw();
}
//
// Check Permissions ...
has =
isAdmin ||
entity.OwnerId == userId;
if (!has)
{
XException.NotAllowed.Throw();
}
//
var result = await WebinarProvider
.QuerySubscribers(
query: query,
webinarId: webinarId,
requesterUserSelectByParam: requesterId
webinarId: webinarId
);
//
@@ -476,8 +635,5 @@ namespace xWebinarService.Controller
}
}
#endregion
//
// Non Actions ...
}
}