More refactoring and more work towards implementing the workflowtemplate controller
This commit is contained in:
parent
500dafe7a2
commit
17aea93370
@ -12,4 +12,5 @@ public interface ISsoManager
|
|||||||
Task AddSsoProviderAsync(AuditUserDetails auditUserDetails, CreateSsoProvider ssoProvider, CancellationToken cancellationToken);
|
Task AddSsoProviderAsync(AuditUserDetails auditUserDetails, CreateSsoProvider ssoProvider, CancellationToken cancellationToken);
|
||||||
Task EditSsoProviderAsync(AuditUserDetails auditUserDetails, EditSsoProvider ssoProvider, CancellationToken cancellationToken);
|
Task EditSsoProviderAsync(AuditUserDetails auditUserDetails, EditSsoProvider ssoProvider, CancellationToken cancellationToken);
|
||||||
Task RemoveSsoProviderAsync( AuditUserDetails auditUserDetails, IGeneralIdRef generalIdRef, CancellationToken cancellationToken);
|
Task RemoveSsoProviderAsync( AuditUserDetails auditUserDetails, IGeneralIdRef generalIdRef, CancellationToken cancellationToken);
|
||||||
|
Task PatchSsoProviderAsync(AuditUserDetails auditUserDetails, GeneralIdRef generalIdRef, PatchSsoProvider patchSsoProvider, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
@ -1,6 +1,113 @@
|
|||||||
namespace e_suite.API.Common;
|
using e_suite.Database.Audit;
|
||||||
|
using e_suite.Database.Core.Extensions;
|
||||||
|
using e_suite.Database.Core.Models;
|
||||||
|
using e_suite.Database.Core.Tables.Workflow;
|
||||||
|
using e_suite.Utilities.Pagination;
|
||||||
|
using eSuite.Core.Miscellaneous;
|
||||||
|
|
||||||
|
namespace e_suite.API.Common;
|
||||||
|
|
||||||
|
public class GetWorkflowTemplate : IGeneralId
|
||||||
|
{
|
||||||
|
public GetWorkflowTemplate()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public GetWorkflowTemplate(WorkflowVersion workflowVersion)
|
||||||
|
{
|
||||||
|
Id = workflowVersion.Id;
|
||||||
|
Guid = workflowVersion.Guid;
|
||||||
|
Deleted = workflowVersion.Deleted;
|
||||||
|
ActivityNameTemplate = workflowVersion.ActivityNameTemplate;
|
||||||
|
Description = workflowVersion.Description;
|
||||||
|
DomainId = workflowVersion.Domain.ToGeneralIdRef();
|
||||||
|
LastUpdated = workflowVersion.LastUpdated;
|
||||||
|
Version = workflowVersion.Version;
|
||||||
|
WorkflowId = workflowVersion.Workflow.ToGeneralIdRef();
|
||||||
|
WorkflowName = workflowVersion.Workflow.Name;
|
||||||
|
Tasks = workflowVersion.Tasks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<TaskDefinition> Tasks { get; set; }
|
||||||
|
|
||||||
|
public string WorkflowName { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? WorkflowId { get; set; }
|
||||||
|
|
||||||
|
public long Version { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset LastUpdated { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? DomainId { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public string ActivityNameTemplate { get; set; }
|
||||||
|
|
||||||
|
public bool Deleted { get; set; }
|
||||||
|
|
||||||
|
public long Id { get; set; }
|
||||||
|
public Guid Guid { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class EditWorkflowTemplate : IGeneralId
|
||||||
|
{
|
||||||
|
public long Id { get; set; }
|
||||||
|
public Guid Guid { get; set; }
|
||||||
|
|
||||||
|
public string WorkflowName { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? WorkflowId { get; set; }
|
||||||
|
|
||||||
|
public long Version { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? DomainId { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public string ActivityNameTemplate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PatchWorkflowTemplate
|
||||||
|
{
|
||||||
|
|
||||||
|
public string? WorkflowName { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? DomainId { get; set; }
|
||||||
|
|
||||||
|
public string? Description { get; set; }
|
||||||
|
|
||||||
|
public string? ActivityNameTemplate { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CreateWorkflowTemplate
|
||||||
|
{
|
||||||
|
public List<TaskDefinition> Tasks { get; set; }
|
||||||
|
|
||||||
|
public string WorkflowName { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? WorkflowId { get; set; }
|
||||||
|
|
||||||
|
public long Version { get; set; }
|
||||||
|
|
||||||
|
public DateTimeOffset LastUpdated { get; set; }
|
||||||
|
|
||||||
|
public GeneralIdRef? DomainId { get; set; }
|
||||||
|
|
||||||
|
public string Description { get; set; }
|
||||||
|
|
||||||
|
public string ActivityNameTemplate { get; set; }
|
||||||
|
|
||||||
|
public bool Deleted { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
public interface IWorkflowTemplateManager
|
public interface IWorkflowTemplateManager
|
||||||
{
|
{
|
||||||
|
Task<PaginatedData<GetWorkflowTemplate>> GetWorkflowTemplatesAsync(Paging paging, CancellationToken cancellationToken);
|
||||||
|
Task<GetWorkflowTemplate?> GetWorkflowTemplateAsync(GeneralIdRef generalIdRef, CancellationToken cancellationToken);
|
||||||
|
Task EditTemplate(AuditUserDetails auditUserDetails, EditWorkflowTemplate template, CancellationToken cancellationToken);
|
||||||
|
Task PatchTemplate(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, PatchWorkflowTemplate patchTemplate, CancellationToken cancellationToken);
|
||||||
|
Task PostTemplate(AuditUserDetails auditUserDetails, CreateWorkflowTemplate template, CancellationToken cancellationToken);
|
||||||
|
Task DeleteTemplate(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
namespace e_suite.API.Common.models;
|
||||||
|
|
||||||
|
public class PatchSsoProvider
|
||||||
|
{
|
||||||
|
public string? Name { get; set; }
|
||||||
|
|
||||||
|
public string? ClientId { get; set; }
|
||||||
|
|
||||||
|
public string? ClientSecret { get; set; }
|
||||||
|
|
||||||
|
public string? ValidIssuer { get; set; }
|
||||||
|
|
||||||
|
public string? AuthorizationEndpoint { get; set; }
|
||||||
|
|
||||||
|
public string? TokenEndpoint { get; set; }
|
||||||
|
|
||||||
|
public bool? IsPublic { get; set; }
|
||||||
|
}
|
||||||
@ -1,10 +1,29 @@
|
|||||||
using e_suite.API.Common.models.@base;
|
using e_suite.API.Common.models.@base;
|
||||||
using e_suite.Database.Core.Models;
|
using e_suite.Database.Core.Models;
|
||||||
|
using e_suite.Database.Core.Tables.UserManager;
|
||||||
|
|
||||||
namespace e_suite.API.Common.models;
|
namespace e_suite.API.Common.models;
|
||||||
|
|
||||||
public class ReadSsoProvider : SsoProviderBase, IGeneralId
|
public class ReadSsoProvider : SsoProviderBase, IGeneralId
|
||||||
{
|
{
|
||||||
|
public ReadSsoProvider()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadSsoProvider(SsoProvider ssoProvider)
|
||||||
|
{
|
||||||
|
Id = ssoProvider.Id;
|
||||||
|
AuthorizationEndpoint = ssoProvider.AuthorizationEndpoint;
|
||||||
|
ClientId = ssoProvider.ClientId;
|
||||||
|
ClientSecret = ssoProvider.ClientSecret;
|
||||||
|
IsPublic = ssoProvider.IsPublic;
|
||||||
|
Name = ssoProvider.Name;
|
||||||
|
TokenEndpoint = ssoProvider.TokenEndpoint;
|
||||||
|
ValidIssuer = ssoProvider.ValidIssuer;
|
||||||
|
Guid = ssoProvider.Guid;
|
||||||
|
}
|
||||||
|
|
||||||
public long Id { get; set; }
|
public long Id { get; set; }
|
||||||
public Guid Guid { get; set; }
|
public Guid Guid { get; set; }
|
||||||
}
|
}
|
||||||
@ -1,8 +1,11 @@
|
|||||||
using e_suite.Database.Core;
|
using e_suite.Database.Audit;
|
||||||
|
using e_suite.Database.Core;
|
||||||
|
using e_suite.Database.Core.Tables.Workflow;
|
||||||
|
|
||||||
namespace e_suite.API.Common.repository;
|
namespace e_suite.API.Common.repository;
|
||||||
|
|
||||||
public interface IWorkflowTemplateRepository : IRepository
|
public interface IWorkflowTemplateRepository : IRepository
|
||||||
{
|
{
|
||||||
|
IQueryable<WorkflowVersion> GetWorkflowVersions();
|
||||||
|
Task EditWorkflowVersionAsync(AuditUserDetails auditUserDetails, WorkflowVersion workflowVersion, CancellationToken cancellationToken);
|
||||||
}
|
}
|
||||||
@ -101,6 +101,26 @@ public class SsoManagerController : ESuiteControllerBase
|
|||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Edit SsoProvider
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="editedSsoProvider"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[Route("ssoProvider")]
|
||||||
|
[HttpPatch]
|
||||||
|
[AccessKey(SecurityAccess.EditSsoProvider)]
|
||||||
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
|
public async Task<IActionResult> PatchSsoProvider(
|
||||||
|
[FromQuery] GeneralIdRef generalIdRef,
|
||||||
|
[FromBody] PatchSsoProvider patchSsoProvider,
|
||||||
|
CancellationToken cancellationToken = default!
|
||||||
|
)
|
||||||
|
{
|
||||||
|
await _ssoManager.PatchSsoProviderAsync(AuditUserDetails, generalIdRef, patchSsoProvider, cancellationToken);
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete SsoProvider
|
/// Delete SsoProvider
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
using e_suite.API.Common.models;
|
using e_suite.API.Common;
|
||||||
|
using e_suite.API.Common.models;
|
||||||
|
using e_suite.Database.Core.Tables.UserManager;
|
||||||
|
using e_suite.Modules.SSOManager;
|
||||||
using e_suite.Utilities.Pagination;
|
using e_suite.Utilities.Pagination;
|
||||||
using eSuite.API.Models;
|
using eSuite.API.Models;
|
||||||
using eSuite.API.security;
|
using eSuite.API.security;
|
||||||
@ -6,6 +9,7 @@ using eSuite.API.Utilities;
|
|||||||
using eSuite.Core.Miscellaneous;
|
using eSuite.Core.Miscellaneous;
|
||||||
using eSuite.Core.Security;
|
using eSuite.Core.Security;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Net.NetworkInformation;
|
||||||
|
|
||||||
namespace eSuite.API.Controllers;
|
namespace eSuite.API.Controllers;
|
||||||
|
|
||||||
@ -16,6 +20,13 @@ namespace eSuite.API.Controllers;
|
|||||||
[ApiController]
|
[ApiController]
|
||||||
public class WorkflowTemplateController : ESuiteControllerBase
|
public class WorkflowTemplateController : ESuiteControllerBase
|
||||||
{
|
{
|
||||||
|
private readonly IWorkflowTemplateManager _workflowTemplateManager;
|
||||||
|
|
||||||
|
public WorkflowTemplateController(IWorkflowTemplateManager workflowTemplateManager)
|
||||||
|
{
|
||||||
|
_workflowTemplateManager = workflowTemplateManager;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a list of workflow templates
|
/// Get a list of workflow templates
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -28,7 +39,8 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GetWorkflowTemplates([FromQuery] Paging paging,CancellationToken cancellationToken = default!)
|
public async Task<IActionResult> GetWorkflowTemplates([FromQuery] Paging paging,CancellationToken cancellationToken = default!)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var result = await _workflowTemplateManager.GetWorkflowTemplatesAsync(paging, cancellationToken);
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -43,12 +55,13 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||||
public async Task<IActionResult> GetUser(
|
public async Task<IActionResult> GetWorkflowTemplate(
|
||||||
[FromQuery] GeneralIdRef generalIdRef,
|
[FromQuery] GeneralIdRef generalIdRef,
|
||||||
CancellationToken cancellationToken = default!
|
CancellationToken cancellationToken = default!
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
var result = await _workflowTemplateManager.GetWorkflowTemplateAsync(generalIdRef, cancellationToken);
|
||||||
|
return Ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -62,9 +75,10 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[AccessKey(SecurityAccess.EditWorkflowTemplate)]
|
[AccessKey(SecurityAccess.EditWorkflowTemplate)]
|
||||||
public async Task<IActionResult> EditTemplate(EditUser template, CancellationToken cancellationToken = default!)
|
public async Task<IActionResult> EditTemplate(EditWorkflowTemplate template, CancellationToken cancellationToken = default!)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
await _workflowTemplateManager.EditTemplate(AuditUserDetails, template, cancellationToken);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -78,9 +92,10 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||||
[AccessKey(SecurityAccess.EditWorkflowTemplate)]
|
[AccessKey(SecurityAccess.EditWorkflowTemplate)]
|
||||||
public async Task<IActionResult> PatchUser([FromQuery] IGeneralIdRef templateId, [FromBody] PatchUser patchTemplate, CancellationToken cancellationToken = default!)
|
public async Task<IActionResult> PatchWorkflowTemplate([FromQuery] IGeneralIdRef templateId, [FromBody] PatchWorkflowTemplate patchTemplate, CancellationToken cancellationToken = default!)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
await _workflowTemplateManager.PatchTemplate(AuditUserDetails, templateId, patchTemplate, cancellationToken);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -95,12 +110,13 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
|
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
|
||||||
[AccessKey(SecurityAccess.AddWorkflowTemplate)]
|
[AccessKey(SecurityAccess.AddWorkflowTemplate)]
|
||||||
public async Task<IActionResult> CreateUser(
|
public async Task<IActionResult> CreateWorkflowTemplate(
|
||||||
[FromBody] UserRegistration userRegistration,
|
[FromBody] CreateWorkflowTemplate template,
|
||||||
CancellationToken cancellationToken = default!
|
CancellationToken cancellationToken = default!
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
await _workflowTemplateManager.PostTemplate(AuditUserDetails, template, cancellationToken);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -114,11 +130,12 @@ public class WorkflowTemplateController : ESuiteControllerBase
|
|||||||
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
|
[ProducesResponseType(StatusCodes.Status404NotFound, Type = typeof(ProblemDetails))]
|
||||||
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
|
[ProducesResponseType(StatusCodes.Status400BadRequest, Type = typeof(ProblemDetails))]
|
||||||
[AccessKey(SecurityAccess.DeleteWorkflowTemplate)]
|
[AccessKey(SecurityAccess.DeleteWorkflowTemplate)]
|
||||||
public async Task<IActionResult> DeactivateUser(
|
public async Task<IActionResult> DeleteWorkflowTemplate(
|
||||||
[FromBody] EmailAddress email,
|
[FromBody] IGeneralIdRef templateId,
|
||||||
CancellationToken cancellationToken = default!
|
CancellationToken cancellationToken = default!
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
await _workflowTemplateManager.DeleteTemplate(AuditUserDetails, templateId, cancellationToken);
|
||||||
|
return Ok();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,13 +1,17 @@
|
|||||||
using e_suite.API.Common;
|
using e_suite.API.Common;
|
||||||
using e_suite.Database.Audit;
|
using e_suite.Database.Audit;
|
||||||
using e_suite.UnitTestCore;
|
using e_suite.UnitTestCore;
|
||||||
|
using Moq;
|
||||||
|
|
||||||
namespace SSOManager.UnitTests.Helpers;
|
namespace SSOManager.UnitTests.Helpers;
|
||||||
|
|
||||||
public class SsoManagerTestBase : TestBase
|
public class SsoManagerTestBase<T> : TestBase
|
||||||
{
|
{
|
||||||
protected FakeSsoManagerRepository SsoManagerRepository = null!;
|
protected FakeSsoManagerRepository SsoManagerRepository = null!;
|
||||||
|
|
||||||
|
public Mock<IPatchFactory> PatchFactoryMock = null!;
|
||||||
|
public Mock<IPatch<T>> PatchMock { get; set; }
|
||||||
|
|
||||||
protected AuditUserDetails AuditUserDetails = null!;
|
protected AuditUserDetails AuditUserDetails = null!;
|
||||||
|
|
||||||
protected ISsoManager SsoManager = null!;
|
protected ISsoManager SsoManager = null!;
|
||||||
@ -23,8 +27,14 @@ public class SsoManagerTestBase : TestBase
|
|||||||
Comment = "Test comment"
|
Comment = "Test comment"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
PatchFactoryMock = new Mock<IPatchFactory>();
|
||||||
|
PatchMock = new Mock<IPatch<T>>();
|
||||||
|
PatchFactoryMock
|
||||||
|
.Setup(f => f.Create(It.IsAny<T>()))
|
||||||
|
.Returns(PatchMock.Object);
|
||||||
|
|
||||||
SsoManagerRepository = new FakeSsoManagerRepository();
|
SsoManagerRepository = new FakeSsoManagerRepository();
|
||||||
|
|
||||||
SsoManager = new e_suite.Modules.SSOManager.SsoManager(SsoManagerRepository);
|
SsoManager = new e_suite.Modules.SSOManager.SsoManager(SsoManagerRepository, PatchFactoryMock.Object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6,7 +6,7 @@ using SSOManager.UnitTests.Helpers;
|
|||||||
namespace SSOManager.UnitTests.SsoManager;
|
namespace SSOManager.UnitTests.SsoManager;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class AddSsoProviderAsyncUnitTests : SsoManagerTestBase
|
public class AddSsoProviderAsyncUnitTests : SsoManagerTestBase<object>
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public override async Task Setup()
|
public override async Task Setup()
|
||||||
|
|||||||
@ -8,7 +8,7 @@ using SSOManager.UnitTests.Helpers;
|
|||||||
namespace SSOManager.UnitTests.SsoManager;
|
namespace SSOManager.UnitTests.SsoManager;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class EditSsoProviderAsyncUnitTests : SsoManagerTestBase
|
public class EditSsoProviderAsyncUnitTests : SsoManagerTestBase<object>
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public override async Task Setup()
|
public override async Task Setup()
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using SSOManager.UnitTests.Helpers;
|
|||||||
namespace SSOManager.UnitTests.SsoManager;
|
namespace SSOManager.UnitTests.SsoManager;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class GetSsoProviderAsyncUnitTests : SsoManagerTestBase
|
public class GetSsoProviderAsyncUnitTests : SsoManagerTestBase<object>
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public override async Task Setup()
|
public override async Task Setup()
|
||||||
|
|||||||
@ -5,7 +5,7 @@ using SSOManager.UnitTests.Helpers;
|
|||||||
namespace SSOManager.UnitTests.SsoManager;
|
namespace SSOManager.UnitTests.SsoManager;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class GetSsoProvidersAsyncUnitTests : SsoManagerTestBase
|
public class GetSsoProvidersAsyncUnitTests : SsoManagerTestBase<object>
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public override async Task Setup()
|
public override async Task Setup()
|
||||||
|
|||||||
@ -7,7 +7,7 @@ using SSOManager.UnitTests.Helpers;
|
|||||||
namespace SSOManager.UnitTests.SsoManager;
|
namespace SSOManager.UnitTests.SsoManager;
|
||||||
|
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class RemoveSsoProviderAsyncUnitTests : SsoManagerTestBase
|
public class RemoveSsoProviderAsyncUnitTests : SsoManagerTestBase<object>
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public override async Task Setup()
|
public override async Task Setup()
|
||||||
|
|||||||
@ -1,66 +1,44 @@
|
|||||||
using e_suite.Database.Audit;
|
using e_suite.API.Common;
|
||||||
|
using e_suite.API.Common.exceptions;
|
||||||
|
using e_suite.API.Common.models;
|
||||||
|
using e_suite.API.Common.repository;
|
||||||
|
using e_suite.Database.Audit;
|
||||||
|
using e_suite.Database.Core.Extensions;
|
||||||
using e_suite.Database.Core.Tables.UserManager;
|
using e_suite.Database.Core.Tables.UserManager;
|
||||||
using e_suite.Utilities.Pagination;
|
using e_suite.Utilities.Pagination;
|
||||||
using eSuite.Core.Miscellaneous;
|
using eSuite.Core.Miscellaneous;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using e_suite.API.Common;
|
|
||||||
using e_suite.API.Common.exceptions;
|
|
||||||
using e_suite.API.Common.models;
|
|
||||||
using e_suite.API.Common.repository;
|
|
||||||
using e_suite.Database.Core.Extensions;
|
|
||||||
|
|
||||||
namespace e_suite.Modules.SSOManager;
|
namespace e_suite.Modules.SSOManager;
|
||||||
|
|
||||||
public class SsoManager : ISsoManager
|
public class SsoManager : ISsoManager
|
||||||
{
|
{
|
||||||
private readonly ISsoManagerRepository _ssoManagerRepository;
|
private readonly ISsoManagerRepository _ssoManagerRepository;
|
||||||
|
private readonly IPatchFactory _patchFactory;
|
||||||
|
|
||||||
public SsoManager(ISsoManagerRepository ssoManagerRepository)
|
public SsoManager(ISsoManagerRepository ssoManagerRepository, IPatchFactory patchFactory)
|
||||||
{
|
{
|
||||||
_ssoManagerRepository = ssoManagerRepository;
|
_ssoManagerRepository = ssoManagerRepository;
|
||||||
|
_patchFactory = patchFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IPaginatedData<ReadSsoProvider>> GetSsoProvidersAsync(Paging paging, CancellationToken cancellationToken)
|
public async Task<IPaginatedData<ReadSsoProvider>> GetSsoProvidersAsync(Paging paging, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var ssoProviders = _ssoManagerRepository.GetSsoProviders().Where(x => x.Deleted == false);
|
var ssoProviders = _ssoManagerRepository.GetSsoProviders().Where(x => x.Deleted == false);
|
||||||
|
|
||||||
var paginatedData = await PaginatedData.Paginate(ssoProviders, paging,
|
var paginatedData = await PaginatedData.Paginate<SsoProvider, ReadSsoProvider>(ssoProviders, paging,
|
||||||
KeySelector, cancellationToken);
|
KeySelector, cancellationToken);
|
||||||
|
|
||||||
var paginatedResult = new PaginatedData<ReadSsoProvider>
|
return paginatedData;
|
||||||
{
|
|
||||||
Count = paginatedData.Count,
|
|
||||||
Page = paginatedData.Page,
|
|
||||||
PageSize = paginatedData.PageSize,
|
|
||||||
Data = paginatedData.Data.Select(MapSsoProvider)
|
|
||||||
};
|
|
||||||
return paginatedResult;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<ReadSsoProvider> GetSsoProviderAsync( IGeneralIdRef generalIdRef, CancellationToken cancellationToken )
|
public async Task<ReadSsoProvider> GetSsoProviderAsync( IGeneralIdRef generalIdRef, CancellationToken cancellationToken )
|
||||||
{
|
{
|
||||||
var ssoProvider = await _ssoManagerRepository.GetSsoProviders().FindByGeneralIdRefAsync(generalIdRef, cancellationToken)
|
var ssoProvider = await _ssoManagerRepository.GetSsoProviders().FindByGeneralIdRefAsync(generalIdRef, cancellationToken)
|
||||||
?? throw new NotFoundException("Unable to find SsoProvider");
|
?? throw new NotFoundException("Unable to find SsoProvider");
|
||||||
return MapSsoProvider(ssoProvider);
|
return new ReadSsoProvider(ssoProvider);
|
||||||
}
|
|
||||||
|
|
||||||
private ReadSsoProvider MapSsoProvider(SsoProvider ssoProvider)
|
|
||||||
{
|
|
||||||
var readSsoProvider = new ReadSsoProvider
|
|
||||||
{
|
|
||||||
Id = ssoProvider.Id,
|
|
||||||
AuthorizationEndpoint = ssoProvider.AuthorizationEndpoint,
|
|
||||||
ClientId = ssoProvider.ClientId,
|
|
||||||
ClientSecret = ssoProvider.ClientSecret,
|
|
||||||
IsPublic = ssoProvider.IsPublic,
|
|
||||||
Name = ssoProvider.Name,
|
|
||||||
TokenEndpoint = ssoProvider.TokenEndpoint,
|
|
||||||
ValidIssuer = ssoProvider.ValidIssuer,
|
|
||||||
Guid = ssoProvider.Guid
|
|
||||||
};
|
|
||||||
|
|
||||||
return readSsoProvider;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression<Func<SsoProvider, object>> KeySelector(string? sortKey)
|
private Expression<Func<SsoProvider, object>> KeySelector(string? sortKey)
|
||||||
{
|
{
|
||||||
return sortKey?.ToLowerInvariant() switch
|
return sortKey?.ToLowerInvariant() switch
|
||||||
@ -105,12 +83,8 @@ public class SsoManager : ISsoManager
|
|||||||
CancellationToken cancellationToken
|
CancellationToken cancellationToken
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
await _ssoManagerRepository.TransactionAsync(async () =>
|
await AlterSsoProviderAsync(auditUserDetails, editSsoProvider.Id, ssoProvider =>
|
||||||
{
|
{
|
||||||
var ssoProvider = await _ssoManagerRepository.GetSsoProviderAsync(editSsoProvider.Id, cancellationToken);
|
|
||||||
if (ssoProvider is null)
|
|
||||||
throw new NotFoundException("SsoProvider with this id does not exists");
|
|
||||||
|
|
||||||
ssoProvider.AuthorizationEndpoint = editSsoProvider.AuthorizationEndpoint;
|
ssoProvider.AuthorizationEndpoint = editSsoProvider.AuthorizationEndpoint;
|
||||||
ssoProvider.Name = editSsoProvider.Name;
|
ssoProvider.Name = editSsoProvider.Name;
|
||||||
ssoProvider.ClientId = editSsoProvider.ClientId;
|
ssoProvider.ClientId = editSsoProvider.ClientId;
|
||||||
@ -120,12 +94,32 @@ public class SsoManager : ISsoManager
|
|||||||
ssoProvider.TokenEndpoint = editSsoProvider.TokenEndpoint;
|
ssoProvider.TokenEndpoint = editSsoProvider.TokenEndpoint;
|
||||||
ssoProvider.IsPublic = editSsoProvider.IsPublic;
|
ssoProvider.IsPublic = editSsoProvider.IsPublic;
|
||||||
ssoProvider.Deleted = false;
|
ssoProvider.Deleted = false;
|
||||||
|
return Task.CompletedTask;
|
||||||
await _ssoManagerRepository.EditNewSsoProviderAsync(auditUserDetails, ssoProvider, cancellationToken);
|
},
|
||||||
});
|
cancellationToken );
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemoveSsoProviderAsync(AuditUserDetails auditUserDetails, IGeneralIdRef generalIdRef, CancellationToken cancellationToken)
|
public async Task PatchSsoProviderAsync(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
GeneralIdRef generalIdRef,
|
||||||
|
PatchSsoProvider patchSsoProvider,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var patch = _patchFactory.Create(patchSsoProvider);
|
||||||
|
await AlterSsoProviderAsync(auditUserDetails, generalIdRef, async ssoProvider =>
|
||||||
|
{
|
||||||
|
await patch.ApplyTo(ssoProvider);
|
||||||
|
},
|
||||||
|
cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AlterSsoProviderAsync(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
IGeneralIdRef generalIdRef,
|
||||||
|
Func<SsoProvider, Task> applyChanges,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
{
|
{
|
||||||
await _ssoManagerRepository.TransactionAsync(async () =>
|
await _ssoManagerRepository.TransactionAsync(async () =>
|
||||||
{
|
{
|
||||||
@ -133,8 +127,18 @@ public class SsoManager : ISsoManager
|
|||||||
if (ssoProvider is null)
|
if (ssoProvider is null)
|
||||||
throw new NotFoundException("SsoProvider with this id does not exists");
|
throw new NotFoundException("SsoProvider with this id does not exists");
|
||||||
|
|
||||||
ssoProvider.Deleted = true;
|
await applyChanges(ssoProvider);
|
||||||
|
|
||||||
await _ssoManagerRepository.EditNewSsoProviderAsync(auditUserDetails, ssoProvider, cancellationToken);
|
await _ssoManagerRepository.EditNewSsoProviderAsync(auditUserDetails, ssoProvider, cancellationToken);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task RemoveSsoProviderAsync(AuditUserDetails auditUserDetails, IGeneralIdRef generalIdRef, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await AlterSsoProviderAsync(auditUserDetails, generalIdRef, async ssoProvider =>
|
||||||
|
{
|
||||||
|
ssoProvider.Deleted = true;
|
||||||
|
},
|
||||||
|
cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
using e_suite.API.Common.repository;
|
using e_suite.API.Common.repository;
|
||||||
|
using e_suite.Database.Audit;
|
||||||
using e_suite.Database.Core;
|
using e_suite.Database.Core;
|
||||||
|
using e_suite.Database.Core.Tables.Workflow;
|
||||||
|
|
||||||
namespace e_suite.Modules.WorkflowTemplatesManager.Repository;
|
namespace e_suite.Modules.WorkflowTemplatesManager.Repository;
|
||||||
|
|
||||||
@ -8,4 +10,14 @@ public class WorkflowTemplateRepository : RepositoryBase, IWorkflowTemplateRepos
|
|||||||
public WorkflowTemplateRepository(IEsuiteDatabaseDbContext databaseDbContext) : base(databaseDbContext)
|
public WorkflowTemplateRepository(IEsuiteDatabaseDbContext databaseDbContext) : base(databaseDbContext)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IQueryable<WorkflowVersion> GetWorkflowVersions()
|
||||||
|
{
|
||||||
|
return DatabaseDbContext.WorkflowVersions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task EditWorkflowVersionAsync(AuditUserDetails auditUserDetails, WorkflowVersion workflowVersion, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await DatabaseDbContext.SaveChangesAsync(auditUserDetails, cancellationToken);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,8 +1,127 @@
|
|||||||
using e_suite.API.Common;
|
using e_suite.API.Common;
|
||||||
|
using e_suite.API.Common.exceptions;
|
||||||
|
using e_suite.API.Common.repository;
|
||||||
|
using e_suite.Database.Audit;
|
||||||
|
using e_suite.Database.Core.Extensions;
|
||||||
|
using e_suite.Database.Core.Tables.Workflow;
|
||||||
|
using e_suite.Utilities.Pagination;
|
||||||
|
using eSuite.Core.Miscellaneous;
|
||||||
|
using System.Linq.Expressions;
|
||||||
|
|
||||||
namespace e_suite.Modules.WorkflowTemplatesManager;
|
namespace e_suite.Modules.WorkflowTemplatesManager;
|
||||||
|
|
||||||
public class WorkflowTemplateManager : IWorkflowTemplateManager
|
public class WorkflowTemplateManager : IWorkflowTemplateManager
|
||||||
{
|
{
|
||||||
|
private readonly IWorkflowTemplateRepository _workflowTemplateRepository;
|
||||||
|
private readonly IDomainRepository _domainRepository;
|
||||||
|
private readonly IPatchFactory _patchFactory;
|
||||||
|
|
||||||
|
public WorkflowTemplateManager(IWorkflowTemplateRepository workflowTemplateRepository, IPatchFactory patchFactory, IDomainRepository domainRepository)
|
||||||
|
{
|
||||||
|
_workflowTemplateRepository = workflowTemplateRepository;
|
||||||
|
_patchFactory = patchFactory;
|
||||||
|
_domainRepository = domainRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<PaginatedData<GetWorkflowTemplate>> GetWorkflowTemplatesAsync(Paging paging, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var ssoProviders = _workflowTemplateRepository.GetWorkflowVersions().Where(x => x.Deleted == false);
|
||||||
|
|
||||||
|
var paginatedData = await PaginatedData.Paginate<WorkflowVersion, GetWorkflowTemplate>(ssoProviders, paging,
|
||||||
|
KeySelector, cancellationToken);
|
||||||
|
|
||||||
|
return paginatedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Expression<Func<WorkflowVersion, object>> KeySelector(string sortKey)
|
||||||
|
{
|
||||||
|
return sortKey?.ToLowerInvariant() switch
|
||||||
|
{
|
||||||
|
"id" => x => x.Id,
|
||||||
|
"activitynametemplate" => x => x.ActivityNameTemplate,
|
||||||
|
"description" => x => x.Description,
|
||||||
|
"domain.name" => x => x.Domain.Name,
|
||||||
|
"workflow.name" => x => x.Workflow.Name,
|
||||||
|
_ => x => x.Id
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<GetWorkflowTemplate?> GetWorkflowTemplateAsync(GeneralIdRef generalIdRef, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
var workflowTemplate = await _workflowTemplateRepository.GetWorkflowVersions().FindByGeneralIdRefAsync(generalIdRef, cancellationToken)
|
||||||
|
?? throw new NotFoundException("Unable to find Workflow Version");
|
||||||
|
return new GetWorkflowTemplate(workflowTemplate);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task EditTemplate(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
EditWorkflowTemplate template,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
await AlterWorkflowTemplateVersionAsync(auditUserDetails, template.ToGeneralIdRef()!, async version =>
|
||||||
|
{
|
||||||
|
var domain = await _domainRepository.GetDomainById(template.DomainId, cancellationToken);
|
||||||
|
if (domain is null)
|
||||||
|
throw new NotFoundException("Unable to find Domain with provided id");
|
||||||
|
|
||||||
|
version.Domain = domain;
|
||||||
|
version.DomainId = domain.Id;
|
||||||
|
version.Description = template.Description;
|
||||||
|
version.ActivityNameTemplate = template.ActivityNameTemplate;
|
||||||
|
version.Deleted = false;
|
||||||
|
version.Version = template.Version;
|
||||||
|
//version.WorkflowId
|
||||||
|
}, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task PatchTemplate(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
IGeneralIdRef templateId,
|
||||||
|
PatchWorkflowTemplate patchTemplate,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
var patch = _patchFactory.Create(patchTemplate);
|
||||||
|
await AlterWorkflowTemplateVersionAsync(auditUserDetails, templateId, async version =>
|
||||||
|
{
|
||||||
|
patch.ApplyTo(version);
|
||||||
|
}, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task PostTemplate(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
CreateWorkflowTemplate template,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteTemplate(AuditUserDetails auditUserDetails, IGeneralIdRef templateId, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
await AlterWorkflowTemplateVersionAsync(auditUserDetails, templateId, async version =>
|
||||||
|
{
|
||||||
|
version.Deleted = true;
|
||||||
|
}, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task AlterWorkflowTemplateVersionAsync(
|
||||||
|
AuditUserDetails auditUserDetails,
|
||||||
|
IGeneralIdRef generalIdRef,
|
||||||
|
Func<WorkflowVersion, Task> applyChanges,
|
||||||
|
CancellationToken cancellationToken
|
||||||
|
)
|
||||||
|
{
|
||||||
|
await _workflowTemplateRepository.TransactionAsync(async () =>
|
||||||
|
{
|
||||||
|
var workflowVersion = await _workflowTemplateRepository.GetWorkflowVersions().FindByGeneralIdRefAsync(generalIdRef, cancellationToken);
|
||||||
|
if (workflowVersion is null)
|
||||||
|
throw new NotFoundException("SsoProvider with this id does not exists");
|
||||||
|
|
||||||
|
await applyChanges(workflowVersion);
|
||||||
|
|
||||||
|
await _workflowTemplateRepository.EditWorkflowVersionAsync(auditUserDetails, workflowVersion, cancellationToken);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user