diff --git a/apps/server/src/core/share/share.service.ts b/apps/server/src/core/share/share.service.ts index 6051ba4cd..1abdfc95b 100644 --- a/apps/server/src/core/share/share.service.ts +++ b/apps/server/src/core/share/share.service.ts @@ -255,67 +255,6 @@ export class ShareService { }; } - async getShareAncestorPage( - ancestorPageId: string, - childPageId: string, - ): Promise { - let ancestor = null; - try { - ancestor = await this.db - .withRecursive('page_ancestors', (db) => - db - .selectFrom('pages') - .select([ - 'id', - 'slugId', - 'title', - 'parentPageId', - 'spaceId', - (eb) => - eb - .case() - .when(eb.ref('id'), '=', ancestorPageId) - .then(true) - .else(false) - .end() - .as('found'), - ]) - .where(isValidUUID(childPageId) ? 'id' : 'slugId', '=', childPageId) - .unionAll((exp) => - exp - .selectFrom('pages as p') - .select([ - 'p.id', - 'p.slugId', - 'p.title', - 'p.parentPageId', - 'p.spaceId', - (eb) => - eb - .case() - .when(eb.ref('p.id'), '=', ancestorPageId) - .then(true) - .else(false) - .end() - .as('found'), - ]) - .innerJoin('page_ancestors as pa', 'pa.parentPageId', 'p.id') - // Continue recursing only when the target ancestor hasn't been found on that branch. - .where('pa.found', '=', false), - ), - ) - .selectFrom('page_ancestors') - .selectAll() - .where('found', '=', true) - .limit(1) - .executeTakeFirst(); - } catch (err) { - // empty - } - - return ancestor; - } - /** * Resolve transclusion content for a public share viewer. Each requested * source page must itself be reachable via the share graph (its own share diff --git a/apps/server/src/database/repos/page/page-permission.repo.ts b/apps/server/src/database/repos/page/page-permission.repo.ts index 4c240905c..cc12c27d8 100644 --- a/apps/server/src/database/repos/page/page-permission.repo.ts +++ b/apps/server/src/database/repos/page/page-permission.repo.ts @@ -1158,67 +1158,6 @@ export class PagePermissionRepo { return results.map((r) => r.parentPageId); } - /** - * Get all page IDs within a subtree that are restricted OR are descendants of restricted pages. - * Used to filter pages from public shares - if a page is restricted, it and all its - * children should be hidden. - */ - async getRestrictedSubtreeIds(rootPageId: string): Promise { - const results = await this.db - .withRecursive('descendants', (qb) => - qb - .selectFrom('pages') - .select(['pages.id as descendantId', 'pages.parentPageId']) - .where('pages.id', '=', rootPageId) - .unionAll((eb) => - eb - .selectFrom('pages') - .innerJoin( - 'descendants', - 'descendants.descendantId', - 'pages.parentPageId', - ) - .select(['pages.id as descendantId', 'pages.parentPageId']) - .where('pages.deletedAt', 'is', null), - ), - ) - .withRecursive('descendantAncestors', (qb) => - qb - .selectFrom('descendants') - .innerJoin('pages', 'pages.id', 'descendants.descendantId') - .select([ - 'descendants.descendantId', - 'pages.id as ancestorId', - 'pages.parentPageId as ancestorParentId', - ]) - .unionAll((eb) => - eb - .selectFrom('pages') - .innerJoin( - 'descendantAncestors', - 'descendantAncestors.ancestorParentId', - 'pages.id', - ) - .select([ - 'descendantAncestors.descendantId', - 'pages.id as ancestorId', - 'pages.parentPageId as ancestorParentId', - ]), - ), - ) - .selectFrom('descendantAncestors') - .innerJoin( - 'pageAccess', - 'pageAccess.pageId', - 'descendantAncestors.ancestorId', - ) - .select('descendantAncestors.descendantId') - .distinct() - .execute(); - - return results.map((r) => r.descendantId); - } - /** * Given a pageId and a set of candidate userIds, return the subset who can * access the page (have permission on ALL restricted ancestors).