Skip to content

Instantly share code, notes, and snippets.

@mikermcneil
Created March 12, 2013 08:10
Show Gist options
  • Select an option

  • Save mikermcneil/5141066 to your computer and use it in GitHub Desktop.

Select an option

Save mikermcneil/5141066 to your computer and use it in GitHub Desktop.
Explicit policies (each actions'/controllers' policies override all parents)
/**
* Policy defines middleware that is run before each controller/action.
* Any policy dropped into the /policies directory is made globally available through sails.policies
* Below, use the string name of the policy (for instance authenticated.js would be "authenticated")
*/
module.exports.policies = {
// Default policy (apply to everything)
// equivalent to ['authenticated']
'*': 'authenticated'
// To access any actions in the MessageController, you must pass all policies on '*', as well as 'canMessage'
'message': ['authenticated', 'canMessage'],
'hotdog': {
// To access the 'index' action in the HotdogController,
// you must pass all policies on '*', as well as 'hotdogQuotaNotExceeded'
'index': ['authenticated', 'hotdogQuotaNotExceeded']
},
// On the UserController, apply all policies on '*' as well as:
'user': {
// For **ALL** actions in the UserController, you must pass 'authenticated' and 'canAccessUsers' policies (in order)
'*': ['authenticated', 'canAccessUsers'],
// To access the 'create' action, you must pass all of the * and user/* policies,
// THEN pass the 'canCreateUsers' and 'userQuotaNotExceeded' policies (in order)
'create': ['authenticated', 'canAccessUsers', 'canCreateUsers', 'userQuotaNotExceeded'],
// To access the 'destroy' action, you must pass all of the * and user/* policies,
// THEN pass the 'canDestroyUsers' policy
'destroy': ['authenticated', 'canAccessUsers', 'canDestroysers']
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment