diff --git a/backend/src/graphql/resolver/CommunityResolver.ts b/backend/src/graphql/resolver/CommunityResolver.ts index 0209c284d..d037fffb4 100644 --- a/backend/src/graphql/resolver/CommunityResolver.ts +++ b/backend/src/graphql/resolver/CommunityResolver.ts @@ -2,7 +2,7 @@ import { Paginated } from '@arg/Paginated' import { EditCommunityInput } from '@input/EditCommunityInput' import { AdminCommunityView } from '@model/AdminCommunityView' import { Community } from '@model/Community' -import { Community as DbCommunity, getHomeCommunity, getReachableCommunities } from 'database' +import { Community as DbCommunity, getAuthorizedCommunities, getHomeCommunity, getReachableCommunities } from 'database' import { updateAllDefinedAndChanged } from 'shared' import { Arg, Args, Authorized, Mutation, Query, Resolver } from 'type-graphql' import { RIGHTS } from '@/auth/RIGHTS' @@ -34,6 +34,17 @@ export class CommunityResolver { return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) } + @Authorized([RIGHTS.COMMUNITIES]) + @Query(() => [Community]) + async authorizedCommunities(): Promise { + const dbCommunities: DbCommunity[] = await getAuthorizedCommunities({ + // order by + foreign: 'ASC', // home community first + name: 'ASC', + }) + return dbCommunities.map((dbCom: DbCommunity) => new Community(dbCom)) + } + @Authorized([RIGHTS.COMMUNITIES]) @Query(() => Community) async communityByIdentifier( diff --git a/database/src/queries/communities.ts b/database/src/queries/communities.ts index 83e8933d0..37fba27ff 100644 --- a/database/src/queries/communities.ts +++ b/database/src/queries/communities.ts @@ -84,7 +84,7 @@ export async function getReachableCommunities( federatedCommunities: { verifiedAt: MoreThanOrEqual(new Date(Date.now() - authenticationTimeoutMs)), }, - }, + }, // or { foreign: false }, ], order, @@ -99,3 +99,17 @@ export async function getNotReachableCommunities( order, }) } + +// return the home community and all communities which had at least once make it through the first handshake +export async function getAuthorizedCommunities( + order?: FindOptionsOrder, +): Promise +{ + return await DbCommunity.find({ + where: [ + { authenticatedAt: Not(IsNull()) }, // or + { foreign: false } + ], + order + }) +} \ No newline at end of file