2017-09-25 12:17:06 +03:00
|
|
|
/**
|
|
|
|
* 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}}
|
|
|
|
*/
|
|
|
|
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,
|
|
|
|
app: null,
|
|
|
|
public: true
|
|
|
|
};
|
|
|
|
|
2017-09-28 16:00:52 +03:00
|
|
|
// NOTE: We use the `external` context for subscribers only at the moment.
|
2017-09-25 12:17:06 +03:00
|
|
|
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.app) {
|
|
|
|
parsed.app = context.app;
|
|
|
|
parsed.public = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsed;
|
|
|
|
};
|