Module: CurationConcerns::SelectsCollections
- Extended by:
- ActiveSupport::Concern
- Included in:
- CollectionsControllerBehavior
- Defined in:
- app/controllers/concerns/curation_concerns/selects_collections.rb
Instance Method Summary collapse
- #access_levels ⇒ Object
- #collections_search_builder(access_level = nil) ⇒ Object
- #collections_search_builder_class ⇒ Object
-
#find_collections(access_level = nil) ⇒ Array<SolrDocument>
Return list of collections matching the passed in access_level for the current user.
-
#find_collections_with_edit_access(include_default = false, default_id = -1,, default_title = 'Select collection...') ⇒ Array<SolrDocument>
Return list of collections for which the current user has edit access.
-
#find_collections_with_read_access ⇒ Array<SolrDocument>
Return list of collections for which the current user has read access.
Instance Method Details
#access_levels ⇒ Object
10 11 12 |
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 10 def access_levels { read: [:read, :edit], edit: [:edit] } end |
#collections_search_builder(access_level = nil) ⇒ Object
59 60 61 62 63 |
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 59 def collections_search_builder(access_level = nil) collections_search_builder_class.new(self).tap do |builder| builder.discovery_perms = access_levels[access_level] if access_level end end |
#collections_search_builder_class ⇒ Object
55 56 57 |
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 55 def collections_search_builder_class CurationConcerns::CollectionSearchBuilder end |
#find_collections(access_level = nil) ⇒ Array<SolrDocument>
Return list of collections matching the passed in access_level for the current user.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 43 def find_collections(access_level = nil) # need to know the user if there is an access level applied otherwise we are just doing public collections authenticate_user! unless access_level.blank? # run the solr query to find the collections query = collections_search_builder(access_level).with(q: '').query response = repository.search(query) # return the user's collections (or public collections if no access_level is applied) @user_collections = response.documents end |
#find_collections_with_edit_access(include_default = false, default_id = -1,, default_title = 'Select collection...') ⇒ Array<SolrDocument>
Return list of collections for which the current user has edit access. Optionally prepend with default that can be used in a select menu to instruct user to select a collection. Add this or find_collections_with_read_access as a before filter on any page that shows the form_for_select_collection
33 34 35 36 37 |
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 33 def find_collections_with_edit_access(include_default = false, default_id = -1, default_title = 'Select collection...') find_collections(:edit) default_option = SolrDocument.new(id: default_id, title_tesim: default_title) @user_collections.unshift(default_option) if include_default end |
#find_collections_with_read_access ⇒ Array<SolrDocument>
Return list of collections for which the current user has read access. Add this or find_collections_with_edit_access as a before filter on any page that shows the form_for_select_collection
19 20 21 |
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 19 def find_collections_with_read_access find_collections(:read) end |