diff --git a/app/controllers/media_controller.rb b/app/controllers/media_controller.rb index 183c351dc..1c9633596 100644 --- a/app/controllers/media_controller.rb +++ b/app/controllers/media_controller.rb @@ -680,7 +680,7 @@ def search_params :teachable_inheritance, :fulltext, :per, :clicker, :purpose, :answers_count, :results_as_list, :all_terms, :all_teachers, - :lecture_option, :user_id, + :lecture_option, :user_id, :from, types: [], teachable_ids: [], tag_ids: [], diff --git a/app/helpers/media_helper.rb b/app/helpers/media_helper.rb index a95385e85..711a57dfa 100644 --- a/app/helpers/media_helper.rb +++ b/app/helpers/media_helper.rb @@ -109,7 +109,9 @@ def media_sorts_select(purpose) return add_prompt(Medium.select_quizzables) if purpose == 'quiz' return Medium.select_question if purpose == 'clicker' return add_prompt(Medium.select_importables) if purpose == 'import' - return add_prompt(Medium.select_generic) if !current_user.admin? + unless current_user.admin_or_editor? + return add_prompt(Medium.select_generic) + end add_prompt(Medium.select_sorts) end diff --git a/app/models/medium.rb b/app/models/medium.rb index c851d537e..124395eac 100644 --- a/app/models/medium.rb +++ b/app/models/medium.rb @@ -202,7 +202,7 @@ def self.select_sorts end def self.advanced_sorts - ['RandomQuiz', 'Question', 'Remark', 'Erdbeere'] + ['Question', 'Remark', 'Erdbeere'] end def self.generic_sorts @@ -282,7 +282,17 @@ def self.lecture_search_option # returns search results for the media search with search_params provided # by the controller def self.search_by(search_params, page) - search_params[:types] = [] if search_params[:all_types] == '1' + # If the search is initiated from the start page, you can only get + # generic media sorts as results even if the 'all' radio button + # is seleted + if search_params[:all_types] == '1' + search_params[:types] = + if search_params[:from] == 'start' + Medium.generic_sorts + else + [] + end + end search_params[:teachable_ids] = TeachableParser.new(search_params) .teachables_as_strings search_params[:editor_ids] = @@ -295,11 +305,12 @@ def self.search_by(search_params, page) if search_params[:all_tags] == '1' && search_params[:tag_operator] == 'and' search_params[:tag_ids] = Tag.pluck(:id) end - admin = User.find_by(id: search_params[:user_id])&.admin? + user = User.find_by(id: search_params[:user_id]) search = Sunspot.new_search(Medium) search.build do with(:sort, search_params[:types]) - without(:sort, Medium.advanced_sorts) unless admin + without(:sort, 'RandomQuiz') + without(:sort, Medium.advanced_sorts) unless user&.admin_or_editor? with(:editor_ids, search_params[:editor_ids]) with(:teachable_compact, search_params[:teachable_ids]) with(:term_id, diff --git a/app/views/main/start/_media_search.html.erb b/app/views/main/start/_media_search.html.erb index 08fde22bb..d57e8da70 100644 --- a/app/views/main/start/_media_search.html.erb +++ b/app/views/main/start/_media_search.html.erb @@ -125,7 +125,7 @@ '2', checked: false, class: 'custom-control-input', - data: { type: 'toggle', + data: { type: 'toggle', id: 'search_media_lectures'} %> <%= f.label :lecture_option, t('search.media.lecture_options.own_selection'), @@ -162,6 +162,7 @@ <%= f.hidden_field :purpose, value: purpose %> <%= f.hidden_field :results_as_list, value: 'false' %> + <%= f.hidden_field :from, value: 'start' %>