perm.go 830 B

1234567891011121314151617181920212223242526
  1. package views
  2. import "net/http"
  3. // DO NOT associate media_library permissions with parent resources
  4. // WRONG: permPolicy.On("*:post:*")
  5. // right: permPolicy.On("*")
  6. // right: permPolicy.On("*:media_libraries:*")
  7. // right: permPolicy.On("*:media_libraries:1")
  8. const (
  9. PermUpload = "perm_media_library_upload"
  10. PermDelete = "perm_media_library_delete"
  11. PermUpdateDesc = "perm_media_library_update_desc"
  12. )
  13. func uploadIsAllowed(r *http.Request) error {
  14. return permVerifier.Do(PermUpload).On("media_libraries").WithReq(r).IsAllowed()
  15. }
  16. func deleteIsAllowed(r *http.Request, obj interface{}) error {
  17. return permVerifier.Do(PermDelete).ObjectOn(obj).WithReq(r).IsAllowed()
  18. }
  19. func updateDescIsAllowed(r *http.Request, obj interface{}) error {
  20. return permVerifier.Do(PermUpdateDesc).ObjectOn(obj).WithReq(r).IsAllowed()
  21. }