mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
2fd4cbb93b
refs #10431 - added v2 endpoint with browse permissions - context.integration was never accessible in the model layer - why? https://github.com/TryGhost/Ghost/issues/10099
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
/**
|
|
* Parse Context
|
|
*
|
|
* Utility function, to expand strings out into objects.
|
|
* @param {Object|String} context
|
|
* @return {{internal: boolean, external: boolean, user: integer|null, app: integer|null, public: boolean, api_key: Object|null}}
|
|
*/
|
|
module.exports = function parseContext(context) {
|
|
// Parse what's passed to canThis.beginCheck for standard user and app scopes
|
|
var parsed = {
|
|
internal: false,
|
|
external: false,
|
|
user: null,
|
|
api_key: null,
|
|
app: null,
|
|
integration: null,
|
|
public: true
|
|
};
|
|
|
|
// NOTE: We use the `external` context for subscribers only at the moment.
|
|
if (context && (context === 'external' || context.external)) {
|
|
parsed.external = true;
|
|
parsed.public = false;
|
|
}
|
|
|
|
if (context && (context === 'internal' || context.internal)) {
|
|
parsed.internal = true;
|
|
parsed.public = false;
|
|
}
|
|
|
|
if (context && context.user) {
|
|
parsed.user = context.user;
|
|
parsed.public = false;
|
|
}
|
|
|
|
if (context && context.api_key) {
|
|
parsed.api_key = context.api_key;
|
|
parsed.integration = context.integration;
|
|
parsed.public = (context.api_key.type === 'content');
|
|
}
|
|
|
|
if (context && context.app) {
|
|
parsed.app = context.app;
|
|
parsed.public = false;
|
|
}
|
|
|
|
return parsed;
|
|
};
|