introduce setting to have default for auto hide notifications

pull/6377/head
Jens Ulferts 6 years ago
parent a0ab2f9032
commit f31388d7f9
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 2
      app/models/user_preference.rb
  2. 74
      app/views/settings/_users.html.erb
  3. 3
      config/locales/en.yml
  4. 3
      config/settings.yml
  5. 12
      spec/models/user_preference_spec.rb
  6. 15
      spec/support/shared/with_settings.rb

@ -69,7 +69,7 @@ class UserPreference < ActiveRecord::Base
end
def auto_hide_popups?
others[:auto_hide_popups] || false
others.fetch(:auto_hide_popups) { Setting.default_auto_hide_popups? }
end
def warn_on_leaving_unsaved?

@ -29,7 +29,17 @@ See docs/COPYRIGHT.rdoc for more details.
<%= styled_form_tag({ action: 'edit', tab: 'users' }, class: 'admin-settings--form') do %>
<div class ="form--section">
<div class="form--fieldset">
<legend class="form--fieldset-legend"><%= t(:'settings.user.default_preferences')%></legend>
<div class="form--field">
<%= setting_check_box :default_auto_hide_popups, label: 'activerecord.attributes.user_preference.auto_hide_popups' %>
</div>
</div>
<div class="form--fieldset">
<legend class="form--fieldset-legend"><%= t(:'settings.user.deletion')%></legend>
<div class="form--field">
<%= setting_check_box :users_deletable_by_admins %>
</div>
@ -39,42 +49,40 @@ See docs/COPYRIGHT.rdoc for more details.
</div>
</div>
<fieldset class="form--fieldset">
<fieldset id="consent_settings" class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t(:label_consent_settings) %></legend>
<fieldset id="consent_settings" class="form--fieldset">
<legend class="form--fieldset-legend"><%= I18n.t(:label_consent_settings) %></legend>
<div class="form--field">
<%= setting_check_box :consent_required %>
</div>
<div class="form--field">
<%= setting_check_box :consent_required %>
</div>
<%= cell Settings::TextSettingCell, I18n.locale, name: "consent_info" %>
<div class="form--field">
<%= setting_block("consent_time") do %>
<span class="form--check-box-field-container -slim">
<input type="hidden" name="settings[consent_time]" disabled id="settings_consent_time">
<%= check_box_tag 'toggle_consent_time',
'1',
!Setting.consent_time.present?,
id: 'toggle_consent_time' %>
</span>
<% end %>
<div class="form--field-instructions">
<%= I18n.t('consent.text_update_consent_time') %>
<br/>
<strong>
<%= I18n.t('consent.update_consent_last_time',
update_time: Setting.consent_time.present? ? format_time(Setting.consent_time) : t(:label_never)) %>
</strong>
</div>
</div>
<div class="form--field">
<%= setting_text_field :consent_decline_mail, size: 6, container_class: '-middle' %>
<span class="form--field-instructions">
<%= t('consent.contact_mail_instructions') %>
<%= cell Settings::TextSettingCell, I18n.locale, name: "consent_info" %>
<div class="form--field">
<%= setting_block("consent_time") do %>
<span class="form--check-box-field-container -slim">
<input type="hidden" name="settings[consent_time]" disabled id="settings_consent_time">
<%= check_box_tag 'toggle_consent_time',
'1',
!Setting.consent_time.present?,
id: 'toggle_consent_time' %>
</span>
<% end %>
<div class="form--field-instructions">
<%= I18n.t('consent.text_update_consent_time') %>
<br/>
<strong>
<%= I18n.t('consent.update_consent_last_time',
update_time: Setting.consent_time.present? ? format_time(Setting.consent_time) : t(:label_never)) %>
</strong>
</div>
</fieldset>
</div>
<div class="form--field">
<%= setting_text_field :consent_decline_mail, size: 6, container_class: '-middle' %>
<span class="form--field-instructions">
<%= t('consent.contact_mail_instructions') %>
</span>
</div>
</fieldset>
<%= styled_button_tag l(:button_save), class: '-highlight -with-icon icon-checkmark' %>
<% end %>

@ -2067,6 +2067,9 @@ en:
passwords: "Passwords"
session: "Session"
brute_force_prevention: "Automated user blocking"
user:
default_preferences: "Default preferences"
deletion: "Deletion"
text_formatting:
textile: 'Textile'

@ -167,6 +167,9 @@ available_languages:
- ru
default_language:
default: en
default_auto_hide_popups:
default: 1
format: boolean
email_login: # use email address as login, hide login in registration form
default: 0
host_name:

@ -45,8 +45,16 @@ describe UserPreference do
expect(subject.others[:no_self_notified]).to be_truthy
end
it 'disables auto hide popups' do
expect(subject.auto_hide_popups).to eql(false)
context 'with default setting auto_hide_popups to false', with_settings: { default_auto_hide_popups: false } do
it 'disables auto hide popups' do
expect(subject.auto_hide_popups).to be_falsey
end
end
context 'with default setting auto_hide_popups to true', with_settings: { default_auto_hide_popups: true } do
it 'disables auto hide popups' do
expect(subject.auto_hide_popups).to be_truthy
end
end
end

@ -46,7 +46,20 @@ RSpec.configure do |config|
settings = aggregate_mocked_settings(example, settings)
settings.each do |k, v|
allow(Setting).to receive(k).and_return(v)
bare, questionmarked = if k.to_s.ends_with?('?')
[k.to_s[0..-2].to_sym, k]
else
[k, "#{k}?".to_sym]
end
raise "#{k} is not a valid setting" unless Setting.available_settings[bare.to_s]
if Setting.available_settings[bare.to_s]['format'] == 'boolean'
allow(Setting).to receive(bare).and_return(v)
allow(Setting).to receive(questionmarked).and_return(v)
else
allow(Setting).to receive(k).and_return(v)
end
end
end
end

Loading…
Cancel
Save