From f9aa18a534edd8ea6e4f797c0720effe2159b87f Mon Sep 17 00:00:00 2001 From: Rishabh Garg Date: Wed, 16 Mar 2022 16:46:26 +0530 Subject: [PATCH] Enabled Admin integration for tiers and offers API (#14325) As multiple tiers is now GA, we want to allow devs to be able to work with Tiers and offers via content/Admin API. This change - - updates fixtures to add permissions to admin integration role for new sites - adds migration to update existing sites to have correct permissions for role - whitelists add/edit/read/browse on tiers and offers API for integrations --- ...fers-admin-integration-permission-roles.js | 23 +++++++++++++++++++ ...iers-admin-integration-permission-roles.js | 20 ++++++++++++++++ .../server/data/schema/fixtures/fixtures.json | 4 +++- .../server/web/api/canary/admin/middleware.js | 2 ++ .../unit/server/data/schema/integrity.test.js | 2 +- 5 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-offers-admin-integration-permission-roles.js create mode 100644 core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-tiers-admin-integration-permission-roles.js diff --git a/core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-offers-admin-integration-permission-roles.js b/core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-offers-admin-integration-permission-roles.js new file mode 100644 index 0000000000..4d1316831d --- /dev/null +++ b/core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-offers-admin-integration-permission-roles.js @@ -0,0 +1,23 @@ +const { + combineTransactionalMigrations, + addPermissionToRole +} = require('../../utils'); + +module.exports = combineTransactionalMigrations( + addPermissionToRole({ + permission: 'Browse offers', + role: 'Admin Integration' + }), + addPermissionToRole({ + permission: 'Read offers', + role: 'Admin Integration' + }), + addPermissionToRole({ + permission: 'Edit offers', + role: 'Admin Integration' + }), + addPermissionToRole({ + permission: 'Add offers', + role: 'Admin Integration' + }) +); diff --git a/core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-tiers-admin-integration-permission-roles.js b/core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-tiers-admin-integration-permission-roles.js new file mode 100644 index 0000000000..78c6a9f0e0 --- /dev/null +++ b/core/server/data/migrations/versions/4.40/2022-03-15-06-40-add-tiers-admin-integration-permission-roles.js @@ -0,0 +1,20 @@ +const {combineTransactionalMigrations, addPermissionToRole} = require('../../utils'); + +module.exports = combineTransactionalMigrations( + addPermissionToRole({ + permission: 'Browse Products', + role: 'Admin Integration' + }), + addPermissionToRole({ + permission: 'Read Products', + role: 'Admin Integration' + }), + addPermissionToRole({ + permission: 'Edit Products', + role: 'Admin Integration' + }), + addPermissionToRole({ + permission: 'Add Products', + role: 'Admin Integration' + }) +); diff --git a/core/server/data/schema/fixtures/fixtures.json b/core/server/data/schema/fixtures/fixtures.json index 307e57edb3..d4697ec20b 100644 --- a/core/server/data/schema/fixtures/fixtures.json +++ b/core/server/data/schema/fixtures/fixtures.json @@ -668,7 +668,9 @@ "label": "all", "email_preview": "all", "email": "all", - "snippet": "all" + "snippet": "all", + "product": ["browse", "read", "add", "edit"], + "offer": ["browse", "read", "add", "edit"] }, "Editor": { "notification": "all", diff --git a/core/server/web/api/canary/admin/middleware.js b/core/server/web/api/canary/admin/middleware.js index f24842a660..37d5ef6909 100644 --- a/core/server/web/api/canary/admin/middleware.js +++ b/core/server/web/api/canary/admin/middleware.js @@ -29,6 +29,8 @@ const notImplemented = function (req, res, next) { users: ['GET'], themes: ['POST', 'PUT'], members: ['GET', 'PUT', 'DELETE', 'POST'], + tiers: ['GET', 'PUT', 'POST'], + offers: ['GET', 'PUT', 'POST'], config: ['GET'], schedules: ['PUT'], files: ['POST'], diff --git a/test/unit/server/data/schema/integrity.test.js b/test/unit/server/data/schema/integrity.test.js index 3a0e80d1e2..1414695916 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 = 'b7867be4de694b4592d748c0367064b5'; - const currentFixturesHash = '84be2bb1d62b384260b72ebfc20f81dc'; + const currentFixturesHash = 'f4dd2a454e1999b6d149cc26ae52ced4'; const currentSettingsHash = '71fa38d0c805c18ceebe0fda80886230'; const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';