From d1dda24b6fe9341ba16984e6563b3d918b3fcada Mon Sep 17 00:00:00 2001 From: Louis Sommer Date: Thu, 1 Sep 2022 14:45:24 +0200 Subject: [PATCH 1/2] Add custom policies to authorization section --- src/2.0/authorization.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/2.0/authorization.md b/src/2.0/authorization.md index 237fefa..2eee401 100644 --- a/src/2.0/authorization.md +++ b/src/2.0/authorization.md @@ -178,6 +178,18 @@ end Now, Avo will use `avo_index?` instead of `index?` to manage the **Index** view authorization. +## Using custom policies + +By default, Avo will infer the policy from the model of the resource object. If you wish to use a different policy for a given resource, you can specify it directly in the resource like so: + +```ruby +class PhotoCommentResource < Avo::BaseResource + self.model_class = ::Comment + self.authorization_policy = PhotoCommentPolicy + # ... +end +``` + ## Raise errors when policies are missing The default behavior of Avo is to silently allow missing policies for resources. So, if you have a `User` model and a `UserResource` but don't have a `UserPolicy`, Avo will not raise errors regarding missing policies and authorize that resource. From 4bbf87aed79d7662878243000a27f6b19b3ee167 Mon Sep 17 00:00:00 2001 From: Louis Sommer Date: Thu, 1 Sep 2022 14:48:22 +0200 Subject: [PATCH 2/2] Add custom policy to resource section --- src/2.0/resources.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/2.0/resources.md b/src/2.0/resources.md index 74d3ddb..f1389d3 100644 --- a/src/2.0/resources.md +++ b/src/2.0/resources.md @@ -184,6 +184,16 @@ end class Avo::SpreeStoresController < Avo::ResourcesController end ``` +## Custom policy + +By default, Avo will infer the policy from the model of the resource object. If you wish to use a different policy for a given resource, you can specify it directly like so: + +```ruby +# app/avo/resources/photo_comment_resource.rb +class PhotoCommentResource < Avo::BaseResource + self.authorization_policy = PhotoCommentPolicy +end +``` ## Devise password optional