From 1fabd76391d5b9504e8a0d20af5341ec844d9981 Mon Sep 17 00:00:00 2001 From: Matt Hanley Date: Thu, 12 May 2022 11:32:30 +0100 Subject: [PATCH] Added newsletter permissions for Editors and Authors refs https://github.com/TryGhost/Team/issues/1618 - Editors and Authors require read access to newsletters as part of the publish + send workflow --- ...ter-permissions-for-editors-and-authors.js | 20 +++++++++++++++++++ .../server/data/schema/fixtures/fixtures.json | 6 ++++-- test/integration/migrations/migration.test.js | 4 ++-- .../schema/fixtures/fixture-manager.test.js | 12 +++++------ .../unit/server/data/schema/integrity.test.js | 2 +- test/utils/fixtures/fixtures.json | 6 ++++-- 6 files changed, 37 insertions(+), 13 deletions(-) create mode 100644 core/server/data/migrations/versions/5.0/2022-05-12-10-29-add-newsletter-permissions-for-editors-and-authors.js diff --git a/core/server/data/migrations/versions/5.0/2022-05-12-10-29-add-newsletter-permissions-for-editors-and-authors.js b/core/server/data/migrations/versions/5.0/2022-05-12-10-29-add-newsletter-permissions-for-editors-and-authors.js new file mode 100644 index 0000000000..2ce01bd3dc --- /dev/null +++ b/core/server/data/migrations/versions/5.0/2022-05-12-10-29-add-newsletter-permissions-for-editors-and-authors.js @@ -0,0 +1,20 @@ +const {combineTransactionalMigrations, addPermissionToRole} = require('../../utils'); + +module.exports = combineTransactionalMigrations( + addPermissionToRole({ + permission: 'Browse newsletters', + role: 'Editor' + }), + addPermissionToRole({ + permission: 'Read newsletters', + role: 'Editor' + }), + addPermissionToRole({ + permission: 'Browse newsletters', + role: 'Author' + }), + addPermissionToRole({ + permission: 'Read newsletters', + role: 'Author' + }) +); diff --git a/core/server/data/schema/fixtures/fixtures.json b/core/server/data/schema/fixtures/fixtures.json index e7b8b2c290..3ed75c20a9 100644 --- a/core/server/data/schema/fixtures/fixtures.json +++ b/core/server/data/schema/fixtures/fixtures.json @@ -723,7 +723,8 @@ "email": "all", "snippet": "all", "label": ["browse", "read"], - "product": ["browse", "read"] + "product": ["browse", "read"], + "newsletter": ["browse", "read"] }, "Author": { "post": ["browse", "read", "add"], @@ -736,7 +737,8 @@ "email_preview": "read", "email": "read", "snippet": ["browse", "read"], - "product": ["browse", "read"] + "product": ["browse", "read"], + "newsletter": ["browse", "read"] }, "Contributor": { "post": ["browse", "read", "add"], diff --git a/test/integration/migrations/migration.test.js b/test/integration/migrations/migration.test.js index db2b690ae8..7df233c6fa 100644 --- a/test/integration/migrations/migration.test.js +++ b/test/integration/migrations/migration.test.js @@ -163,8 +163,8 @@ describe('Database Migration (special functions)', function () { permissions.should.havePermission('Browse custom theme settings', ['Administrator']); permissions.should.havePermission('Edit custom theme settings', ['Administrator']); - permissions.should.havePermission('Browse newsletters', ['Administrator', 'Admin Integration']); - permissions.should.havePermission('Read newsletters', ['Administrator', 'Admin Integration']); + permissions.should.havePermission('Browse newsletters', ['Administrator', 'Editor', 'Author', 'Admin Integration']); + permissions.should.havePermission('Read newsletters', ['Administrator', 'Editor', 'Author', 'Admin Integration']); permissions.should.havePermission('Edit newsletters', ['Administrator', 'Admin Integration']); permissions.should.havePermission('Add newsletters', ['Administrator', 'Admin Integration']); }); diff --git a/test/unit/server/data/schema/fixtures/fixture-manager.test.js b/test/unit/server/data/schema/fixtures/fixture-manager.test.js index 4a880745ee..eb8783c752 100644 --- a/test/unit/server/data/schema/fixtures/fixture-manager.test.js +++ b/test/unit/server/data/schema/fixtures/fixture-manager.test.js @@ -201,18 +201,18 @@ describe('Migration Fixture Utils', function () { fixtureManager.addFixturesForRelation(fixtures.relations[0]).then(function (result) { should.exist(result); result.should.be.an.Object(); - result.should.have.property('expected', 86); - result.should.have.property('done', 86); + result.should.have.property('expected', 88); + result.should.have.property('done', 88); // Permissions & Roles permsAllStub.calledOnce.should.be.true(); rolesAllStub.calledOnce.should.be.true(); - dataMethodStub.filter.callCount.should.eql(86); + dataMethodStub.filter.callCount.should.eql(88); dataMethodStub.find.callCount.should.eql(7); - baseUtilAttachStub.callCount.should.eql(86); + baseUtilAttachStub.callCount.should.eql(88); - fromItem.related.callCount.should.eql(86); - fromItem.find.callCount.should.eql(86); + fromItem.related.callCount.should.eql(88); + fromItem.find.callCount.should.eql(88); done(); }).catch(done); diff --git a/test/unit/server/data/schema/integrity.test.js b/test/unit/server/data/schema/integrity.test.js index 224f322226..f3100afe6a 100644 --- a/test/unit/server/data/schema/integrity.test.js +++ b/test/unit/server/data/schema/integrity.test.js @@ -36,7 +36,7 @@ const validateRouteSettings = require('../../../../../core/server/services/route describe('DB version integrity', function () { // Only these variables should need updating const currentSchemaHash = '2f4266e6e5087ad92dd30f3e721d46e5'; - const currentFixturesHash = 'f4795020369ec3a770b538be8d8b2536'; + const currentFixturesHash = '2219972fb91a30f8d740e05afd3a033c'; const currentSettingsHash = 'ffd899a82b0ad2886e92d8244bcbca6a'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01'; diff --git a/test/utils/fixtures/fixtures.json b/test/utils/fixtures/fixtures.json index a8207575ed..21ef0a5888 100644 --- a/test/utils/fixtures/fixtures.json +++ b/test/utils/fixtures/fixtures.json @@ -896,7 +896,8 @@ "email": "all", "snippet": "all", "label": ["browse", "read"], - "product": ["browse", "read"] + "product": ["browse", "read"], + "newsletter": ["browse", "read"] }, "Author": { "post": ["browse", "read", "add"], @@ -909,7 +910,8 @@ "email_preview": "read", "email": "read", "snippet": ["browse", "read"], - "product": ["browse", "read"] + "product": ["browse", "read"], + "newsletter": ["browse", "read"] }, "Contributor": { "post": ["browse", "read", "add"],