Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion UvA.Workflow.Api/Infrastructure/ApiControllerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ public static IServiceCollection AddWorkflow(this IServiceCollection services, I
services.AddScoped<IUserRepository, UserRepository>();

services.AddScoped<WorkflowInstanceService>();
services.AddScoped<IUserService, UserService>();

// TODO: restore actual user service when UI has SurfContext support
services.AddScoped<IUserService, MockUserService>();
//services.AddScoped<IUserService, MockUserService>();

services.AddScoped<ModelService>(sp => sp.GetRequiredService<ModelServiceResolver>().Get());

services.AddScoped<IArtifactService, ArtifactService>();
Expand Down
31 changes: 31 additions & 0 deletions UvA.Workflow/Users/MockUserService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace UvA.Workflow.Users;

public class MockUserService : IUserService
{
private static readonly IEnumerable<User> DummyUsers =
[
new() { Id = "1", DisplayName = "User 1", Email = "[email protected]" },
new() { Id = "2", DisplayName = "User 2", Email = "[email protected]" },
new() { Id = "3", DisplayName = "User 3", Email = "[email protected]" }
];

private static readonly IEnumerable<string> Roles = ["Coordinator", "SuperAdmin", "Admin"];

public Task<IEnumerable<string>> GetRoles(User user, CancellationToken ct = default) => Task.FromResult(Roles);

public Task<IEnumerable<UserSearchResult>> 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<User?> GetCurrentUser(CancellationToken ct = default) => Task.FromResult(DummyUsers.FirstOrDefault());

public Task<IEnumerable<string>> GetRolesOfCurrentUser(CancellationToken ct = default) => Task.FromResult(Roles);

public Task<User>
AddOrUpdateUser(string username, string displayName, string email, CancellationToken ct = default) =>
GetCurrentUser(ct)!;

public Task<User?> GetUser(string username, CancellationToken ct) =>
Task.FromResult(DummyUsers.FirstOrDefault(u => u.Id == username));
}