Feature #21421 » 0006-Send-a-security-notification-when-certain-settings-a.patch
| app/models/setting.rb | ||
|---|---|---|
|
def self.[]=(name, v)
|
||
|
setting = find_or_default(name)
|
||
|
previous_value = setting.value
|
||
|
setting.value = (v ? v : "")
|
||
|
@cached_settings[name] = nil
|
||
|
setting.save
|
||
|
if available_settings[setting.name]['security_notifications'] && setting.value != previous_value
|
||
|
User.where(admin: true, status: Principal::STATUS_ACTIVE).each do |admin|
|
||
|
Mailer.security_notification(admin,
|
||
|
message: :mail_body_security_notification_change,
|
||
|
field: "setting_#{name}",
|
||
|
title: :label_settings,
|
||
|
url: {controller: 'settings', action: 'index'}
|
||
|
).deliver
|
||
|
end
|
||
|
end
|
||
|
setting.value
|
||
|
end
|
||
| config/settings.yml | ||
|---|---|---|
|
default:
|
||
|
login_required:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
self_registration:
|
||
|
default: '2'
|
||
|
security_notifications: 1
|
||
|
lost_password:
|
||
|
default: 1
|
||
|
security_notifications: 1
|
||
|
unsubscribe:
|
||
|
default: 1
|
||
|
password_min_length:
|
||
|
format: int
|
||
|
default: 8
|
||
|
security_notifications: 1
|
||
|
# Maximum password age in days
|
||
|
password_max_age:
|
||
|
format: int
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
# Maximum number of additional email addresses per user
|
||
|
max_additional_emails:
|
||
|
format: int
|
||
| ... | ... | |
|
session_lifetime:
|
||
|
format: int
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
# User session timeout in minutes
|
||
|
session_timeout:
|
||
|
format: int
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
attachment_max_size:
|
||
|
format: int
|
||
|
default: 5120
|
||
| ... | ... | |
|
default: localhost:3000
|
||
|
protocol:
|
||
|
default: http
|
||
|
security_notifications: 1
|
||
|
feeds_limit:
|
||
|
format: int
|
||
|
default: 15
|
||
| ... | ... | |
|
- Cvs
|
||
|
- Bazaar
|
||
|
- Git
|
||
|
security_notifications: 1
|
||
|
autofetch_changesets:
|
||
|
default: 1
|
||
|
sys_api_enabled:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
sys_api_key:
|
||
|
default: ''
|
||
|
security_notifications: 1
|
||
|
commit_cross_project_ref:
|
||
|
default: 0
|
||
|
commit_ref_keywords:
|
||
| ... | ... | |
|
default: ''
|
||
|
mail_handler_api_enabled:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
mail_handler_api_key:
|
||
|
default:
|
||
|
security_notifications: 1
|
||
|
issue_list_default_columns:
|
||
|
serialized: true
|
||
|
default:
|
||
| ... | ... | |
|
default: 0
|
||
|
openid:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
gravatar_default:
|
||
|
default: ''
|
||
|
start_of_week:
|
||
|
default: ''
|
||
|
rest_api_enabled:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
jsonp_enabled:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
|
default_notification_option:
|
||
|
default: 'only_my_events'
|
||
|
emails_header:
|
||
| test/functional/settings_controller_test.rb | ||
|---|---|---|
|
], Setting.commit_update_keywords)
|
||
|
end
|
||
|
def test_post_edit_should_send_security_notification_for_notified_settings
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
post :edit, :settings => {
|
||
|
:login_required => 1
|
||
|
}
|
||
|
assert_not_nil (mail = ActionMailer::Base.deliveries.last)
|
||
|
assert_mail_body_match '0.0.0.0', mail
|
||
|
assert_mail_body_match I18n.t(:mail_body_security_notification_change, field: I18n.t(:setting_login_required)), mail
|
||
|
assert_select_email do
|
||
|
assert_select 'a[href^=?]', 'http://localhost:3000/settings', :text => 'Settings'
|
||
|
end
|
||
|
# All admins should receive this
|
||
|
User.where(admin: true, status: Principal::STATUS_ACTIVE).each do |admin|
|
||
|
assert_not_nil ActionMailer::Base.deliveries.detect{|mail| [mail.bcc, mail.cc].flatten.include?(admin.mail) }
|
||
|
end
|
||
|
end
|
||
|
def test_post_edit_should_not_send_security_notification_for_non_notified_settings
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
post :edit, :settings => {
|
||
|
:app_title => 'MineRed'
|
||
|
}
|
||
|
assert_nil (mail = ActionMailer::Base.deliveries.last)
|
||
|
end
|
||
|
def test_post_edit_should_not_send_security_notification_for_unchanged_settings
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
post :edit, :settings => {
|
||
|
:login_required => 0
|
||
|
}
|
||
|
assert_nil (mail = ActionMailer::Base.deliveries.last)
|
||
|
end
|
||
|
def test_get_plugin_settings
|
||
|
ActionController::Base.append_view_path(File.join(Rails.root, "test/fixtures/plugins"))
|
||
|
Redmine::Plugin.register :foo do
|
||
| test/unit/mailer_test.rb | ||
|---|---|---|
|
def test_generated_links_in_emails
|
||
|
Setting.host_name = 'mydomain.foo'
|
||
|
Setting.protocol = 'https'
|
||
|
ActionMailer::Base.deliveries.clear
|
||
|
journal = Journal.find(3)
|
||
|
assert Mailer.deliver_issue_edit(journal)
|
||