lib/middleware.js
function (modelName) {
      if (["make", "list"].indexOf(modelName) === -1) {
        throw new Error(
          "checkOwnerApp middleware can only be configured with 'make' or 'list'. You passed in: '" +
          modelName +
          "'"
        );
      }

      return function (req, res, next) {
        // Don't enforce write permissions if not enabled.
        if (!ENFORCE_WRITE_PERMISSIONS) {
          return next();
        }

        var model = req[modelName],
          user = req.credentials.user;
        // check if the authenticated application has admin permissions, or if it owns the make
        if (req.credentials.admin !== true && user !== model.ownerApp) {
          return hawkModule.respond(403, res, req.credentials, req.artifacts, {
            status: "failure",
            reason: "unauthorized"
          }, "application/json");
        }
        next();
      };
    }
function (modelName) {
      if (["make", "list"].indexOf(modelName) === -1) {
        throw new Error(
          "checkOwnerApp middleware can only be configured with 'make' or 'list'. You passed in: '" +
          modelName +
          "'"
        );
      }

      return function (req, res, next) {
        // Don't enforce write permissions if not enabled.
        if (!ENFORCE_WRITE_PERMISSIONS) {
          return next();
        }

        var model = req[modelName],
          user = req.credentials.user;
        // check if the authenticated application has admin permissions, or if it owns the make
        if (req.credentials.admin !== true && user !== model.ownerApp) {
          return hawkModule.respond(403, res, req.credentials, req.artifacts, {
            status: "failure",
            reason: "unauthorized"
          }, "application/json");
        }
        next();
      };
    }
function ( modelName ) { if ( [ "make" , "list" ] . indexOf ( modelName ) === - 1 ) { throw new Error ( "checkOwnerApp middleware can only be configured with 'make' or 'list'. You passed in: '" + modelName + "'" ) ; } return function ( req , res , next ) { // Don't enforce write permissions if not enabled. if ( ! ENFORCE_WRITE_PERMISSIONS ) { return next ( ) ; } var model = req [ modelName ] , user = req . credentials . user ; // check if the authenticated application has admin permissions, or if it owns the make if ( req . credentials . admin !== true && user !== model . ownerApp ) { return hawkModule . respond ( 403 , res , req . credentials , req . artifacts , { status : "failure" , reason : "unauthorized" } , "application/json" ) ; } next ( ) ; } ; }
modelName must be "make" or "list" only
modelName must be make or list only