         else
           res.json 401, {}
 
+  roleAction = (role) ->
+    (req, res, next) ->
+      userAction req, res, () ->
+        isInRole role, req.user, (ok) ->
+          if ok
+            next()
+          else
+            isAdmin req.user, (admin) ->
+              if admin
+                next()
+              else
+                res.json 401, {}
+
   isInRole = (role, user, callback) ->
     result = false
     settingName = role + 'RoleName'

  #Export the authentiaction action middleware
    publicAction: publicAction
    publicReadAction: publicReadAction
    userAction: userAction
    adminAction: adminAction
    sysAdminAction: sysAdminAction

        roleName = result.value
      app.models.roles.findOneBy 'name', roleName, user.systemId
      , (err, obj) ->
        if obj?._id? and not err
          _.each(user.roles, (role) ->
            if role.toString() is obj._id.toString()
              result = true
