feat: add organization domain foundation
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Security.Claims;
|
||||
using Socialize.Api.Data;
|
||||
using Socialize.Api.Modules.Identity.Data;
|
||||
using Socialize.Api.Infrastructure.Security;
|
||||
using Socialize.Api.Modules.Workspaces.Data;
|
||||
|
||||
namespace Socialize.Api.Modules.Workspaces.Handlers;
|
||||
|
||||
@@ -12,6 +13,7 @@ public record WorkspaceMemberDto(
|
||||
string DisplayName,
|
||||
string Email,
|
||||
string? PortraitUrl,
|
||||
string RelationshipCategory,
|
||||
IReadOnlyCollection<string> Roles);
|
||||
|
||||
public class GetWorkspaceMembersHandler(
|
||||
@@ -29,12 +31,20 @@ public class GetWorkspaceMembersHandler(
|
||||
{
|
||||
Guid workspaceId = Route<Guid>("workspaceId");
|
||||
|
||||
if (!accessScopeService.CanManageWorkspace(User, workspaceId))
|
||||
if (!await accessScopeService.CanManageWorkspaceAsync(User, workspaceId, ct))
|
||||
{
|
||||
await SendForbiddenAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
Workspace? workspace = await dbContext.Workspaces
|
||||
.SingleOrDefaultAsync(candidate => candidate.Id == workspaceId, ct);
|
||||
if (workspace is null)
|
||||
{
|
||||
await SendNotFoundAsync(ct);
|
||||
return;
|
||||
}
|
||||
|
||||
string workspaceClaimValue = workspaceId.ToString();
|
||||
|
||||
var users = await dbContext.Users
|
||||
@@ -42,7 +52,11 @@ public class GetWorkspaceMembersHandler(
|
||||
dbContext.UserClaims.Any(claim =>
|
||||
claim.UserId == candidate.Id &&
|
||||
claim.ClaimType == KnownClaims.WorkspaceScope &&
|
||||
claim.ClaimValue == workspaceClaimValue))
|
||||
claim.ClaimValue == workspaceClaimValue) ||
|
||||
dbContext.OrganizationMemberships.Any(membership =>
|
||||
membership.UserId == candidate.Id &&
|
||||
membership.OrganizationId == workspace.OrganizationId) ||
|
||||
candidate.Id == workspace.OwnerUserId)
|
||||
.OrderBy(candidate => candidate.Lastname)
|
||||
.ThenBy(candidate => candidate.Firstname)
|
||||
.ThenBy(candidate => candidate.Email)
|
||||
@@ -70,12 +84,19 @@ public class GetWorkspaceMembersHandler(
|
||||
.ToArray(),
|
||||
ct);
|
||||
|
||||
HashSet<Guid> organizationMemberUserIds = await dbContext.OrganizationMemberships
|
||||
.Where(membership => membership.OrganizationId == workspace.OrganizationId)
|
||||
.Select(membership => membership.UserId)
|
||||
.ToHashSetAsync(ct);
|
||||
organizationMemberUserIds.Add(workspace.OwnerUserId);
|
||||
|
||||
var members = users
|
||||
.Select(candidate => new WorkspaceMemberDto(
|
||||
candidate.Id,
|
||||
BuildDisplayName(candidate),
|
||||
candidate.Email ?? string.Empty,
|
||||
candidate.PortraitUrl,
|
||||
organizationMemberUserIds.Contains(candidate.Id) ? "Organization Member" : "External Collaborator",
|
||||
rolesByUserId.GetValueOrDefault(candidate.Id) ?? Array.Empty<string>()))
|
||||
.ToList();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user