Merge branch 'issue_55024' into 'master'

Do not save user preferences on read-only mode

Closes #55024

See merge request gitlab-org/gitlab-ce!23698
This commit is contained in:
Nick Thomas 2018-12-12 16:15:58 +00:00
commit c7ba5c0aeb
4 changed files with 38 additions and 0 deletions

View file

@ -126,6 +126,8 @@ module IssuableCollections
sort_param = params[:sort] sort_param = params[:sort]
sort_param ||= user_preference[issuable_sorting_field] sort_param ||= user_preference[issuable_sorting_field]
return sort_param if Gitlab::Database.read_only?
if user_preference[issuable_sorting_field] != sort_param if user_preference[issuable_sorting_field] != sort_param
user_preference.update_attribute(issuable_sorting_field, sort_param) user_preference.update_attribute(issuable_sorting_field, sort_param)
end end

View file

@ -42,6 +42,8 @@ describe Projects::IssuesController do
it_behaves_like "issuables list meta-data", :issue it_behaves_like "issuables list meta-data", :issue
it_behaves_like 'set sort order from user preference'
it "returns index" do it "returns index" do
get :index, namespace_id: project.namespace, project_id: project get :index, namespace_id: project.namespace, project_id: project

View file

@ -160,6 +160,8 @@ describe Projects::MergeRequestsController do
it_behaves_like "issuables list meta-data", :merge_request it_behaves_like "issuables list meta-data", :merge_request
it_behaves_like 'set sort order from user preference'
context 'when page param' do context 'when page param' do
let(:last_page) { project.merge_requests.page().total_pages } let(:last_page) { project.merge_requests.page().total_pages }
let!(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) } let!(:merge_request) { create(:merge_request_with_diffs, target_project: project, source_project: project) }

View file

@ -0,0 +1,32 @@
shared_examples 'set sort order from user preference' do
describe '#set_sort_order_from_user_preference' do
# There is no issuable_sorting_field defined in any CE controllers yet,
# however any other field present in user_preferences table can be used for testing.
let(:sorting_field) { :issue_notes_filter }
let(:sorting_param) { 'any' }
before do
allow(controller).to receive(:issuable_sorting_field).and_return(sorting_field)
end
context 'when database is in read-only mode' do
it 'it does not update user preference' do
allow(Gitlab::Database).to receive(:read_only?).and_return(true)
expect_any_instance_of(UserPreference).not_to receive(:update_attribute).with(sorting_field, sorting_param)
get :index, namespace_id: project.namespace, project_id: project, sort: sorting_param
end
end
context 'when database is not in read-only mode' do
it 'updates user preference' do
allow(Gitlab::Database).to receive(:read_only?).and_return(false)
expect_any_instance_of(UserPreference).to receive(:update_attribute).with(sorting_field, sorting_param)
get :index, namespace_id: project.namespace, project_id: project, sort: sorting_param
end
end
end
end