You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

email_addresses_controller.rb 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Redmine - project management software
  2. # Copyright (C) 2006-2017 Jean-Philippe Lang
  3. #
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU General Public License
  6. # as published by the Free Software Foundation; either version 2
  7. # of the License, or (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. class EmailAddressesController < ApplicationController
  18. self.main_menu = false
  19. before_action :find_user, :require_admin_or_current_user
  20. before_action :find_email_address, :only => [:update, :destroy]
  21. require_sudo_mode :create, :update, :destroy
  22. def index
  23. @addresses = @user.email_addresses.order(:id).where(:is_default => false).to_a
  24. @address ||= EmailAddress.new
  25. end
  26. def create
  27. saved = false
  28. if @user.email_addresses.count <= Setting.max_additional_emails.to_i
  29. @address = EmailAddress.new(:user => @user, :is_default => false)
  30. @address.safe_attributes = params[:email_address]
  31. saved = @address.save
  32. end
  33. respond_to do |format|
  34. format.html {
  35. if saved
  36. redirect_to user_email_addresses_path(@user)
  37. else
  38. index
  39. render :action => 'index'
  40. end
  41. }
  42. format.js {
  43. @address = nil if saved
  44. index
  45. render :action => 'index'
  46. }
  47. end
  48. end
  49. def update
  50. if params[:notify].present?
  51. @address.notify = params[:notify].to_s
  52. end
  53. @address.save
  54. respond_to do |format|
  55. format.html {
  56. redirect_to user_email_addresses_path(@user)
  57. }
  58. format.js {
  59. @address = nil
  60. index
  61. render :action => 'index'
  62. }
  63. end
  64. end
  65. def destroy
  66. @address.destroy
  67. respond_to do |format|
  68. format.html {
  69. redirect_to user_email_addresses_path(@user)
  70. }
  71. format.js {
  72. @address = nil
  73. index
  74. render :action => 'index'
  75. }
  76. end
  77. end
  78. private
  79. def find_user
  80. @user = User.find(params[:user_id])
  81. end
  82. def find_email_address
  83. @address = @user.email_addresses.where(:is_default => false).find(params[:id])
  84. rescue ActiveRecord::RecordNotFound
  85. render_404
  86. end
  87. def require_admin_or_current_user
  88. unless @user == User.current
  89. require_admin
  90. end
  91. end
  92. end