diff --git a/dev/tool/src/calendar.ts b/dev/tool/src/calendar.ts index d6ef9ebd02..7cc2659c7e 100644 --- a/dev/tool/src/calendar.ts +++ b/dev/tool/src/calendar.ts @@ -1,5 +1,11 @@ import calendar from '@hcengineering/calendar' -import { type PersonId, type WorkspaceInfoWithStatus, type WorkspaceUuid, systemAccountUuid } from '@hcengineering/core' +import { + type PersonId, + type WorkspaceInfoWithStatus, + type WorkspaceUuid, + isActiveMode, + systemAccountUuid +} from '@hcengineering/core' import { getClient as getKvsClient } from '@hcengineering/kvs-client' import { createClient, getAccountClient } from '@hcengineering/server-client' import { generateToken } from '@hcengineering/server-token' @@ -129,6 +135,7 @@ async function migrateCalendarIntegrations ( if (ws == null) { continue } + if (!isActiveMode(ws.mode)) continue token.workspace = ws.uuid const personId = await getPersonIdByEmail(ws.uuid, token.email, token.userId) @@ -215,6 +222,7 @@ async function migrateCalendarHistory ( if (ws == null) { continue } + if (!isActiveMode(ws.mode)) continue const personId = await getPersonIdByEmail(ws.uuid, history.email, history.userId) if (personId == null) { diff --git a/plugins/contact-resources/src/utils.ts b/plugins/contact-resources/src/utils.ts index 68dc0ea085..b76931500e 100644 --- a/plugins/contact-resources/src/utils.ts +++ b/plugins/contact-resources/src/utils.ts @@ -32,6 +32,7 @@ import { type PermissionsStore, type Person, type PersonsByPermission, + type MembersBySpace, type SocialIdentity } from '@hcengineering/contact' import core, { @@ -732,19 +733,33 @@ export async function resolveLocationData (loc: Location): Promise } export function checkMyPermission (_id: Ref, space: Ref, store: PermissionsStore): boolean { + const arePermissionsDisabled = getMetadata(core.metadata.DisablePermissions) ?? false + if (arePermissionsDisabled) return true return (store.whitelist.has(space) || store.ps[space]?.has(_id)) ?? false } +export function getPermittedPersons ( + _id: Ref, + space: Ref, + store: PermissionsStore +): Array> { + const arePermissionsDisabled = getMetadata(core.metadata.DisablePermissions) ?? false + if (arePermissionsDisabled) return Array.from(store.ms[space] ?? []) + return store.whitelist.has(space) ? Array.from(store.ms[space] ?? []) : Array.from(store.ap[space]?.[_id] ?? []) +} + const spacesStore = writable([]) export const permissionsStore = derived([spacesStore, personRefByAccountUuidStore], ([spaces, personRefByAccount]) => { const whitelistedSpaces = new Set>() const permissionsBySpace: PermissionsBySpace = {} const employeesByPermission: PersonsByPermission = {} + const membersBySpace: MembersBySpace = {} const client = getClient() const hierarchy = client.getHierarchy() for (const s of spaces) { + membersBySpace[s._id] = new Set(s.members.map((m) => personRefByAccount.get(m)).filter(notEmpty)) if (hierarchy.isDerived(s._class, core.class.TypedSpace)) { const type = client.getModel().findAllSync(core.class.SpaceType, { _id: (s as TypedSpace).type })[0] const mixin = type?.targetClass @@ -790,6 +805,7 @@ export const permissionsStore = derived([spacesStore, personRefByAccountUuidStor return { ps: permissionsBySpace, ap: employeesByPermission, + ms: membersBySpace, whitelist: whitelistedSpaces } }) @@ -815,6 +831,7 @@ spaceTypesQuery.query(core.class.SpaceType, {}, (types) => { projection: { _id: 1, type: 1, + members: 1, ...targetClasses } as any } diff --git a/plugins/contact/src/types.ts b/plugins/contact/src/types.ts index 334fb0f0d6..6196244546 100644 --- a/plugins/contact/src/types.ts +++ b/plugins/contact/src/types.ts @@ -52,9 +52,11 @@ export const AVATAR_COLORS: ColorDefinition[] = [ export type PermissionsBySpace = Record, Set>> export type PersonsByPermission = Record, Record, Set>>> +export type MembersBySpace = Record, Set>> export interface PermissionsStore { ps: PermissionsBySpace ap: PersonsByPermission + ms: MembersBySpace whitelist: Set> } diff --git a/plugins/controlled-documents-resources/src/components/TeamPopup.svelte b/plugins/controlled-documents-resources/src/components/TeamPopup.svelte index 359d76e06c..7a653492de 100644 --- a/plugins/controlled-documents-resources/src/components/TeamPopup.svelte +++ b/plugins/controlled-documents-resources/src/components/TeamPopup.svelte @@ -4,18 +4,18 @@ // -->