Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Add v2.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
YannickRe committed Feb 7, 2019
1 parent 1c7c283 commit fec7ba9
Show file tree
Hide file tree
Showing 73 changed files with 1,338 additions and 587 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions core/server/analytics-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ module.exports.init = function () {
toTrack = [
{
event: 'post.published',
name: 'Blog Post Published'
name: 'Post Published'
},
{
event: 'page.published',
name: 'Blog Page Published'
name: 'Page Published'
},
{
event: 'theme.uploaded',
name: 'Theme Uploaded'
}
];

Expand Down
4 changes: 3 additions & 1 deletion core/server/api/shared/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const http = (apiImpl) => {
id: req.api_key.get('id'),
type: req.api_key.get('type')
};
integration = req.api_key.get('integration_id');
integration = {
id: req.api_key.get('integration_id')
};
}

if ((req.user && req.user.id) || (req.user && models.User.isExternalUser(req.user.id))) {
Expand Down
2 changes: 2 additions & 0 deletions core/server/api/v0.1/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ themes = {
themeUtils.activate(loadedTheme, checkedTheme);
}

common.events.emit('theme.uploaded');

// @TODO: unify the name across gscan and Ghost!
return themeUtils.toJSON(zip.shortName, checkedTheme);
})
Expand Down
38 changes: 38 additions & 0 deletions core/server/api/v2/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const models = require('../../models');

module.exports = {
docName: 'actions',

browse: {
options: [
'page',
'limit',
'fields'
],
data: [
'id',
'type'
],
validation: {
id: {
required: true
},
type: {
required: true,
values: ['resource', 'actor']
}
},
permissions: true,
query(frame) {
if (frame.data.type === 'resource') {
frame.options.withRelated = ['actor'];
frame.options.filter = `resource_id:${frame.data.id}`;
} else {
frame.options.withRelated = ['resource'];
frame.options.filter = `actor_id:${frame.data.id}`;
}

return models.Action.findPage(frame.options);
}
}
};
4 changes: 4 additions & 0 deletions core/server/api/v2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,9 @@ module.exports = {

get themes() {
return shared.pipeline(require('./themes'), localUtils);
},

get actions() {
return shared.pipeline(require('./actions'), localUtils);
}
};
2 changes: 2 additions & 0 deletions core/server/api/v2/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ module.exports = {
this.headers.cacheInvalidate = true;
}

common.events.emit('theme.uploaded');

// @TODO: unify the name across gscan and Ghost!
return themeService.toJSON(zip.shortName, checkedTheme);
})
Expand Down
15 changes: 15 additions & 0 deletions core/server/api/v2/utils/serializers/output/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const debug = require('ghost-ignition').debug('api:v2:utils:serializers:output:actions');
const mapper = require('./utils/mapper');

module.exports = {
browse(models, apiConfig, frame) {
debug('browse');

frame.response = {
actions: models.data.map(model => mapper.mapAction(model, frame)),
meta: models.meta
};

debug(frame.response);
}
};
4 changes: 4 additions & 0 deletions core/server/api/v2/utils/serializers/output/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,9 @@ module.exports = {

get themes() {
return require('./themes');
},

get actions() {
return require('./actions');
}
};
27 changes: 27 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/clean.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const _ = require('lodash');
const localUtils = require('../../../index');

