Skip to content

Commit

Permalink
Hide members of confidential projects
Browse files Browse the repository at this point in the history
Only the following people can see the list of members if a project is
confidential: the manager(s) of the project, site admins, and the org
admin(s) of the org(s) the project belongs to, if any. Everyone else,
including people who are themselves members of the project, cannot see
its membership.
  • Loading branch information
rmunn committed Aug 23, 2024
1 parent 578963e commit d555fa6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ protected override async Task HandleRequirementAsync(AuthorizationHandlerContext
{
projectId = middlewareContext.Parent<Project>().Id;
}
if (projectId != Guid.Empty && await permissions.CanSyncProjectAsync(projectId))
if (projectId != Guid.Empty && await permissions.CanViewProjectMembers(projectId))
{
context.Succeed(requirement);
} else
}
else
{
if (projectId == Guid.Empty)
{
Expand Down
10 changes: 10 additions & 0 deletions backend/LexBoxApi/Services/PermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ public async ValueTask AssertCanViewProject(string projectCode)
if (!await CanViewProject(projectCode)) throw new UnauthorizedAccessException();
}

public async ValueTask<bool> CanViewProjectMembers(Guid projectId)
{
if (User is not null && User.Role == UserRole.admin) return true;
// Project managers can view members of their own projects, even confidential ones
if (await CanManageProject(projectId)) return true;
var isConfidential = await projectService.LookupProjectConfidentiality(projectId);
if (isConfidential is null) return false; // Private by default
return isConfidential == false; // Explicitly set to public
}

public async ValueTask<bool> CanManageProject(Guid projectId)
{
if (User is null) return false;
Expand Down
1 change: 1 addition & 0 deletions backend/LexCore/ServiceInterfaces/IPermissionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public interface IPermissionService
ValueTask AssertCanViewProject(Guid projectId);
ValueTask<bool> CanViewProject(string projectCode);
ValueTask AssertCanViewProject(string projectCode);
ValueTask<bool> CanViewProjectMembers(Guid projectId);
ValueTask<bool> CanManageProject(Guid projectId);
ValueTask<bool> CanManageProject(string projectCode);
ValueTask AssertCanManageProject(Guid projectId);
Expand Down

0 comments on commit d555fa6

Please sign in to comment.