mirror of
https://github.com/outline/outline.git
synced 2026-05-08 02:50:30 -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"),
|
||||
|
||||
Reference in New Issue
Block a user