diff --git a/backend/LexBoxApi/GraphQL/LexQueries.cs b/backend/LexBoxApi/GraphQL/LexQueries.cs index 442fcd8f3..062869d44 100644 --- a/backend/LexBoxApi/GraphQL/LexQueries.cs +++ b/backend/LexBoxApi/GraphQL/LexQueries.cs @@ -15,6 +15,7 @@ public class LexQueries { [UseProjection] [UseSorting] + [UseFiltering] public IQueryable MyProjects(LoggedInContext loggedInContext, LexBoxDbContext context) { var userId = loggedInContext.User.Id; diff --git a/frontend/schema.graphql b/frontend/schema.graphql index 7624aaa32..06060b836 100644 --- a/frontend/schema.graphql +++ b/frontend/schema.graphql @@ -425,7 +425,7 @@ type ProjectWritingSystems { } type Query { - myProjects(orderBy: [ProjectSortInput!] @cost(weight: "10")): [Project!]! @cost(weight: "10") + myProjects(orderBy: [ProjectSortInput!] @cost(weight: "10") where: ProjectFilterInput @cost(weight: "10")): [Project!]! @cost(weight: "10") projects(withDeleted: Boolean! = false where: ProjectFilterInput @cost(weight: "10") orderBy: [ProjectSortInput!] @cost(weight: "10")): [Project!]! @authorize(policy: "AdminRequiredPolicy") @cost(weight: "10") myDraftProjects(orderBy: [DraftProjectSortInput!] @cost(weight: "10")): [DraftProject!]! @cost(weight: "10") draftProjects(where: DraftProjectFilterInput @cost(weight: "10") orderBy: [DraftProjectSortInput!] @cost(weight: "10")): [DraftProject!]! @authorize(policy: "AdminRequiredPolicy") @cost(weight: "10") diff --git a/frontend/src/routes/(authenticated)/org/[org_id]/+page.ts b/frontend/src/routes/(authenticated)/org/[org_id]/+page.ts index cb0978e5b..f7a0cf93e 100644 --- a/frontend/src/routes/(authenticated)/org/[org_id]/+page.ts +++ b/frontend/src/routes/(authenticated)/org/[org_id]/+page.ts @@ -17,6 +17,7 @@ import type { } from '$lib/gql/types'; import {getClient, graphql} from '$lib/gql'; +import type {LexAuthUser} from '$lib/user'; import type {OrgTabId} from './OrgTabs.svelte'; import type {PageLoadEvent} from './$types'; import type {UUID} from 'crypto'; @@ -315,14 +316,24 @@ export async function _deleteOrg(orgId: string): $OpResult { return result; } -export async function _getMyProjects(): Promise { +export async function _getProjectsIManage(user: LexAuthUser): Promise { const client = getClient(); + //language=GraphQL const results = await client.query(graphql(` - query loadMyProjects { - myProjects(orderBy: [ + query loadMyProjects($userId: UUID!) { + myProjects( + orderBy: [ {name: ASC } - ]) { + ], + where: { + users: { + some: { + userId: {eq: $userId}, + role: {eq: MANAGER} + } + } + }) { code id name @@ -333,7 +344,7 @@ export async function _getMyProjects(): Promise; let newProjects: Project[] = []; - let alreadyAddedProjects: Project[] = []; + let alreadyAddedProjects: number = 0; let selectedProjects: string[] = []; async function openModal(): Promise { - const myProjects = await _getMyProjects(); - const projectsIManage = myProjects.map((project) => ({ - id: project.id, - name: project.name, - code: project.code, - memberRole: project.users.find(projUser => projUser.userId === user.id)?.role ?? ProjectRole.Editor, - })).filter(p => p.memberRole === ProjectRole.Manager); + const projectsIManage = await _getProjectsIManage(user); newProjects = []; - alreadyAddedProjects = []; + alreadyAddedProjects = 0; projectsIManage.forEach(proj => { if (org.projects.find(p => p.id === proj.id)) { - alreadyAddedProjects.push(proj); + alreadyAddedProjects++; } else { - newProjects.push(proj); + newProjects.push({ + ...proj, + memberRole: ProjectRole.Manager, + }); } }); @@ -66,9 +63,9 @@ {#if newProjects.length} - {:else if alreadyAddedProjects.length} + {:else if alreadyAddedProjects} - {$t('org_page.add_my_projects.all_projects_already_added', { count: alreadyAddedProjects.length })} + {$t('org_page.add_my_projects.all_projects_already_added', { count: alreadyAddedProjects })} {:else}