-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Closed
Description
var async = require('async')
var _ = lodash = require('lodash')
var ObjectID = require('mongodb').ObjectID
module.exports = function(app) {
var Role = app.models.Role;
Role.registerResolver('aToB', function(role, context, cb) {
var data, userId
if (context && context.remotingContext && context.remotingContext.args && context.remotingContext.args.data) {
data = context.remotingContext.args.data
}
userId = context.accessToken.userId
if (context.modelName === 'name') {
if (context.accessType === 'WRITE') {
async.waterfall([
function(asyncCb) {
var A = app.models.a
A.findById(data.aId, function(err, a) {
if (a && a.name) {
var ACL = app.models.ACL
ACL.isMappedToRole(ACL.USER, userId, a.name, function(err, isMappedToRole) {
asyncCb(err, isMappedToRole)
})
}
else{
asyncCb(null, false)
}
})
},
function(isMappedToRole, asyncCb) {
if (!isMappedToRole) {
var Team = app.models.team
Team.count({
projectId: data.aId,
memberId: userId
}, function (err, count) {
return asyncCb(null, count > 0)
})
}
else {
asyncCb(null, isMappedToRole)
}
}
, function(err, isMappedToRole) {
cb(err, isMappedToRole)
})
}
}
})
}