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
+182 -26
View File
@@ -1,4 +1,5 @@
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
@@ -6,6 +7,7 @@ using Microsoft.Extensions.Logging;
using xCommons.Configurations; using xCommons.Configurations;
using xCommons.Extensions; using xCommons.Extensions;
using xCommons.Providers; using xCommons.Providers;
using xExceptions.Constants;
using xIdentityService.Controllers; using xIdentityService.Controllers;
using xIdentityService.Interfaces; using xIdentityService.Interfaces;
using xModels.Dtos; using xModels.Dtos;
@@ -60,6 +62,19 @@ namespace xWebinarService.Controller
// Do ... // Do ...
try 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 var result = await WebinarProvider
.CreateWebinar(item); .CreateWebinar(item);
@@ -90,6 +105,20 @@ namespace xWebinarService.Controller
// Do ... // Do ...
try 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 var result = await WebinarProvider
.UpdateWebinar(item); .UpdateWebinar(item);
@@ -210,14 +239,29 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
.RemoveWebinar( .RemoveWebinar(webinarId);
webinarId: webinarId,
requesterUserSelectByParam: requesterId
);
// //
return Ok(result. return Ok(result.
@@ -253,14 +297,34 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
.Subscribe( .Subscribe(
webinarId: webinarId, webinarId: webinarId,
subscriberId: subscriberId, subscriberId: subscriberId
requesterUserSelectByParam: requesterId
); );
// //
@@ -294,7 +358,27 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
@@ -334,14 +418,34 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
.Unsubscribe( .Unsubscribe(
webinarId: webinarId, webinarId: webinarId,
subscriberId: subscriberId, subscriberId: subscriberId
requesterUserSelectByParam: requesterId
); );
// //
@@ -375,14 +479,33 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
.GetSubscriber( .GetSubscriber(
webinarId: webinarId, webinarId: webinarId,
subscriberId: subscriberId, subscriberId: subscriberId
requesterUserSelectByParam: requesterId
); );
// //
@@ -414,14 +537,31 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
.GetSubscribers( .GetSubscribers(webinarId);
webinarId: webinarId,
requesterUserSelectByParam: requesterId
);
// //
return Ok(result. return Ok(result.
@@ -454,14 +594,33 @@ namespace xWebinarService.Controller
// //
// Retrieve User Info ... // Retrieve User Info ...
var userInfo = await GetUserInfo(); 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 var result = await WebinarProvider
.QuerySubscribers( .QuerySubscribers(
query: query, query: query,
webinarId: webinarId, webinarId: webinarId
requesterUserSelectByParam: requesterId
); );
// //
@@ -476,8 +635,5 @@ namespace xWebinarService.Controller
} }
} }
#endregion #endregion
//
// Non Actions ...
} }
} }
+6 -22
View File
@@ -80,12 +80,8 @@ namespace xWebinarService.Interfaces
/// Remove Specified Webinar ... /// Remove Specified Webinar ...
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> RemoveWebinar( Task<bool> RemoveWebinar(Guid webinarId);
Guid webinarId,
string requesterUserSelectByParam = null
);
#endregion #endregion
// //
@@ -95,12 +91,10 @@ namespace xWebinarService.Interfaces
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="subscriberId"></param> /// <param name="subscriberId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> Subscribe( Task<bool> Subscribe(
Guid webinarId, Guid webinarId,
string subscriberId, string subscriberId
string requesterUserSelectByParam = null
); );
/// <summary> /// <summary>
@@ -119,12 +113,10 @@ namespace xWebinarService.Interfaces
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="subscriberId"></param> /// <param name="subscriberId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
Task<bool> Unsubscribe( Task<bool> Unsubscribe(
Guid webinarId, Guid webinarId,
string subscriberId, string subscriberId
string requesterUserSelectByParam = null
); );
/// <summary> /// <summary>
@@ -132,36 +124,28 @@ namespace xWebinarService.Interfaces
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="subscriberId"></param> /// <param name="subscriberId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
Task<XWebinarSubscriberDto> GetSubscriber( Task<XWebinarSubscriberDto> GetSubscriber(
Guid webinarId, Guid webinarId,
string subscriberId, string subscriberId
string requesterUserSelectByParam = null
); );
/// <summary> /// <summary>
/// Get all Specified Webinars Subscribers ... /// Get all Specified Webinars Subscribers ...
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
Task<IEnumerable<XWebinarSubscriberDto>> GetSubscribers( Task<IEnumerable<XWebinarSubscriberDto>> GetSubscribers(Guid webinarId);
Guid webinarId,
string requesterUserSelectByParam = null
);
/// <summary> /// <summary>
/// Query Specified Webinar's Subscribers ... /// Query Specified Webinar's Subscribers ...
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="query"></param> /// <param name="query"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
Task<XQueryResult<XWebinarSubscriberDto>> QuerySubscribers( Task<XQueryResult<XWebinarSubscriberDto>> QuerySubscribers(
Guid webinarId, Guid webinarId,
XQuery query, XQuery query
string requesterUserSelectByParam = null
); );
#endregion #endregion
} }
+10 -74
View File
@@ -522,11 +522,9 @@ namespace xWebinarService.Providers
/// Remove Specified Webinar ... /// Remove Specified Webinar ...
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
public async Task<bool> RemoveWebinar( public async Task<bool> RemoveWebinar(
Guid webinarId, Guid webinarId
string requesterUserSelectByParam = null
) )
{ {
// //
@@ -551,27 +549,17 @@ namespace xWebinarService.Providers
return result; return result;
} }
//
// Check Permissions ...
result = entity.OwnerId == requesterUserSelectByParam;
if (!result)
{
return result;
}
// //
// Handle Remove ... // Handle Remove ...
var subscribers = await GetSubscribers( var subscribers = await GetSubscribers(
webinarId: webinarId, webinarId: webinarId
requesterUserSelectByParam: requesterUserSelectByParam
); );
try try
{ {
// //
await subscribers.SelectAsync(async s => await Unsubscribe( await subscribers.SelectAsync(async s => await Unsubscribe(
webinarId: webinarId, webinarId: webinarId,
subscriberId: s.SubscriberId, subscriberId: s.SubscriberId
requesterUserSelectByParam: requesterUserSelectByParam
)); ));
// //
@@ -600,12 +588,10 @@ namespace xWebinarService.Providers
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="subscriberId"></param> /// <param name="subscriberId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
public async Task<bool> Subscribe( public async Task<bool> Subscribe(
Guid webinarId, Guid webinarId,
string subscriberId, string subscriberId
string requesterUserSelectByParam = null
) )
{ {
// //
@@ -636,19 +622,7 @@ namespace xWebinarService.Providers
// //
// Check Webinar Enabled ... // Check Webinar Enabled ...
result = result = webinar.Enabled;
webinar.Enabled ||
requesterUserSelectByParam == webinar.OwnerId;
if (!result)
{
return result;
}
//
// Check Webinar Type ...
result =
webinar.Type == XWebinarType.Public ||
requesterUserSelectByParam == webinar.OwnerId;
if (!result) if (!result)
{ {
return result; return result;
@@ -755,12 +729,10 @@ namespace xWebinarService.Providers
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="subscriberId"></param> /// <param name="subscriberId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
public async Task<bool> Unsubscribe( public async Task<bool> Unsubscribe(
Guid webinarId, Guid webinarId,
string subscriberId, string subscriberId
string requesterUserSelectByParam = null
) )
{ {
// //
@@ -792,16 +764,6 @@ namespace xWebinarService.Providers
// Retrieve Webinar ... // Retrieve Webinar ...
var webinar = await WebinarRepository.GetAsync(webinarId); var webinar = await WebinarRepository.GetAsync(webinarId);
//
// Check Permission ...
result =
requesterUserSelectByParam == subscriberId ||
requesterUserSelectByParam == webinar.OwnerId;
if (!result)
{
return result;
}
// //
// Retrieve Subscription Entity ... // Retrieve Subscription Entity ...
var entity = await WebinarSubscriberRepository.FindOneAsync(ws => var entity = await WebinarSubscriberRepository.FindOneAsync(ws =>
@@ -820,12 +782,10 @@ namespace xWebinarService.Providers
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="subscriberId"></param> /// <param name="subscriberId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
public async Task<XWebinarSubscriberDto> GetSubscriber( public async Task<XWebinarSubscriberDto> GetSubscriber(
Guid webinarId, Guid webinarId,
string subscriberId, string subscriberId
string requesterUserSelectByParam = null
) )
{ {
// //
@@ -860,16 +820,6 @@ namespace xWebinarService.Providers
XException.NotFound.Throw(); XException.NotFound.Throw();
} }
//
// Check Permissions ...
isValid =
subscriberId == requesterUserSelectByParam ||
webinar.OwnerId == requesterUserSelectByParam;
if (!isValid)
{
XException.NotAllowed.Throw();
}
// //
// Converts to Subscriber Dto ... // Converts to Subscriber Dto ...
var result = await ToXWebinarSubscriberDto(entity); var result = await ToXWebinarSubscriberDto(entity);
@@ -880,11 +830,9 @@ namespace xWebinarService.Providers
/// Get all Specified Webinars Subscribers ... /// Get all Specified Webinars Subscribers ...
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
public async Task<IEnumerable<XWebinarSubscriberDto>> GetSubscribers( public async Task<IEnumerable<XWebinarSubscriberDto>> GetSubscribers(
Guid webinarId, Guid webinarId
string requesterUserSelectByParam = null
) )
{ {
// //
@@ -906,15 +854,6 @@ namespace xWebinarService.Providers
XException.NotFound.Throw(); XException.NotFound.Throw();
} }
//
// Check Permissions ...
isValid =
webinar.OwnerId == requesterUserSelectByParam;
if (!isValid)
{
XException.NotAllowed.Throw();
}
// //
var subscribers = await WebinarSubscriberRepository.FindManyAsync(e => var subscribers = await WebinarSubscriberRepository.FindManyAsync(e =>
e.WebinarId == webinarId e.WebinarId == webinarId
@@ -934,12 +873,10 @@ namespace xWebinarService.Providers
/// </summary> /// </summary>
/// <param name="webinarId"></param> /// <param name="webinarId"></param>
/// <param name="query"></param> /// <param name="query"></param>
/// <param name="requesterUserSelectByParam"></param>
/// <returns></returns> /// <returns></returns>
public async Task<XQueryResult<XWebinarSubscriberDto>> QuerySubscribers( public async Task<XQueryResult<XWebinarSubscriberDto>> QuerySubscribers(
Guid webinarId, Guid webinarId,
XQuery query, XQuery query
string requesterUserSelectByParam = null
) )
{ {
// //
@@ -968,8 +905,7 @@ namespace xWebinarService.Providers
// //
// Retrieve all Items ... // Retrieve all Items ...
var items = await GetSubscribers( var items = await GetSubscribers(
webinarId: webinarId, webinarId: webinarId
requesterUserSelectByParam: requesterUserSelectByParam
); );
var totalItemsCount = items.Count(); var totalItemsCount = items.Count();