mirror of
https://github.com/docmost/docmost.git
synced 2026-09-11 07:56:54 +08:00
refactor: remove unused hierarchy readers
This commit is contained in:
@@ -255,67 +255,6 @@ export class ShareService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
async getShareAncestorPage(
|
|
||||||
ancestorPageId: string,
|
|
||||||
childPageId: string,
|
|
||||||
): Promise<any> {
|
|
||||||
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
|
* Resolve transclusion content for a public share viewer. Each requested
|
||||||
* source page must itself be reachable via the share graph (its own share
|
* source page must itself be reachable via the share graph (its own share
|
||||||
|
|||||||
@@ -1158,67 +1158,6 @@ export class PagePermissionRepo {
|
|||||||
return results.map((r) => r.parentPageId);
|
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<string[]> {
|
|
||||||
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
|
* Given a pageId and a set of candidate userIds, return the subset who can
|
||||||
* access the page (have permission on ALL restricted ancestors).
|
* access the page (have permission on ALL restricted ancestors).
|
||||||
|
|||||||
Reference in New Issue
Block a user