Skip to content

Commit

Permalink
Add GraphQL query for projects in org by lang code
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Jul 23, 2024
1 parent 1539fbb commit 9144205
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
28 changes: 28 additions & 0 deletions backend/LexBoxApi/GraphQL/LexQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ public IQueryable<DraftProject> DraftProjects(LexBoxDbContext context)
return context.DraftProjects;
}

public record ProjectsByLangCodeAndOrgInput(Guid OrgId, string LangCode);
[UseProjection]
[UseSorting]
public IQueryable<Project> ProjectsByLangCodeAndOrg(LoggedInContext loggedInContext, LexBoxDbContext context, IPermissionService permissionService, ProjectsByLangCodeAndOrgInput input)
{
var userId = loggedInContext.User.Id;
var authorized = loggedInContext.User.IsAdmin || permissionService.IsOrgMember(input.OrgId);
if (!authorized) throw new UnauthorizedAccessException();
var query = context.Projects.Where(p =>
p.Organizations.Any(o => o.Id == input.OrgId) &&
p.FlexProjectMetadata != null &&
p.FlexProjectMetadata.WritingSystems != null &&
p.FlexProjectMetadata.WritingSystems.VernacularWss.Any(ws =>
ws.IsActive && (
ws.Tag == input.LangCode ||
ws.Tag == $"qaa-x-{input.LangCode}" ||
ws.Tag.StartsWith($"{input.LangCode}-")
)
)
);
// Org admins can see all projects, everyone else can only see non-confidential
if (!permissionService.CanEditOrg(input.OrgId))
{
query = query.Where(p => p.IsConfidential == false);
}
return query;
}

[UseSingleOrDefault]
[UseProjection]
public async Task<IQueryable<Project>> ProjectById(LexBoxDbContext context, IPermissionService permissionService, Guid projectId)
Expand Down
6 changes: 6 additions & 0 deletions frontend/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ type Query {
projects(withDeleted: Boolean! = false where: ProjectFilterInput orderBy: [ProjectSortInput!]): [Project!]! @authorize(policy: "AdminRequiredPolicy")
myDraftProjects(orderBy: [DraftProjectSortInput!]): [DraftProject!]!
draftProjects(where: DraftProjectFilterInput orderBy: [DraftProjectSortInput!]): [DraftProject!]! @authorize(policy: "AdminRequiredPolicy")
projectsByLangCodeAndOrg(input: ProjectsByLangCodeAndOrgInput! orderBy: [ProjectSortInput!]): [Project!]!
projectById(projectId: UUID!): Project
projectByCode(code: String!): Project
draftProjectByCode(code: String!): DraftProject @authorize(policy: "AdminRequiredPolicy")
Expand Down Expand Up @@ -907,6 +908,11 @@ input ProjectWritingSystemsFilterInput {
analysisWss: ListFilterInputTypeOfFLExWsIdFilterInput
}

input ProjectsByLangCodeAndOrgInput {
orgId: UUID!
langCode: String!
}

input RemoveProjectFromOrgInput {
orgId: UUID!
projectId: UUID!
Expand Down

0 comments on commit 9144205

Please sign in to comment.