Created
August 10, 2016 12:40
-
-
Save azatoth/c0f80f1a35923d87eb22ca93bc9785fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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