Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessible_by is a monkey patch #372

Open
atz opened this issue Sep 1, 2016 · 3 comments
Open

accessible_by is a monkey patch #372

atz opened this issue Sep 1, 2016 · 3 comments

Comments

@atz
Copy link
Contributor

atz commented Sep 1, 2016

Two monkey patches, actually:

ActiveFedora::QueryMethods.module_eval do
  extend ActiveSupport::Concern
  included do
    include Hydra::AccessControlsEnforcement
  end

  def accessible_by(ability, action = :index)
    permission_types = case action
      when :index then [:discover, :read, :edit]
      when :show, :read then [:read, :edit]
      when :update, :edit, :create, :new, :destroy then [:edit]
    end

    filters = gated_discovery_filters(permission_types, ability).join(" OR ")
    spawn.where!(filters)
  end
end

ActiveFedora::Querying.module_eval do
  delegate :accessible_by, :to=>:all
end

This is pretty poor form for code that is intended to enact security controls. We're reaching into AF:QueryMethods and declaring that its includers get an additional method with hardcoded permissions levels and Hydra::AccessControlsEnforcement.

The application of the monkey patches is not controlled by any invocation, and it is not avoidable or reversible.

@jcoyne
Copy link
Member

jcoyne commented Sep 1, 2016

@jcoyne
Copy link
Member

jcoyne commented Sep 1, 2016

I think this could be refactored to get rid of at least one of the monkey patches though, but I don't think this feature is something often used, because Fedora is slow, so we typically fulfill this use case by querying only Solr (and not Fedora)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants