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..c3207ed --- /dev/null +++ b/UvA.Workflow/Users/MockUserService.cs @@ -0,0 +1,31 @@ +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) => Task.FromResult(Roles); + + 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