mirror of
https://github.com/documenso/documenso.git
synced 2026-07-25 01:15:49 +10:00
138d663c25
Merge origin/main into feat/external-2fa-codes. Resolve formatting conflicts caused by biome rollout; preserve both feature streams: PR's external 2FA token + signing-session 2FA proof additions plus main's RateLimit/RecipientExpired/signingReminders/date-auto-insert. In complete-document-with-token.ts, drop the duplicate early field-fetching block introduced when main moved that logic later with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH check using derivedRecipientActionAuth.
92 lines
2.6 KiB
TypeScript
92 lines
2.6 KiB
TypeScript
import { getHighestOrganisationRoleInGroup } from '@documenso/lib/utils/organisations';
|
|
import { buildTeamWhereQuery, extractDerivedTeamSettings, getHighestTeamRoleInGroup } from '@documenso/lib/utils/teams';
|
|
import { prisma } from '@documenso/prisma';
|
|
|
|
import { authenticatedProcedure } from '../trpc';
|
|
import type { TGetOrganisationSessionResponse } from './get-organisation-session.types';
|
|
import { ZGetOrganisationSessionResponseSchema } from './get-organisation-session.types';
|
|
|
|
/**
|
|
* Get all the organisations and teams a user belongs to.
|
|
*/
|
|
export const getOrganisationSessionRoute = authenticatedProcedure
|
|
.output(ZGetOrganisationSessionResponseSchema)
|
|
.query(async ({ ctx }) => {
|
|
return await getOrganisationSession({ userId: ctx.user.id });
|
|
});
|
|
|
|
export const getOrganisationSession = async ({
|
|
userId,
|
|
}: {
|
|
userId: number;
|
|
}): Promise<TGetOrganisationSessionResponse> => {
|
|
const organisations = await prisma.organisation.findMany({
|
|
where: {
|
|
members: {
|
|
some: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
include: {
|
|
organisationClaim: true,
|
|
organisationGlobalSettings: true,
|
|
subscription: true,
|
|
groups: {
|
|
where: {
|
|
organisationGroupMembers: {
|
|
some: {
|
|
organisationMember: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
teams: {
|
|
where: buildTeamWhereQuery({ teamId: undefined, userId }),
|
|
include: {
|
|
teamGlobalSettings: true,
|
|
teamEmail: { select: { email: true } },
|
|
teamGroups: {
|
|
where: {
|
|
organisationGroup: {
|
|
organisationGroupMembers: {
|
|
some: {
|
|
organisationMember: {
|
|
userId,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
include: {
|
|
organisationGroup: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
return organisations.map((organisation) => {
|
|
const { organisationGlobalSettings } = organisation;
|
|
|
|
return {
|
|
...organisation,
|
|
teams: organisation.teams.map((team) => {
|
|
const derivedSettings = extractDerivedTeamSettings(organisationGlobalSettings, team.teamGlobalSettings);
|
|
|
|
return {
|
|
...team,
|
|
currentTeamRole: getHighestTeamRoleInGroup(team.teamGroups),
|
|
preferences: {
|
|
aiFeaturesEnabled: derivedSettings.aiFeaturesEnabled,
|
|
},
|
|
};
|
|
}),
|
|
currentOrganisationRole: getHighestOrganisationRoleInGroup(organisation.groups),
|
|
};
|
|
});
|
|
};
|