bouncer.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Contract source: https://git.io/Jte3T
  3. *
  4. * Feel free to let us know via PR, if you find something broken in this config
  5. * file.
  6. */
  7. import Bouncer from '@ioc:Adonis/Addons/Bouncer'
  8. /*
  9. |--------------------------------------------------------------------------
  10. | Bouncer Actions
  11. |--------------------------------------------------------------------------
  12. |
  13. | Actions allows you to separate your application business logic from the
  14. | authorization logic. Feel free to make use of policies when you find
  15. | yourself creating too many actions
  16. |
  17. | You can define an action using the `.define` method on the Bouncer object
  18. | as shown in the following example
  19. |
  20. | ```
  21. | Bouncer.define('deletePost', (user: User, post: Post) => {
  22. | return post.user_id === user.id
  23. | })
  24. | ```
  25. |
  26. |****************************************************************
  27. | NOTE: Always export the "actions" const from this file
  28. |****************************************************************
  29. */
  30. export const { actions } = Bouncer
  31. /*
  32. |--------------------------------------------------------------------------
  33. | Bouncer Policies
  34. |--------------------------------------------------------------------------
  35. |
  36. | Policies are self contained actions for a given resource. For example: You
  37. | can create a policy for a "User" resource, one policy for a "Post" resource
  38. | and so on.
  39. |
  40. | The "registerPolicies" accepts a unique policy name and a function to lazy
  41. | import the policy
  42. |
  43. | ```
  44. | Bouncer.registerPolicies({
  45. | UserPolicy: () => import('App/Policies/User'),
  46. | PostPolicy: () => import('App/Policies/Post')
  47. | })
  48. | ```
  49. |
  50. |****************************************************************
  51. | NOTE: Always export the "policies" const from this file
  52. |****************************************************************
  53. */
  54. export const { policies } = Bouncer.registerPolicies({})