From d055021ad4da24a6396c385c008f828d6ee2b677 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 12 Aug 2020 10:49:02 -0700 Subject: [PATCH] chore: Remove all usage of collection.type (#1445) * chore: Remove all usage of collection.type * migration: Remove type column --- app/models/Collection.js | 1 - server/api/collections.js | 3 +-- server/api/collections.test.js | 1 - server/api/documents.js | 9 +-------- .../20200812170227-remove-collection-type.js | 14 ++++++++++++++ server/models/Collection.js | 6 ------ server/models/Document.js | 6 ++---- server/models/Team.js | 1 - server/presenters/collection.js | 7 ++----- server/test/factories.js | 1 - server/test/support.js | 1 - 11 files changed, 20 insertions(+), 30 deletions(-) create mode 100644 server/migrations/20200812170227-remove-collection-type.js diff --git a/app/models/Collection.js b/app/models/Collection.js index ce9249d93..5c96486a4 100644 --- a/app/models/Collection.js +++ b/app/models/Collection.js @@ -16,7 +16,6 @@ export default class Collection extends BaseModel { icon: string; color: string; private: boolean; - type: "atlas" | "journal"; documents: NavigationNode[]; createdAt: ?string; updatedAt: ?string; diff --git a/server/api/collections.js b/server/api/collections.js index c23c0a02b..740d23490 100644 --- a/server/api/collections.js +++ b/server/api/collections.js @@ -30,7 +30,7 @@ const { authorize } = policy; const router = new Router(); router.post("collections.create", auth(), async (ctx) => { - const { name, color, description, icon, type } = ctx.body; + const { name, color, description, icon } = ctx.body; const isPrivate = ctx.body.private; ctx.assertPresent(name, "name is required"); @@ -46,7 +46,6 @@ router.post("collections.create", auth(), async (ctx) => { description, icon, color, - type: type || "atlas", teamId: user.teamId, creatorId: user.id, private: isPrivate, diff --git a/server/api/collections.test.js b/server/api/collections.test.js index 581bbcebc..abb8574f2 100644 --- a/server/api/collections.test.js +++ b/server/api/collections.test.js @@ -1062,7 +1062,6 @@ describe("#collections.delete", () => { urlId: "blah", teamId: user.teamId, creatorId: user.id, - type: "atlas", }); const res = await server.post("/api/collections.delete", { diff --git a/server/api/documents.js b/server/api/documents.js index 932b66ec9..90f88e1a7 100644 --- a/server/api/documents.js +++ b/server/api/documents.js @@ -718,7 +718,7 @@ router.post("documents.create", auth(), async (ctx) => { authorize(user, "publish", collection); let parentDocument; - if (parentDocumentId && collection.type === "atlas") { + if (parentDocumentId) { parentDocument = await Document.findOne({ where: { id: parentDocumentId, @@ -938,13 +938,6 @@ router.post("documents.move", auth(), async (ctx) => { const document = await Document.findByPk(id, { userId: user.id }); authorize(user, "move", document); - const { collection } = document; - if (collection.type !== "atlas" && parentDocumentId) { - throw new InvalidRequestError( - "Document cannot be nested in this collection type" - ); - } - if (parentDocumentId) { const parent = await Document.findByPk(parentDocumentId, { userId: user.id, diff --git a/server/migrations/20200812170227-remove-collection-type.js b/server/migrations/20200812170227-remove-collection-type.js new file mode 100644 index 000000000..156c1ce90 --- /dev/null +++ b/server/migrations/20200812170227-remove-collection-type.js @@ -0,0 +1,14 @@ +'use strict'; + +module.exports = { + up: async (queryInterface, Sequelize) => { + await queryInterface.removeColumn('collections', 'type'); + }, + + down: async (queryInterface, Sequelize) => { + await queryInterface.addColumn('collections', 'type', { + type: Sequelize.STRING, + defaultValue: "atlas" + }); + } +}; \ No newline at end of file diff --git a/server/models/Collection.js b/server/models/Collection.js index 1d869b5c3..45026e256 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -23,12 +23,6 @@ const Collection = sequelize.define( color: DataTypes.STRING, private: DataTypes.BOOLEAN, maintainerApprovalRequired: DataTypes.BOOLEAN, - type: { - type: DataTypes.STRING, - validate: { isIn: [["atlas", "journal"]] }, - }, - - /* type: atlas */ documentStructure: DataTypes.JSONB, }, { diff --git a/server/models/Document.js b/server/models/Document.js index 224409ed1..6518bd1c6 100644 --- a/server/models/Document.js +++ b/server/models/Document.js @@ -441,7 +441,7 @@ Document.addHook("beforeSave", async (model) => { } const collection = await Collection.findByPk(model.collectionId); - if (!collection || collection.type !== "atlas") { + if (!collection) { return; } @@ -455,7 +455,7 @@ Document.addHook("afterCreate", async (model) => { } const collection = await Collection.findByPk(model.collectionId); - if (!collection || collection.type !== "atlas") { + if (!collection) { return; } @@ -548,8 +548,6 @@ Document.prototype.publish = async function (options) { if (this.publishedAt) return this.save(options); const collection = await Collection.findByPk(this.collectionId); - if (collection.type !== "atlas") return this.save(options); - await collection.addDocumentToStructure(this); this.publishedAt = new Date(); diff --git a/server/models/Team.js b/server/models/Team.js index 4563c5e36..ca269aefc 100644 --- a/server/models/Team.js +++ b/server/models/Team.js @@ -134,7 +134,6 @@ Team.prototype.provisionFirstCollection = async function (userId) { name: "Welcome", description: "This collection is a quick guide to what Outline is all about. Feel free to delete this collection once your team is up to speed with the basics!", - type: "atlas", teamId: this.id, creatorId: userId, }); diff --git a/server/presenters/collection.js b/server/presenters/collection.js index 22893f9f8..6ef2fb986 100644 --- a/server/presenters/collection.js +++ b/server/presenters/collection.js @@ -26,7 +26,6 @@ export default function present(collection: Collection) { description: collection.description, icon: collection.icon, color: collection.color || "#4E5C6E", - type: collection.type, private: collection.private, createdAt: collection.createdAt, updatedAt: collection.updatedAt, @@ -34,10 +33,8 @@ export default function present(collection: Collection) { documents: undefined, }; - if (collection.type === "atlas") { - // Force alphabetical sorting - data.documents = sortDocuments(collection.documentStructure); - } + // Force alphabetical sorting + data.documents = sortDocuments(collection.documentStructure); return data; } diff --git a/server/test/factories.js b/server/test/factories.js index ed8afb37c..e5ddc2c21 100644 --- a/server/test/factories.js +++ b/server/test/factories.js @@ -85,7 +85,6 @@ export async function buildCollection(overrides: Object = {}) { name: `Test Collection ${count}`, description: "Test collection description", creatorId: overrides.userId, - type: "atlas", ...overrides, }); } diff --git a/server/test/support.js b/server/test/support.js index e163ac06d..15389e5c4 100644 --- a/server/test/support.js +++ b/server/test/support.js @@ -60,7 +60,6 @@ const seed = async () => { urlId: "collection", teamId: team.id, creatorId: user.id, - type: "atlas", }); const document = await Document.create({