From e0ec7da86cfef47eb0553d778a8c53bf6f30ce49 Mon Sep 17 00:00:00 2001 From: Robert Boer Date: Tue, 25 Nov 2025 11:27:00 +0100 Subject: [PATCH 1/2] DN-3381 Feature: Disable authorization and use dummy user service --- .../Infrastructure/ApiControllerBase.cs | 2 +- .../ServiceCollectionExtentions.cs | 6 +++- UvA.Workflow/Users/MockUserService.cs | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 UvA.Workflow/Users/MockUserService.cs diff --git a/UvA.Workflow.Api/Infrastructure/ApiControllerBase.cs b/UvA.Workflow.Api/Infrastructure/ApiControllerBase.cs index 5be1156..e0e78ae 100644 --- a/UvA.Workflow.Api/Infrastructure/ApiControllerBase.cs +++ b/UvA.Workflow.Api/Infrastructure/ApiControllerBase.cs @@ -4,7 +4,7 @@ namespace UvA.Workflow.Api.Infrastructure; [ApiController] -[Authorize] +//[Authorize] //TODO: enable authentication when UI has SurfConext support [Route("[controller]")] public abstract class ApiControllerBase : ControllerBase { diff --git a/UvA.Workflow.Api/Infrastructure/ServiceCollectionExtentions.cs b/UvA.Workflow.Api/Infrastructure/ServiceCollectionExtentions.cs index 5732ee6..386a459 100644 --- a/UvA.Workflow.Api/Infrastructure/ServiceCollectionExtentions.cs +++ b/UvA.Workflow.Api/Infrastructure/ServiceCollectionExtentions.cs @@ -28,7 +28,11 @@ public static IServiceCollection AddWorkflow(this IServiceCollection services, I services.AddScoped(); services.AddScoped(); - services.AddScoped(); + + // TODO: restore actual user service when UI has SurfContext support + services.AddScoped(); + //services.AddScoped(); + services.AddScoped(sp => sp.GetRequiredService().Get()); services.AddScoped(); diff --git a/UvA.Workflow/Users/MockUserService.cs b/UvA.Workflow/Users/MockUserService.cs new file mode 100644 index 0000000..58cd6a6 --- /dev/null +++ b/UvA.Workflow/Users/MockUserService.cs @@ -0,0 +1,32 @@ +namespace UvA.Workflow.Users; + +public class MockUserService : IUserService +{ + private static readonly IEnumerable DummyUsers = + [ + new() { Id = "1", DisplayName = "User 1", Email = "1@invalid.invalid" }, + new() { Id = "2", DisplayName = "User 2", Email = "2@invalid.invalid" }, + new() { Id = "3", DisplayName = "User 3", Email = "3@invalid.invalid" } + ]; + + private static readonly IEnumerable Roles = ["Coordinator", "SuperAdmin", "Admin"]; + + public Task> GetRoles(User user, CancellationToken ct = default) => + throw new NotImplementedException(); + + public Task> FindUsers(string query, CancellationToken cancellationToken) + => Task.FromResult(DummyUsers + .Where(u => u.DisplayName.Contains(query, StringComparison.CurrentCultureIgnoreCase)) + .Select(r => new UserSearchResult(r.Id, r.DisplayName, r.Email))); + + public Task GetCurrentUser(CancellationToken ct = default) => Task.FromResult(DummyUsers.FirstOrDefault()); + + public Task> GetRolesOfCurrentUser(CancellationToken ct = default) => Task.FromResult(Roles); + + public Task + AddOrUpdateUser(string username, string displayName, string email, CancellationToken ct = default) => + GetCurrentUser(ct)!; + + public Task GetUser(string username, CancellationToken ct) => + Task.FromResult(DummyUsers.FirstOrDefault(u => u.Id == username)); +} \ No newline at end of file From 35c5e1063a0234aa0c23abbc05395b96ee5715b4 Mon Sep 17 00:00:00 2001 From: Robert Boer Date: Tue, 25 Nov 2025 11:39:13 +0100 Subject: [PATCH 2/2] DN-3381 Fixed GetRoles --- UvA.Workflow/Users/MockUserService.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/UvA.Workflow/Users/MockUserService.cs b/UvA.Workflow/Users/MockUserService.cs index 58cd6a6..c3207ed 100644 --- a/UvA.Workflow/Users/MockUserService.cs +++ b/UvA.Workflow/Users/MockUserService.cs @@ -11,8 +11,7 @@ public class MockUserService : IUserService private static readonly IEnumerable Roles = ["Coordinator", "SuperAdmin", "Admin"]; - public Task> GetRoles(User user, CancellationToken ct = default) => - throw new NotImplementedException(); + public Task> GetRoles(User user, CancellationToken ct = default) => Task.FromResult(Roles); public Task> FindUsers(string query, CancellationToken cancellationToken) => Task.FromResult(DummyUsers