const tag = (attrs) => {
Expand Down Expand Up @@ -98,6 +99,32 @@ const post = (attrs, frame) => {
return attrs;
};

const action = (attrs) => {
if (attrs.actor) {
delete attrs.actor_id;
delete attrs.resource_id;

if (attrs.actor_type === 'user') {
attrs.actor = _.pick(attrs.actor, ['id', 'name', 'slug', 'profile_image']);
attrs.actor.image = attrs.actor.profile_image;
delete attrs.actor.profile_image;
} else {
attrs.actor = _.pick(attrs.actor, ['id', 'name', 'slug', 'icon_image']);
attrs.actor.image = attrs.actor.icon_image;
delete attrs.actor.icon_image;
}
} else if (attrs.resource) {
delete attrs.actor_id;
delete attrs.resource_id;

// @NOTE: we only support posts right now
attrs.resource = _.pick(attrs.resource, ['id', 'title', 'slug', 'feature_image']);
attrs.resource.image = attrs.resource.feature_image;
delete attrs.resource.feature_image;
}
};

module.exports.post = post;
module.exports.tag = tag;
module.exports.author = author;
module.exports.action = action;
7 changes: 7 additions & 0 deletions core/server/api/v2/utils/serializers/output/utils/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,16 @@ const mapImage = (path) => {
return url.forImage(path);
};

const mapAction = (model, frame) => {
const attrs = model.toJSON(frame.options);
clean.action(attrs);
return attrs;
};

module.exports.mapPost = mapPost;
module.exports.mapUser = mapUser;
module.exports.mapTag = mapTag;
module.exports.mapIntegration = mapIntegration;
module.exports.mapSettings = mapSettings;
module.exports.mapImage = mapImage;
module.exports.mapAction = mapAction;
3 changes: 3 additions & 0 deletions core/server/config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"scheduling": {
"active": "SchedulingDefault"
},
"members": {
"paymentProcessors": []
},
"logging": {
"level": "info",
"rotation": {
Expand Down
35 changes: 35 additions & 0 deletions core/server/data/migrations/versions/2.14/1-add-actions-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const common = require('../../../../lib/common');
const commands = require('../../../schema').commands;
const table = 'actions';
const message1 = `Adding table: ${table}`;
const message2 = `Dropping table: ${table}`;

module.exports.up = (options) => {
const connection = options.connection;

return connection.schema.hasTable(table)
.then(function (exists) {
if (exists) {
common.logging.warn(message1);
return;
}

common.logging.info(message1);
return commands.createTable(table, connection);
});
};

module.exports.down = (options) => {
const connection = options.connection;

return connection.schema.hasTable(table)
.then(function (exists) {
if (!exists) {
common.logging.warn(message2);
return;
}

common.logging.info(message2);
return commands.deleteTable(table, connection);
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const _ = require('lodash');
const utils = require('../../../schema/fixtures/utils');
const permissions = require('../../../../services/permissions');
const common = require('../../../../lib/common');
const resource = 'action';
const _private = {};

_private.getPermissions = function getPermissions() {
return utils.findModelFixtures('Permission', {object_type: resource});
};

_private.getRelations = function getRelations() {
return utils.findPermissionRelationsForObject(resource);
};

_private.printResult = function printResult(result, message) {
if (result.done === result.expected) {
common.logging.info(message);
} else {
common.logging.warn('(' + result.done + '/' + result.expected + ') ' + message);
}
};

module.exports.config = {
transaction: true
};

module.exports.up = function addRedirectsPermissions(options) {
const modelToAdd = _private.getPermissions();
const relationToAdd = _private.getRelations();
const localOptions = _.merge({
context: {
internal: true,
migrating: true
}
}, options);

return utils.addFixturesForModel(modelToAdd, localOptions)
.then(function (result) {
_private.printResult(result, 'Adding permissions fixtures for ' + resource + 's');
return utils.addFixturesForRelation(relationToAdd, localOptions);
})
.then(function (result) {
_private.printResult(result, 'Adding permissions_roles fixtures for ' + resource + 's');
return permissions.init(localOptions);
});
};
11 changes: 9 additions & 2 deletions core/server/data/schema/fixtures/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,11 @@
"name": "Delete API keys",
"action_type": "destroy",
"object_type": "api_key"
},
{
"name": "Browse Actions",
"action_type": "browse",
"object_type": "action"
}
]
},
Expand Down Expand Up @@ -559,7 +564,8 @@
"redirect": "all",
"webhook": "all",
"integration": "all",
"api_key": "all"
"api_key": "all",
"action": "all"
},
"Admin Integration": {
"mail": "all",
Expand All @@ -575,7 +581,8 @@
"subscriber": "all",
"invite": "all",
"redirect": "all",
"webhook": "all"
"webhook": "all",
"action": "all"
},
"Editor": {
"post": "all",
Expand Down
13 changes: 13 additions & 0 deletions core/server/data/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,5 +383,18 @@ module.exports = {
created_by: {type: 'string', maxlength: 24, nullable: false},
updated_at: {type: 'dateTime', nullable: true},
updated_by: {type: 'string', maxlength: 24, nullable: true}
},
actions: {
id: {type: 'string', maxlength: 24, nullable: false, primary: true},
resource_id: {type: 'string', maxlength: 24, nullable: true},
resource_type: {type: 'string', maxlength: 50, nullable: false},
actor_id: {type: 'string', maxlength: 24, nullable: false},
actor_type: {type: 'string', maxlength: 50, nullable: false},
// @NOTE: The event column contains short buzzwords e.g. subscribed, started, added, deleted, edited etc.
// We already store and require the target resource type. No need to remember e.g. post.edited
event: {type: 'string', maxlength: 50, nullable: false},
// @NOTE: The context object can be used to store information about an action e.g. diffs, meta
context: {type: 'text', maxlength: 1000000000, nullable: true},
created_at: {type: 'dateTime', nullable: false}
}
};
4 changes: 2 additions & 2 deletions core/server/lib/members/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function cookies(sessionSecret) {
function setCookie(member) {
return cookie.serialize('signedin', member.id, {
maxAge: MAX_AGE,
path: '/ghost/api/v2/members/token',
path: '/ghost/api/v2/members',
httpOnly: true,
encode: encodeCookie
});
Expand All @@ -32,7 +32,7 @@ module.exports = function cookies(sessionSecret) {
function removeCookie() {
return cookie.serialize('signedin', false, {
maxAge: 0,
path: '/ghost/api/v2/members/token',
path: '/ghost/api/v2/members',
httpOnly: true
});
}
Expand Down
Loading

0 comments on commit fec7ba9

Please sign in to comment.