feat: Templates (#1399)
* Migrations * New from template * fix: Don't allow public share of template * chore: Template badges * fix: Collection active * feat: New doc button on template list item * feat: New template menu * fix: Sorting * feat: Templates onboarding notice * fix: New doc button showing on archived/deleted templates
This commit is contained in:
@@ -98,6 +98,7 @@ const Document = sequelize.define(
|
||||
},
|
||||
},
|
||||
version: DataTypes.SMALLINT,
|
||||
template: DataTypes.BOOLEAN,
|
||||
editorVersion: DataTypes.STRING,
|
||||
text: DataTypes.TEXT,
|
||||
|
||||
@@ -142,6 +143,10 @@ Document.associate = models => {
|
||||
as: "team",
|
||||
foreignKey: "teamId",
|
||||
});
|
||||
Document.belongsTo(models.Document, {
|
||||
as: "document",
|
||||
foreignKey: "templateId",
|
||||
});
|
||||
Document.belongsTo(models.User, {
|
||||
as: "createdBy",
|
||||
foreignKey: "createdById",
|
||||
@@ -431,20 +436,28 @@ Document.searchForUser = async (
|
||||
// Hooks
|
||||
|
||||
Document.addHook("beforeSave", async model => {
|
||||
if (!model.publishedAt) return;
|
||||
if (!model.publishedAt || model.template) {
|
||||
return;
|
||||
}
|
||||
|
||||
const collection = await Collection.findByPk(model.collectionId);
|
||||
if (!collection || collection.type !== "atlas") return;
|
||||
if (!collection || collection.type !== "atlas") {
|
||||
return;
|
||||
}
|
||||
|
||||
await collection.updateDocument(model);
|
||||
model.collection = collection;
|
||||
});
|
||||
|
||||
Document.addHook("afterCreate", async model => {
|
||||
if (!model.publishedAt) return;
|
||||
if (!model.publishedAt || model.template) {
|
||||
return;
|
||||
}
|
||||
|
||||
const collection = await Collection.findByPk(model.collectionId);
|
||||
if (!collection || collection.type !== "atlas") return;
|
||||
if (!collection || collection.type !== "atlas") {
|
||||
return;
|
||||
}
|
||||
|
||||
await collection.addDocumentToStructure(model);
|
||||
model.collection = collection;
|
||||
|
||||
Reference in New Issue
Block a user