readd diff_type to user preferences

pull/9999/head
ulferts 3 years ago
parent 1314126200
commit bb9befbcb9
No known key found for this signature in database
GPG Key ID: A205708DE1284017
  1. 24
      app/controllers/repositories_controller.rb
  2. 4
      app/models/user_preference.rb
  3. 4
      config/schemas/user_preferences.schema.json
  4. 21
      spec/models/user_preference_spec.rb

@ -259,14 +259,7 @@ class RepositoriesController < ApplicationController
type: 'text/x-patch',
disposition: 'attachment'
else
@diff_type = params[:type] || User.current.pref[:diff_type] || 'inline'
@diff_type = 'inline' unless %w(inline sbs).include?(@diff_type)
# Save diff type as user preference
if User.current.logged? && @diff_type != User.current.pref[:diff_type]
User.current.pref[:diff_type] = @diff_type
User.current.preference.save
end
@diff_type = diff_type_persisted
@cache_key = "repositories/diff/#{@repository.id}/" +
Digest::MD5.hexdigest("#{@path}-#{@rev}-#{@rev_to}-#{@diff_type}")
@ -497,6 +490,21 @@ class RepositoriesController < ApplicationController
# rails looking for e.g text when .txt is asked for
render 'entry', formats: [:html]
end
def diff_type_persisted
preferences = current_user.pref
diff_type = params[:type] || preferences.diff_type
diff_type = 'inline' unless %w(inline sbs).include?(diff_type)
# Save diff type as user preference
if current_user.logged? && diff_type != preferences.diff_type
preferences.diff_type = diff_type
preferences.save
end
diff_type
end
end
class Date

@ -85,6 +85,10 @@ class UserPreference < ApplicationRecord
comments_sorting == 'desc'
end
def diff_type
settings.fetch(:diff_type, 'inline')
end
def hide_mail
settings.fetch(:hide_mail, true)
end

@ -22,6 +22,10 @@
"auto_hide_popups": {
"type": "boolean"
},
"diff_type": {
"type": "string",
"enum": ["inline", "sbs"]
},
"workdays": {
"type": "array",
"items": {

@ -140,6 +140,27 @@ describe UserPreference do
end
end
describe '#diff_type' do
it 'can be set and written' do
expect(subject.diff_type)
.to eql 'inline'
subject.diff_type = 'sbs'
expect(subject.diff_type)
.to eql 'sbs'
end
context 'with a new pref instance' do
subject { described_class.new }
it 'defaults to `inline`' do
expect(subject.diff_type)
.to eql 'inline'
end
end
end
describe '#daily_reminders' do
context 'without reminders being stored' do
it 'uses the defaults' do

Loading…
Cancel
Save