Skip to content

Instantly share code, notes, and snippets.

@azatoth
Created August 10, 2016 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azatoth/c0f80f1a35923d87eb22ca93bc9785fb to your computer and use it in GitHub Desktop.
Save azatoth/c0f80f1a35923d87eb22ca93bc9785fb to your computer and use it in GitHub Desktop.
Path.find = function (filter, options, callback) {
var PrivMgr = app.PrivilegeManager;
if (!callback) {
callback = options;
}
callback = callback || ldjutils.createPromiseCallback();
var cfg = Path.app.get('cache');
var _memCache = cacheManager.caching(cfg);
var key = `path_${JSON.stringify(filter)}`;
_memCache.wrap(key, (cacheCallback) => {
var userId = parseInt(_.get(options, 'remoteCtx.req.accessToken.userId'));
if (!userId) {
var ctx = app.loopback.getCurrentContext();
if (ctx) {
var accessToken = ctx.get('accessToken');
if (accessToken) {
userId = accessToken.userId;
}
}
}
if (!userId) {
return callback('no user context');
}
debug('userId', userId);
var flags, type;
if (_.has(filter, 'where.id')) {
var parsed = utils.parseId(filter.where.id);
type = parsed.realtype;
} else {
type = _.get(filter, 'where.type');
}
switch (type) {
case 'media':
flags = PrivMgr.FLAGS.PP_DISPLAY_MEDIA_MANAGER;
break;
case 'playlist':
flags = PrivMgr.FLAGS.PP_DISPLAY_BLOCK_MANAGER;
break;
default:
flags = PrivMgr.FLAGS.PP_RO;
}
PrivMgr.listGroupsWithPriv({
userId,
flags
}, (err, groups) => {
findFn(filter, options, userId, groups, cacheCallback);
});
}, callback);
return callback.promise;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment