diff --git a/server/api/collections.js b/server/api/collections.js index d5a139f34..99f2394f5 100644 --- a/server/api/collections.js +++ b/server/api/collections.js @@ -53,7 +53,7 @@ router.post("collections.create", auth(), async (ctx) => { icon, color, teamId: user.teamId, - creatorId: user.id, + createdById: user.id, private: isPrivate, sort, }); diff --git a/server/api/collections.test.js b/server/api/collections.test.js index a0b26e119..d713fa686 100644 --- a/server/api/collections.test.js +++ b/server/api/collections.test.js @@ -1109,7 +1109,7 @@ describe("#collections.delete", () => { // to ensure it isn't the last collection await buildCollection({ teamId: user.teamId, - creatorId: user.id, + createdById: user.id, }); const res = await server.post("/api/collections.delete", { @@ -1127,7 +1127,7 @@ describe("#collections.delete", () => { // to ensure it isn't the last collection await buildCollection({ teamId: user.teamId, - creatorId: user.id, + createdById: user.id, }); // archived document should not be deleted diff --git a/server/commands/documentMover.test.js b/server/commands/documentMover.test.js index bee447d67..a006a5b49 100644 --- a/server/commands/documentMover.test.js +++ b/server/commands/documentMover.test.js @@ -28,7 +28,7 @@ describe("documentMover", () => { parentDocumentId: document.id, collectionId: collection.id, teamId: collection.teamId, - userId: collection.creatorId, + userId: collection.createdById, title: "Child document", text: "content", }); @@ -59,7 +59,7 @@ describe("documentMover", () => { parentDocumentId: document.id, collectionId: collection.id, teamId: collection.teamId, - userId: collection.creatorId, + userId: collection.createdById, title: "Child document", text: "content", }); diff --git a/server/migrations/20210110143902-collection-rename-creator-id.js b/server/migrations/20210110143902-collection-rename-creator-id.js new file mode 100644 index 000000000..762f51847 --- /dev/null +++ b/server/migrations/20210110143902-collection-rename-creator-id.js @@ -0,0 +1,19 @@ +"use strict"; + +module.exports = { + up: async (queryInterface, Sequelize) => { + return queryInterface.renameColumn( + "collections", + "creatorId", + "createdById" + ); + }, + + down: async (queryInterface, Sequelize) => { + return queryInterface.renameColumn( + "collections", + "createdById", + "creatorId" + ); + }, +}; diff --git a/server/models/Collection.js b/server/models/Collection.js index c14b361e0..f72a67fcd 100644 --- a/server/models/Collection.js +++ b/server/models/Collection.js @@ -103,7 +103,7 @@ Collection.associate = (models) => { }); Collection.belongsTo(models.User, { as: "user", - foreignKey: "creatorId", + foreignKey: "createdById", }); Collection.belongsTo(models.Team, { as: "team", @@ -194,11 +194,11 @@ Collection.addHook("afterCreate", (model: Collection, options) => { return CollectionUser.findOrCreate({ where: { collectionId: model.id, - userId: model.creatorId, + userId: model.createdById, }, defaults: { permission: "read_write", - createdById: model.creatorId, + createdById: model.createdById, }, transaction: options.transaction, }); diff --git a/server/models/Collection.test.js b/server/models/Collection.test.js index 17e866359..c217e83e9 100644 --- a/server/models/Collection.test.js +++ b/server/models/Collection.test.js @@ -131,9 +131,9 @@ describe("#updateDocument", () => { parentDocumentId: document.id, collectionId: collection.id, teamId: collection.teamId, - userId: collection.creatorId, - lastModifiedById: collection.creatorId, - createdById: collection.creatorId, + userId: collection.createdById, + lastModifiedById: collection.createdById, + createdById: collection.createdById, title: "Child document", text: "content", }); @@ -184,9 +184,9 @@ describe("#removeDocument", () => { parentDocumentId: document.id, collectionId: collection.id, teamId: collection.teamId, - userId: collection.creatorId, - lastModifiedById: collection.creatorId, - createdById: collection.creatorId, + userId: collection.createdById, + lastModifiedById: collection.createdById, + createdById: collection.createdById, title: "Child document", text: "content", }); @@ -212,9 +212,9 @@ describe("#removeDocument", () => { parentDocumentId: document.id, collectionId: collection.id, teamId: collection.teamId, - userId: collection.creatorId, - lastModifiedById: collection.creatorId, - createdById: collection.creatorId, + userId: collection.createdById, + lastModifiedById: collection.createdById, + createdById: collection.createdById, publishedAt: new Date(), title: "Child document", text: "content", diff --git a/server/models/Team.js b/server/models/Team.js index 2e86971ae..4faf6d5c3 100644 --- a/server/models/Team.js +++ b/server/models/Team.js @@ -144,7 +144,7 @@ Team.prototype.provisionFirstCollection = async function (userId) { 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!", teamId: this.id, - creatorId: userId, + createdById: userId, sort: Collection.DEFAULT_SORT, }); @@ -175,9 +175,9 @@ Team.prototype.provisionFirstCollection = async function (userId) { parentDocumentId: null, collectionId: collection.id, teamId: collection.teamId, - userId: collection.creatorId, - lastModifiedById: collection.creatorId, - createdById: collection.creatorId, + userId: collection.createdById, + lastModifiedById: collection.createdById, + createdById: collection.createdById, title, text, }); diff --git a/server/policies/collection.js b/server/policies/collection.js index e0fc7c1dc..37abacacd 100644 --- a/server/policies/collection.js +++ b/server/policies/collection.js @@ -72,7 +72,7 @@ allow(User, "delete", Collection, (user, collection) => { } if (user.isAdmin) return true; - if (user.id === collection.creatorId) return true; + if (user.id === collection.createdById) return true; throw new AdminRequiredError(); }); diff --git a/server/test/factories.js b/server/test/factories.js index 01c4c8c15..02ff43696 100644 --- a/server/test/factories.js +++ b/server/test/factories.js @@ -113,7 +113,7 @@ export async function buildCollection(overrides: Object = {}) { return Collection.create({ name: `Test Collection ${count}`, description: "Test collection description", - creatorId: overrides.userId, + createdById: overrides.userId, ...overrides, }); } diff --git a/server/test/support.js b/server/test/support.js index 64be6bd51..4fd1125ca 100644 --- a/server/test/support.js +++ b/server/test/support.js @@ -61,16 +61,16 @@ const seed = async () => { name: "Collection", urlId: "collection", teamId: team.id, - creatorId: user.id, + createdById: user.id, }); const document = await Document.create({ parentDocumentId: null, collectionId: collection.id, teamId: team.id, - userId: collection.creatorId, - lastModifiedById: collection.creatorId, - createdById: collection.creatorId, + userId: collection.createdById, + lastModifiedById: collection.createdById, + createdById: collection.createdById, title: "First ever document", text: "# Much test support", });