mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9fd2f0cb17 | |||
| f1c8be7bed |
+23
-35
@@ -10,7 +10,6 @@ import type {
|
||||
SaveOptions,
|
||||
} from "sequelize";
|
||||
import {
|
||||
Sequelize,
|
||||
Transaction,
|
||||
Op,
|
||||
FindOptions,
|
||||
@@ -101,6 +100,9 @@ type AdditionalFindOptions = {
|
||||
},
|
||||
},
|
||||
},
|
||||
attributes: {
|
||||
exclude: ["state"],
|
||||
},
|
||||
}))
|
||||
@Scopes(() => ({
|
||||
withCollectionPermissions: (userId: string, paranoid = true) => ({
|
||||
@@ -130,17 +132,6 @@ type AdditionalFindOptions = {
|
||||
},
|
||||
],
|
||||
},
|
||||
withStateIsEmpty: {
|
||||
attributes: {
|
||||
exclude: ["state"],
|
||||
include: [
|
||||
[
|
||||
Sequelize.literal(`CASE WHEN state IS NULL THEN true ELSE false END`),
|
||||
"stateIsEmpty",
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
withState: {
|
||||
attributes: {
|
||||
// resets to include the state column
|
||||
@@ -1150,30 +1141,27 @@ class Document extends ArchivableModel<
|
||||
// Checking if the record is new is a performance optimization – new docs cannot have children
|
||||
const childDocuments = this.isNewRecord
|
||||
? []
|
||||
: await (this.constructor as typeof Document)
|
||||
.unscoped()
|
||||
.scope("withoutState")
|
||||
.findAll({
|
||||
where: options?.includeArchived
|
||||
? {
|
||||
teamId: this.teamId,
|
||||
parentDocumentId: this.id,
|
||||
publishedAt: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
}
|
||||
: {
|
||||
teamId: this.teamId,
|
||||
parentDocumentId: this.id,
|
||||
publishedAt: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
archivedAt: {
|
||||
[Op.is]: null,
|
||||
},
|
||||
: await (this.constructor as typeof Document).unscoped().findAll({
|
||||
where: options?.includeArchived
|
||||
? {
|
||||
teamId: this.teamId,
|
||||
parentDocumentId: this.id,
|
||||
publishedAt: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
transaction: options?.transaction,
|
||||
});
|
||||
}
|
||||
: {
|
||||
teamId: this.teamId,
|
||||
parentDocumentId: this.id,
|
||||
publishedAt: {
|
||||
[Op.ne]: null,
|
||||
},
|
||||
archivedAt: {
|
||||
[Op.is]: null,
|
||||
},
|
||||
},
|
||||
transaction: options?.transaction,
|
||||
});
|
||||
|
||||
const children = await Promise.all(
|
||||
childDocuments.map((child) => child.toNavigationNode(options))
|
||||
|
||||
@@ -269,13 +269,15 @@ class GroupMembership extends ParanoidModel<
|
||||
transaction,
|
||||
});
|
||||
|
||||
const document = await Document.unscoped().findOne({
|
||||
attributes: ["id"],
|
||||
where: {
|
||||
id: model.documentId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
const document = await Document.unscoped()
|
||||
.scope("withoutState")
|
||||
.findOne({
|
||||
attributes: ["id"],
|
||||
where: {
|
||||
id: model.documentId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -256,13 +256,15 @@ class UserMembership extends IdModel<
|
||||
transaction,
|
||||
});
|
||||
|
||||
const document = await Document.unscoped().findOne({
|
||||
attributes: ["id"],
|
||||
where: {
|
||||
id: model.documentId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
const document = await Document.unscoped()
|
||||
.scope("withoutState")
|
||||
.findOne({
|
||||
attributes: ["id"],
|
||||
where: {
|
||||
id: model.documentId,
|
||||
},
|
||||
transaction,
|
||||
});
|
||||
if (!document) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -183,7 +183,6 @@ export default class SearchHelper {
|
||||
];
|
||||
|
||||
return Document.scope([
|
||||
"withoutState",
|
||||
"withDrafts",
|
||||
{
|
||||
method: ["withViews", user.id],
|
||||
@@ -246,7 +245,6 @@ export default class SearchHelper {
|
||||
// Final query to get associated document data
|
||||
const [documents, count] = await Promise.all([
|
||||
Document.scope([
|
||||
"withState",
|
||||
"withDrafts",
|
||||
{
|
||||
method: ["withViews", user.id],
|
||||
|
||||
@@ -464,7 +464,7 @@ export default class WebsocketsProcessor {
|
||||
const comment = await Comment.findByPk(event.modelId, {
|
||||
include: [
|
||||
{
|
||||
model: Document.scope(["withoutState", "withDrafts"]),
|
||||
model: Document.scope("withDrafts"),
|
||||
as: "document",
|
||||
required: true,
|
||||
},
|
||||
@@ -486,7 +486,7 @@ export default class WebsocketsProcessor {
|
||||
paranoid: false,
|
||||
include: [
|
||||
{
|
||||
model: Document.scope(["withoutState", "withDrafts"]),
|
||||
model: Document.scope("withDrafts"),
|
||||
as: "document",
|
||||
required: true,
|
||||
},
|
||||
@@ -510,7 +510,7 @@ export default class WebsocketsProcessor {
|
||||
const comment = await Comment.findByPk(event.modelId, {
|
||||
include: [
|
||||
{
|
||||
model: Document.scope(["withoutState", "withDrafts"]),
|
||||
model: Document.scope("withDrafts"),
|
||||
as: "document",
|
||||
required: true,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user