utilities/auth-helper.js
function(model, type, logger) {
    let routeScope = model.routeOptions.routeScope || {}
    let rootScope = routeScope.rootScope
    let scope = []

    let additionalScope = null

    switch (type) {
      case 'create':
        additionalScope = routeScope.createScope
        break
      case 'read':
        additionalScope = routeScope.readScope
        break
      case 'update':
        additionalScope = routeScope.updateScope
        break
      case 'delete':
        additionalScope = routeScope.deleteScope
        break
      case 'associate':
        additionalScope = routeScope.associateScope
        break
      default:
        if (routeScope[type]) {
          scope = routeScope[type]
          if (!_.isArray(scope)) {
            scope = [scope]
          }
        }
        return scope
    }

    if (rootScope && _.isArray(rootScope)) {
      scope = scope.concat(rootScope)
    } else if (rootScope) {
      scope.push(rootScope)
    }

    if (additionalScope && _.isArray(additionalScope)) {
      scope = scope.concat(additionalScope)
    } else if (additionalScope) {
      scope.push(additionalScope)
    }

    return scope
  }
function(model, type, logger) {
    let routeScope = model.routeOptions.routeScope || {}
    let rootScope = routeScope.rootScope
    let scope = []

    let additionalScope = null

    switch (type) {
      case 'create':
        additionalScope = routeScope.createScope
        break
      case 'read':
        additionalScope = routeScope.readScope
        break
      case 'update':
        additionalScope = routeScope.updateScope
        break
      case 'delete':
        additionalScope = routeScope.deleteScope
        break
      case 'associate':
        additionalScope = routeScope.associateScope
        break
      default:
        if (routeScope[type]) {
          scope = routeScope[type]
          if (!_.isArray(scope)) {
            scope = [scope]
          }
        }
        return scope
    }

    if (rootScope && _.isArray(rootScope)) {
      scope = scope.concat(rootScope)
    } else if (rootScope) {
      scope.push(rootScope)
    }

    if (additionalScope && _.isArray(additionalScope)) {
      scope = scope.concat(additionalScope)
    } else if (additionalScope) {
      scope.push(additionalScope)
    }

    return scope
  }
function ( model , type , logger ) { let routeScope = model . routeOptions . routeScope || { } let rootScope = routeScope . rootScope let scope = [ ] let additionalScope = null switch ( type ) { case 'create' : additionalScope = routeScope . createScope break case 'read' : additionalScope = routeScope . readScope break case 'update' : additionalScope = routeScope . updateScope break case 'delete' : additionalScope = routeScope . deleteScope break case 'associate' : additionalScope = routeScope . associateScope break default : if ( routeScope [ type ] ) { scope = routeScope [ type ] if ( ! _ . isArray ( scope ) ) { scope = [ scope ] } } return scope } if ( rootScope && _ . isArray ( rootScope ) ) { scope = scope . concat ( rootScope ) } else if ( rootScope ) { scope . push ( rootScope ) } if ( additionalScope && _ . isArray ( additionalScope ) ) { scope = scope . concat ( additionalScope ) } else if ( additionalScope ) { scope . push ( additionalScope ) } return scope }
Generates the proper scope for an endpoint based on the model routeOptions
@param model: A mongoose model
@param type: The scope CRUD type. Valid values are 'create', 'read', 'update', 'delete', and 'associate'.
@param logger: A logging object
@returns {Array}: A list of authorization scopes for the endpoint.
Generates the proper scope for an endpoint based on the model routeOptions