role.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package example_basics
  2. import (
  3. "github.com/qor5/admin/presets"
  4. "github.com/qor5/admin/role"
  5. "github.com/qor5/ui/vuetify"
  6. "github.com/qor5/x/perm"
  7. "gorm.io/gorm"
  8. )
  9. func rolePieces() {
  10. var db *gorm.DB
  11. // @snippet_begin(RolePermEnableDBPolicy)
  12. perm.New().
  13. Policies(
  14. // static policies
  15. ).
  16. DBPolicy(perm.NewDBPolicy(db))
  17. // @snippet_end
  18. // @snippet_begin(RoleSetResources)
  19. rb := role.New(db).
  20. Resources([]*vuetify.DefaultOptionItem{
  21. {Text: "All", Value: "*"},
  22. {Text: "Posts", Value: "*:posts:*"},
  23. {Text: "Customers", Value: "*:customers:*"},
  24. {Text: "Products", Value: "*:products:*"},
  25. })
  26. // @snippet_end
  27. // @snippet_begin(RoleSetActions)
  28. // default value
  29. rb.Actions([]*vuetify.DefaultOptionItem{
  30. {Text: "All", Value: "*"},
  31. {Text: "List", Value: presets.PermList},
  32. {Text: "Get", Value: presets.PermGet},
  33. {Text: "Create", Value: presets.PermCreate},
  34. {Text: "Update", Value: presets.PermUpdate},
  35. {Text: "Delete", Value: presets.PermDelete},
  36. })
  37. // @snippet_end
  38. // @snippet_begin(RoleSetEditorSubject)
  39. rb.EditorSubject("RoleEditor")
  40. // @snippet_end
  41. var presetsBuilder *presets.Builder
  42. // @snippet_begin(RoleAttachToPresetsBuilder)
  43. rb.Configure(presetsBuilder)
  44. // @snippet_end
  45. }