mirror of
https://github.com/outline/outline.git
synced 2026-05-06 18:12:33 -05:00
Refactor withMembershipScope (#9134)
This commit is contained in:
@@ -634,21 +634,17 @@ class Document extends ArchivableModel<
|
||||
|
||||
static withMembershipScope(
|
||||
userId: string,
|
||||
scopeOrOptions?: string[] | FindOptions<Document>,
|
||||
opts?: FindOptions<Document>
|
||||
options?: FindOptions<Document> & { includeDrafts?: boolean }
|
||||
) {
|
||||
const scopes = Array.isArray(scopeOrOptions) ? scopeOrOptions : [];
|
||||
const options = Array.isArray(scopeOrOptions) ? opts : scopeOrOptions;
|
||||
|
||||
return this.scope([
|
||||
"defaultScope",
|
||||
options?.includeDrafts ? "withDrafts" : "defaultScope",
|
||||
"withoutState",
|
||||
{
|
||||
method: ["withViews", userId],
|
||||
},
|
||||
{
|
||||
method: ["withMembership", userId, options?.paranoid],
|
||||
},
|
||||
...scopes,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,9 @@ export default class SearchHelper {
|
||||
},
|
||||
];
|
||||
|
||||
return Document.withMembershipScope(user.id, ["withDrafts"]).findAll({
|
||||
return Document.withMembershipScope(user.id, {
|
||||
includeDrafts: true,
|
||||
}).findAll({
|
||||
where,
|
||||
subQuery: false,
|
||||
order: [["updatedAt", "DESC"]],
|
||||
@@ -262,7 +264,7 @@ export default class SearchHelper {
|
||||
|
||||
// Final query to get associated document data
|
||||
const [documents, count] = await Promise.all([
|
||||
Document.withMembershipScope(user.id, ["withDrafts"]).findAll({
|
||||
Document.withMembershipScope(user.id, { includeDrafts: true }).findAll({
|
||||
where: {
|
||||
teamId: user.teamId,
|
||||
id: map(results, "id"),
|
||||
|
||||
@@ -535,9 +535,9 @@ router.post(
|
||||
delete where.updatedAt;
|
||||
}
|
||||
|
||||
const documents = await Document.withMembershipScope(user.id, [
|
||||
"withDrafts",
|
||||
]).findAll({
|
||||
const documents = await Document.withMembershipScope(user.id, {
|
||||
includeDrafts: true,
|
||||
}).findAll({
|
||||
where,
|
||||
order: [[sort, direction]],
|
||||
offset: ctx.state.pagination.offset,
|
||||
|
||||
@@ -58,9 +58,9 @@ router.post(
|
||||
const documentIds = memberships
|
||||
.map((p) => p.documentId)
|
||||
.filter(Boolean) as string[];
|
||||
const documents = await Document.withMembershipScope(userId, [
|
||||
"withDrafts",
|
||||
]).findAll({
|
||||
const documents = await Document.withMembershipScope(userId, {
|
||||
includeDrafts: true,
|
||||
}).findAll({
|
||||
where: {
|
||||
id: documentIds,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user