last ...
This commit is contained in:
@@ -1,86 +1,86 @@
|
||||
// using System.Threading;
|
||||
// using xCommons.Extensions;
|
||||
// using xIdentityModels.Dtos;
|
||||
// using xExceptions.Constants;
|
||||
// using System.Threading.Tasks;
|
||||
// using xIdentityModels.Models;
|
||||
using System.Threading;
|
||||
using xCommons.Extensions;
|
||||
using xIdentityModels.Dtos;
|
||||
using xExceptions.Constants;
|
||||
using System.Threading.Tasks;
|
||||
using xIdentityModels.Models;
|
||||
|
||||
// namespace xIdentityService.Providers
|
||||
// {
|
||||
// public partial class XAuthorizationProvider
|
||||
// {
|
||||
// //
|
||||
// #region Policy ...
|
||||
// public async Task<XPolicyDefinitionDto> AddPolicyAsync(
|
||||
// XPolicyDefinitionDto item,
|
||||
// XUserClaimsInfoDto userInfo,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// // Validate ...
|
||||
// if (item.IsNull() || item.Name.IsNullOrEmpty())
|
||||
// {
|
||||
// XException.InvalidArgs.Throw();
|
||||
// }
|
||||
namespace xIdentityService.Providers
|
||||
{
|
||||
public partial class XAuthorizationProvider
|
||||
{
|
||||
//
|
||||
#region Policy ...
|
||||
public async Task<XPolicyDefinitionDto> AddPolicyAsync(
|
||||
XPolicyDefinitionDto item,
|
||||
XUserClaimsInfoDto userInfo,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
// Validate ...
|
||||
if (item.IsNull() || item.Name.IsNullOrEmpty())
|
||||
{
|
||||
XException.InvalidArgs.Throw();
|
||||
}
|
||||
|
||||
// //
|
||||
// var normalized = item.Name.ToNormalString();
|
||||
// var exists = await policies.FindOneAsync(
|
||||
// predicate: p => p.Name.ToLower() == normalized,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
// if (!exists.IsNull())
|
||||
// {
|
||||
// XException.Duplicate.Throw();
|
||||
// }
|
||||
//
|
||||
var normalized = item.Name.ToNormalString();
|
||||
var exists = await policies.FindOneAsync(
|
||||
predicate: p => p.Name.ToLower() == normalized,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
if (!exists.IsNull())
|
||||
{
|
||||
XException.Duplicate.Throw();
|
||||
}
|
||||
|
||||
// //
|
||||
// await ValidateReferencesAsync(item, cancellationToken);
|
||||
//
|
||||
await ValidateReferencesAsync(item, cancellationToken);
|
||||
|
||||
// //
|
||||
// item.IsSystem = false;
|
||||
//
|
||||
item.IsSystem = false;
|
||||
|
||||
// //
|
||||
// var result = await policies.AddAsync(
|
||||
// item: item,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
//
|
||||
var result = await policies.AddAsync(
|
||||
item: item,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
// //
|
||||
// await InvalidateAsync(result.Name);
|
||||
//
|
||||
await InvalidateAsync(result.Name);
|
||||
|
||||
// //
|
||||
// return await ToDtoWithEffectiveRolesAsync(result, cancellationToken);
|
||||
// }
|
||||
//
|
||||
return await ToDtoWithEffectiveRolesAsync(result, cancellationToken);
|
||||
}
|
||||
|
||||
// public async Task<bool> RemovePolicyAsync(
|
||||
// string name,
|
||||
// XUserClaimsInfoDto userInfo,
|
||||
// CancellationToken cancellationToken = default
|
||||
// )
|
||||
// {
|
||||
// //
|
||||
// var entity = await FindPolicyOrThrowAsync(name, cancellationToken);
|
||||
// if (entity.IsSystem)
|
||||
// {
|
||||
// XException.NotAllowed.Throw();
|
||||
// }
|
||||
public async Task<bool> RemovePolicyAsync(
|
||||
string name,
|
||||
XUserClaimsInfoDto userInfo,
|
||||
CancellationToken cancellationToken = default
|
||||
)
|
||||
{
|
||||
//
|
||||
var entity = await FindPolicyOrThrowAsync(name, cancellationToken);
|
||||
if (entity.IsSystem)
|
||||
{
|
||||
XException.NotAllowed.Throw();
|
||||
}
|
||||
|
||||
// //
|
||||
// await policies.RemoveAsync(
|
||||
// id: entity.Id,
|
||||
// cancellationToken: cancellationToken
|
||||
// );
|
||||
//
|
||||
await policies.RemoveAsync(
|
||||
id: entity.Id,
|
||||
cancellationToken: cancellationToken
|
||||
);
|
||||
|
||||
// //
|
||||
// await InvalidateAsync(entity.Name);
|
||||
// return true;
|
||||
// }
|
||||
// #endregion
|
||||
//
|
||||
await InvalidateAsync(entity.Name);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
// //
|
||||
// #region Private ...
|
||||
// #endregion
|
||||
// }
|
||||
// }
|
||||
//
|
||||
#region Private ...
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user