Skip to content

Role.registerResolver called twice #1799

Description

@mike-aungsan
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)
        })

      }

    }

  })

}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions