0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-17 23:44:39 -05:00
ghost/core/server/services/permissions/parse-context.js
Hannah Wolfe 8c1a0b8d0c Remove External Apps
- Apps are marked as removed in 3.0, never officially launched and have been deprecated for at least 2 years.
- We've slowly removed bits that got in our way or were insecure over time meaning they mostly didn't work
- This cleans up the remainder of the logic
- The tables should be cleaned up in a future major
2020-03-20 10:40:22 +00:00

41 lines
1.1 KiB
JavaScript

/**
* Parse Context
*
* Utility function, to expand strings out into objects.
* @param {Object|String} context
* @return {{internal: boolean, external: boolean, user: integer|null, public: boolean, api_key: Object|null}}
*/
module.exports = function parseContext(context) {
var parsed = {
internal: false,
external: false,
user: null,
api_key: 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');
}
return parsed;
};