mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added offers
table (#13381)
refs https://github.com/TryGhost/Team/issues/1088 - adds schema for new offers table - adds permission fixtures for new offers table - adds migrations for new table and permissions Co-authored-by: Fabien O'Carroll <fabien@allou.is>
This commit is contained in:
parent
64124b9cea
commit
c4cfd1839a
9 changed files with 110 additions and 11 deletions
|
@ -36,7 +36,8 @@ const BACKUP_TABLES = [
|
|||
'members_status_events',
|
||||
'members_paid_subscription_events',
|
||||
'members_subscribe_events',
|
||||
'members_product_events'
|
||||
'members_product_events',
|
||||
'offers'
|
||||
];
|
||||
|
||||
// NOTE: exposing only tables which are going to be included in a "default" export file
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
const utils = require('../../utils');
|
||||
|
||||
module.exports = utils.addTable('offers', {
|
||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||
code: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
|
||||
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
|
||||
interval: {type: 'string', maxlength: 50, nullable: false},
|
||||
currency: {type: 'string', maxlength: 50, nullable: true},
|
||||
discount_type: {type: 'string', maxlength: 50, nullable: false},
|
||||
discount_amount: {type: 'integer', nullable: false},
|
||||
duration: {type: 'string', maxlength: 50, nullable: false},
|
||||
duration_in_months: {type: 'integer', nullable: true},
|
||||
portal_title: {type: 'string', maxlength: 191, nullable: false},
|
||||
portal_description: {type: 'string', maxlength: 2000, nullable: true},
|
||||
created_at: {type: 'dateTime', nullable: false},
|
||||
updated_at: {type: 'dateTime', nullable: true}
|
||||
});
|
|
@ -0,0 +1,35 @@
|
|||
const {
|
||||
addPermissionWithRoles,
|
||||
combineTransactionalMigrations
|
||||
} = require('../../utils');
|
||||
|
||||
module.exports = combineTransactionalMigrations(
|
||||
addPermissionWithRoles({
|
||||
name: 'Browse offers',
|
||||
action: 'browse',
|
||||
object: 'offer'
|
||||
}, [
|
||||
'Administrator'
|
||||
]),
|
||||
addPermissionWithRoles({
|
||||
name: 'Read offers',
|
||||
action: 'read',
|
||||
object: 'offer'
|
||||
}, [
|
||||
'Administrator'
|
||||
]),
|
||||
addPermissionWithRoles({
|
||||
name: 'Edit offers',
|
||||
action: 'edit',
|
||||
object: 'offer'
|
||||
}, [
|
||||
'Administrator'
|
||||
]),
|
||||
addPermissionWithRoles({
|
||||
name: 'Add offers',
|
||||
action: 'add',
|
||||
object: 'offer'
|
||||
}, [
|
||||
'Administrator'
|
||||
])
|
||||
);
|
|
@ -487,6 +487,26 @@
|
|||
"action_type": "destroy",
|
||||
"object_type": "snippet"
|
||||
},
|
||||
{
|
||||
"name": "Browse offers",
|
||||
"action_type": "browse",
|
||||
"object_type": "offer"
|
||||
},
|
||||
{
|
||||
"name": "Read offers",
|
||||
"action_type": "read",
|
||||
"object_type": "offer"
|
||||
},
|
||||
{
|
||||
"name": "Edit offers",
|
||||
"action_type": "edit",
|
||||
"object_type": "offer"
|
||||
},
|
||||
{
|
||||
"name": "Add offers",
|
||||
"action_type": "add",
|
||||
"object_type": "offer"
|
||||
},
|
||||
{
|
||||
"name": "Reset all passwords",
|
||||
"action_type": "resetAllPasswords",
|
||||
|
@ -749,6 +769,7 @@
|
|||
"member_signin_url": "read",
|
||||
"snippet": "all",
|
||||
"custom_theme_setting": "all",
|
||||
"offer": "all",
|
||||
"authentication": "resetAllPasswords",
|
||||
"members_stripe_connect": "auth"
|
||||
},
|
||||
|
|
|
@ -384,6 +384,23 @@ module.exports = {
|
|||
created_at: {type: 'dateTime', nullable: false},
|
||||
updated_at: {type: 'dateTime', nullable: true}
|
||||
},
|
||||
offers: {
|
||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||
name: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||
code: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||
product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
|
||||
stripe_coupon_id: {type: 'string', maxlength: 255, nullable: false, unique: true},
|
||||
interval: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['month', 'year']]}},
|
||||
currency: {type: 'string', maxlength: 50, nullable: true},
|
||||
discount_type: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['percent', 'amount']]}},
|
||||
discount_amount: {type: 'integer', nullable: false},
|
||||
duration: {type: 'string', maxlength: 50, nullable: false},
|
||||
duration_in_months: {type: 'integer', nullable: true},
|
||||
portal_title: {type: 'string', maxlength: 191, nullable: false},
|
||||
portal_description: {type: 'string', maxlength: 2000, nullable: true},
|
||||
created_at: {type: 'dateTime', nullable: false},
|
||||
updated_at: {type: 'dateTime', nullable: true}
|
||||
},
|
||||
benefits: {
|
||||
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||
name: {type: 'string', maxlength: 191, nullable: false},
|
||||
|
|
|
@ -49,6 +49,7 @@ describe('Exporter', function () {
|
|||
'migrations_lock',
|
||||
'mobiledoc_revisions',
|
||||
'oauth',
|
||||
'offers',
|
||||
'permissions',
|
||||
'permissions_roles',
|
||||
'permissions_users',
|
||||
|
|
|
@ -45,7 +45,7 @@ describe('Database Migration (special functions)', function () {
|
|||
const permissions = this.obj;
|
||||
|
||||
// If you have to change this number, please add the relevant `havePermission` checks below
|
||||
permissions.length.should.eql(88);
|
||||
permissions.length.should.eql(92);
|
||||
|
||||
permissions.should.havePermission('Export database', ['Administrator', 'DB Backup Integration']);
|
||||
permissions.should.havePermission('Import database', ['Administrator', 'DB Backup Integration']);
|
||||
|
@ -147,6 +147,11 @@ describe('Database Migration (special functions)', function () {
|
|||
permissions.should.havePermission('Add Members');
|
||||
permissions.should.havePermission('Delete Members');
|
||||
|
||||
permissions.should.havePermission('Browse offers', ['Administrator']);
|
||||
permissions.should.havePermission('Read offers', ['Administrator']);
|
||||
permissions.should.havePermission('Edit offers', ['Administrator']);
|
||||
permissions.should.havePermission('Add offers', ['Administrator']);
|
||||
|
||||
permissions.should.havePermission('Browse Products', ['Administrator', 'Editor', 'Author']);
|
||||
permissions.should.havePermission('Read Products', ['Administrator', 'Editor', 'Author']);
|
||||
permissions.should.havePermission('Edit Products', ['Administrator']);
|
||||
|
@ -214,7 +219,7 @@ describe('Database Migration (special functions)', function () {
|
|||
result.roles.at(7).get('name').should.eql('Scheduler Integration');
|
||||
|
||||
// Permissions
|
||||
result.permissions.length.should.eql(88);
|
||||
result.permissions.length.should.eql(92);
|
||||
result.permissions.toJSON().should.be.CompletePermissions();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -160,18 +160,18 @@ describe('Migration Fixture Utils', function () {
|
|||
fixtureUtils.addFixturesForRelation(fixtures.relations[0]).then(function (result) {
|
||||
should.exist(result);
|
||||
result.should.be.an.Object();
|
||||
result.should.have.property('expected', 81);
|
||||
result.should.have.property('done', 81);
|
||||
result.should.have.property('expected', 82);
|
||||
result.should.have.property('done', 82);
|
||||
|
||||
// Permissions & Roles
|
||||
permsAllStub.calledOnce.should.be.true();
|
||||
rolesAllStub.calledOnce.should.be.true();
|
||||
dataMethodStub.filter.callCount.should.eql(81);
|
||||
dataMethodStub.filter.callCount.should.eql(82);
|
||||
dataMethodStub.find.callCount.should.eql(7);
|
||||
baseUtilAttachStub.callCount.should.eql(81);
|
||||
baseUtilAttachStub.callCount.should.eql(82);
|
||||
|
||||
fromItem.related.callCount.should.eql(81);
|
||||
fromItem.find.callCount.should.eql(81);
|
||||
fromItem.related.callCount.should.eql(82);
|
||||
fromItem.find.callCount.should.eql(82);
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
|
|
|
@ -32,8 +32,8 @@ const defaultSettings = require('../../../../core/server/data/schema/default-set
|
|||
*/
|
||||
describe('DB version integrity', function () {
|
||||
// Only these variables should need updating
|
||||
const currentSchemaHash = '66e58a7b9081ccf78ac539a527f27332';
|
||||
const currentFixturesHash = '1b842814f2b02ab8831c7e9c139d186e';
|
||||
const currentSchemaHash = 'c1c45b460f39504a01b26fcd7a62f395';
|
||||
const currentFixturesHash = '74bec16459c86486a1ca76665eca0926';
|
||||
const currentSettingsHash = 'aa3fcbc8ab119b630aeda7366ead5493';
|
||||
const currentRoutesHash = '3d180d52c663d173a6be791ef411ed01';
|
||||
|
||||
|
|
Loading…
Reference in a new issue