Commit 47ef25a1 authored by Jake Lear's avatar Jake Lear

Add flash message to projects index when search is disabled

parent d086bd98
......@@ -26,6 +26,7 @@ class Explore::ProjectsController < Explore::ApplicationController
feature_category :projects
def index
show_alert_if_search_is_disabled
@projects = load_projects
respond_to do |format|
......@@ -120,6 +121,12 @@ class Explore::ProjectsController < Explore::ApplicationController
end
end
end
def show_alert_if_search_is_disabled
return if current_user || params[:name].blank? && params[:search].blank? || !html_request? || Feature.disabled?(:disable_anonymous_search, type: :ops)
flash[:notice] = _('You must sign in to search for specific projects.')
end
end
Explore::ProjectsController.prepend_mod_with('Explore::ProjectsController')
......@@ -38758,6 +38758,9 @@ msgstr ""
msgid "You must provide your current password in order to change it."
msgstr ""
msgid "You must sign in to search for specific projects."
msgstr ""
msgid "You must sign in to search for specific terms."
msgstr ""
......
......@@ -200,6 +200,24 @@ RSpec.describe Explore::ProjectsController do
let(:sorting_param) { 'created_asc' }
end
end
describe 'GET #index' do
let(:controller_action) { :index }
let(:params_with_name) { { name: 'some project' } }
context 'when disable_anonymous_search is enabled' do
before do
stub_feature_flags(disable_anonymous_search: true)
end
it 'does not show a flash message' do
sign_in(create(:user))
get controller_action, params: params_with_name
expect(flash[:notice]).to be_nil
end
end
end
end
context 'when user is not signed in' do
......@@ -229,5 +247,50 @@ RSpec.describe Explore::ProjectsController do
expect(response).to redirect_to new_user_session_path
end
end
describe 'GET #index' do
let(:controller_action) { :index }
let(:params_with_name) { { name: 'some project' } }
context 'when disable_anonymous_search is enabled' do
before do
stub_feature_flags(disable_anonymous_search: true)
end
it 'shows a flash message' do
get controller_action, params: params_with_name
expect(flash[:notice]).to eq('You must sign in to search for specific projects.')
end
context 'when search param is not given' do
it 'does not show a flash message' do
get controller_action
expect(flash[:notice]).to be_nil
end
end
context 'when format is not HTML' do
it 'does not show a flash message' do
get controller_action, params: params_with_name.merge(format: :atom)
expect(flash[:notice]).to be_nil
end
end
end
context 'when disable_anonymous_search is disabled' do
before do
stub_feature_flags(disable_anonymous_search: false)
end
it 'does not show a flash message' do
get controller_action, params: params_with_name
expect(flash[:notice]).to be_nil
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment