Redmine 4.1.1

This commit is contained in:
Manuel Cillero 2020-11-22 21:20:06 +01:00
parent 33e7b881a5
commit 3d976f1b3b
1593 changed files with 36180 additions and 19489 deletions

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
# Redmine - project management software
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2006-2019 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@ -18,15 +20,19 @@
class EmailAddress < ActiveRecord::Base
include Redmine::SafeAttributes
belongs_to :user
attr_protected :id
EMAIL_REGEXP = /\A([^@\s]+)@((?:[-a-z0-9]+\.)+(?:(?:xn--[-a-z0-9]+)|(?:[a-z]{2,})))\z/i
after_create :deliver_security_notification_create
after_update :destroy_tokens, :deliver_security_notification_update
after_destroy :destroy_tokens, :deliver_security_notification_destroy
belongs_to :user
after_update :destroy_tokens
after_destroy :destroy_tokens
after_create_commit :deliver_security_notification_create
after_update_commit :deliver_security_notification_update
after_destroy_commit :deliver_security_notification_destroy
validates_presence_of :address
validates_format_of :address, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :allow_blank => true
validates_format_of :address, :with => EMAIL_REGEXP, :allow_blank => true
validates_length_of :address, :maximum => User::MAIL_LENGTH_LIMIT, :allow_nil => true
validates_uniqueness_of :address, :case_sensitive => false,
:if => Proc.new {|email| email.address_changed? && email.address.present?}
@ -53,7 +59,7 @@ class EmailAddress < ActiveRecord::Base
# in that case, the user is just being created and
# should not receive this email.
if user.mails != [address]
deliver_security_notification(user,
deliver_security_notification(
message: :mail_body_security_notification_add,
field: :field_mail,
value: address
@ -63,26 +69,27 @@ class EmailAddress < ActiveRecord::Base
# send a security notification to user that an email has been changed (notified/not notified)
def deliver_security_notification_update
if address_changed?
recipients = [user, address_was]
if saved_change_to_address?
options = {
recipients: [address_before_last_save],
message: :mail_body_security_notification_change_to,
field: :field_mail,
value: address
}
elsif notify_changed?
recipients = [user, address]
elsif saved_change_to_notify?
options = {
message: notify_was ? :mail_body_security_notification_notify_disabled : :mail_body_security_notification_notify_enabled,
recipients: [address],
message: notify_before_last_save ? :mail_body_security_notification_notify_disabled : :mail_body_security_notification_notify_enabled,
value: address
}
end
deliver_security_notification(recipients, options)
deliver_security_notification(options)
end
# send a security notification to user that an email address was deleted
def deliver_security_notification_destroy
deliver_security_notification([user, address],
deliver_security_notification(
recipients: [address],
message: :mail_body_security_notification_remove,
field: :field_mail,
value: address
@ -90,20 +97,22 @@ class EmailAddress < ActiveRecord::Base
end
# generic method to send security notifications for email addresses
def deliver_security_notification(recipients, options={})
Mailer.security_notification(recipients,
def deliver_security_notification(options={})
Mailer.deliver_security_notification(
user,
User.current,
options.merge(
title: :label_my_account,
url: {controller: 'my', action: 'account'}
)
).deliver
)
end
# Delete all outstanding password reset tokens on email change.
# This helps to keep the account secure in case the associated email account
# was compromised.
def destroy_tokens
if address_changed? || destroyed?
if saved_change_to_address? || destroyed?
tokens = ['recovery']
Token.where(:user_id => user_id, :action => tokens).delete_all
end