Skip to content

Commit

Permalink
permissions for ProjectByCode endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jul 7, 2023
1 parent 5366f92 commit e24d1fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion backend/LexBoxApi/GraphQL/LexQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ public IQueryable<Project> Projects(LexBoxDbContext context)

[UseSingleOrDefault]
[UseProjection]
public IQueryable<Project> ProjectByCode(LexBoxDbContext context, string code)
public IQueryable<Project> ProjectByCode(LexBoxDbContext context, LoggedInContext loggedInContext, string code)
{
loggedInContext.User.AssertCanAccessProject(code);
return context.Projects.Where(p => p.Code == code);
}

Expand Down
5 changes: 5 additions & 0 deletions backend/LexCore/Auth/LexAuthUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ public void AssertCanManageProject(Guid projectId)
{
if (!CanManageProject(projectId)) throw new UnauthorizedAccessException();
}

public void AssertCanAccessProject(string projectCode)
{
if (Role != UserRole.admin && Projects.All(p => p.Code != projectCode)) throw new UnauthorizedAccessException();
}
}

public record AuthUserProject(string Code, ProjectRole Role, Guid ProjectId);
Expand Down

0 comments on commit e24d1fa

Please sign in to comment.