Module: CurationConcerns::SelectsCollections

Extended by:
ActiveSupport::Concern, Deprecation
Defined in:
app/controllers/concerns/curation_concerns/selects_collections.rb

Instance Method Summary collapse

Instance Method Details

#access_levelsHash{Symbol => Array[Symbol]}

Note:

i.e., requiring :read access is satisfied by either :read or :edit access

Returns bottom-up map of “what you need” to “what qualifies”.

Returns:

  • (Hash{Symbol => Array[Symbol]})

    bottom-up map of “what you need” to “what qualifies”



14
15
16
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 14

def access_levels
  { read: [:read, :edit], edit: [:edit] }
end

#collections_search_builder(access_level = nil) ⇒ Object



63
64
65
66
67
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 63

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_classObject



59
60
61
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 59

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.

Parameters:

  • :access_level (Symbol)

    one of :read or :edit

Returns:

  • (Array<SolrDocument>)

    Solr documents for each collection the user has the appropriate access level



47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 47

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

Parameters:

  • :include_default (TrueClass|FalseClass)

    if true, prepends the default_option; otherwise, if false, returns only collections

  • :default_id (Fixnum)

    for select menus, this is the id of the first selection representing the instructions

  • :default_title (String)

    for select menus, this is the text displayed as the first item serving as instructions

Returns:

  • (Array<SolrDocument>)

    Solr documents for each collection the user has edit access, plus optional instructions



37
38
39
40
41
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 37

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_accessArray<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

Returns:

  • (Array<SolrDocument>)

    Solr documents for each collection the user has read access



23
24
25
# File 'app/controllers/concerns/curation_concerns/selects_collections.rb', line 23

def find_collections_with_read_access
  find_collections(:read)
end