Created
November 3, 2011 19:07
-
-
Save cbeer/1337478 to your computer and use it in GitHub Desktop.
WGBH gated discovery solr helper logic example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CatalogController < ... | |
include AmericanArchive::SolrHelper::Authz | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module AmericanArchive::SolrHelper::Authz | |
def self.included(some_class) | |
some_class.solr_search_params_logic += [:apply_authorization_params] | |
end | |
def apply_authorization_params(solr_parameters, user_parameters) | |
return if current_user and (current_user.has_role?(:admin) or current_user.has_role?(:observer)) and user_parameters[:organization_id].nil? | |
solr_parameters[:fq] ||= [] | |
if current_organization | |
solr_parameters[:fq] << 'organization_id_i:(' + current_organization.id.to_s + ')' | |
solr_parameters[:fq] << 'public_b:1' unless current_organization.has_member? current_user or (user_parameters[:persistence_token] and current_organization.persistence_token == user_parameters[:persistence_token]) | |
else | |
# return { } if current_user <-- logged in users may see any records | |
solr_parameters[:fq] << 'organization_id_i:(' + current_user.organizations.map(&:id).join(' OR ') + ')' if current_user and not current_user.organizations.empty? | |
solr_parameters[:fq] << 'public_b:1' if current_user.nil? or current_user.organizations.empty? | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment