lemon-wall-20836
01/16/2022, 12:13 PMlemon-wall-20836
01/16/2022, 12:13 PMclean-salesmen-51708
01/16/2022, 12:17 PMclean-salesmen-51708
01/16/2022, 12:17 PMlemon-wall-20836
01/16/2022, 12:18 PMsome-tiger-63907
01/16/2022, 11:44 PMclass ProfilePolicy < ApplicationPolicy
class Scope < Scope
def resolve
scope.none
end
end
...
lemon-wall-20836
01/17/2022, 6:16 PMability appears to fail "open"
2. Pundit scopes work if you have a pro license. I tested right now them and they work on both index and show. Are they not working on your end?
3. I don't understand ignore the domain in development mode
? Are you getting any notices in development regarding the pro license?
I want to cover all the bases here. Have you restarted the server after you applied the pro license like on the docs page?
https://docs.avohq.io/1.0/licensing.html#add-the-license-keysome-tiger-63907
01/17/2022, 10:52 PMafter_action
methods to ensure its run e.g. after_action :verify_authorized
and verify_policy_scoped
. See https://github.com/varvet/pundit#ensuring-policies-and-scopes-are-used
Looks like it only works with the controller methods so wont with the Avo service: https://github.com/varvet/pundit/blob/main/lib/pundit/authorization.rb#L65
2. ☠️ It doesn't appear to be working for the controller resource. Just the controller resource associations. I'll do some more testing.
UPDATE: BaseResource#query_scope
authorization service has no user and apply_policy
has a guard statement: return model if user.nil?
. It also has a
rescue
model
end
3. 💚 Fixed above thanks. Was just another config line redefining license.lemon-wall-20836
01/18/2022, 7:43 AMlemon-wall-20836
01/18/2022, 7:44 AMlemon-wall-20836
01/18/2022, 7:47 AMlemon-wall-20836
01/18/2022, 2:17 PMsome-tiger-63907
01/18/2022, 10:26 PMAvo::Services::AuthorizationService.new Avo::App.current_user
in BaseResource
returning nil. Not sure how it expected to be populated in class context.
e.g.
@resource.authorization.apply_policy @query #works
@resource.class.query_scope # doesn't
If I add the following to the index action I get the expected behaviour:
@query = @resource.authorization.apply_policy @query
This appears to be a major bug in authorization.some-tiger-63907
01/19/2022, 3:42 AMconfig.current_user_method
.lemon-wall-20836
01/19/2022, 7:45 AMcurrent_user_method
in your initializer?lemon-wall-20836
01/19/2022, 7:45 AMlemon-wall-20836
01/19/2022, 7:46 AMlemon-wall-20836
01/19/2022, 8:12 AMlemon-wall-20836
01/19/2022, 8:13 AMavo.rb
initializer config.current_user_method = :current_user
lemon-wall-20836
01/19/2022, 8:13 AMcurrent_user
lemon-wall-20836
01/19/2022, 8:22 AMlemon-wall-20836
01/19/2022, 12:19 PMsome-tiger-63907
01/19/2022, 10:46 PMdef apply_policy(user, model)
return model if skip_authorization
return model if user.nil?
begin
Pundit.policy_scope! user, model
rescue
model
end
end
It was throwing an exception as per the Pundit docs e.g. raise Pundit::NotAuthorizedError, "must be logged in" unless user
and Avo unscopes the collection.some-tiger-63907
01/19/2022, 10:50 PMreturn model if user.nil? # no security
begin
# security
rescue
# no security
end
some-tiger-63907
01/19/2022, 10:59 PMconfig.current_user_method do
User.find(session[:user_id]) if session[:user_id]
end
quaint-pencil-2979
01/21/2022, 6:50 PMerb
#/app/components/avo/views/resource_index_component.html.erb
<%= render partial: 'avo/partials/resource_search', locals: {resource: @resource.route_key} if @resource.search_query.present? %>
@resource.route_key returns library_media_index in my case, and i guess should return library_media
If a change this to @resource.model_class.model_name.plural it works.
Use route_key is this case is necessary?lemon-wall-20836
01/21/2022, 6:51 PMlemon-wall-20836
01/21/2022, 6:51 PMlemon-wall-20836
01/21/2022, 6:51 PMquaint-pencil-2979
01/21/2022, 6:52 PM