forked from External/greenlight
GRN2-6: Notify admins when a approve/invite user signs up (#538)
* Notify admins when a approve/invite user signs up * Fix formating * Uses admins_url variable
This commit is contained in:
committed by
Jesus Federico
parent
83a9edf81d
commit
f88d67f6fb
@ -49,6 +49,14 @@ module Emailer
|
||||
UserMailer.approve_user(user, root_url, logo_image, user_color).deliver_now
|
||||
end
|
||||
|
||||
def send_approval_user_signup_email(user)
|
||||
UserMailer.approval_user_signup(user, admins_url, logo_image, user_color, admin_emails).deliver_now
|
||||
end
|
||||
|
||||
def send_invite_user_signup_email(user)
|
||||
UserMailer.invite_user_signup(user, admins_url, logo_image, user_color, admin_emails).deliver_now
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Returns the link the user needs to click to verify their account
|
||||
@ -56,6 +64,17 @@ module Emailer
|
||||
edit_account_activation_url(token: @user.activation_token, email: @user.email)
|
||||
end
|
||||
|
||||
def admin_emails
|
||||
admins = User.with_role(:admin)
|
||||
|
||||
if Rails.configuration.loadbalanced_configuration
|
||||
admins = admins.without_role(:super_admin)
|
||||
.where(provider: user_settings_provider)
|
||||
end
|
||||
|
||||
admins.collect(&:email).join(",")
|
||||
end
|
||||
|
||||
def reset_link
|
||||
edit_password_reset_url(@user.reset_token, email: @user.email)
|
||||
end
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
class SessionsController < ApplicationController
|
||||
include Registrar
|
||||
include Emailer
|
||||
|
||||
skip_before_action :verify_authenticity_token, only: [:omniauth, :fail]
|
||||
|
||||
@ -58,9 +59,16 @@ class SessionsController < ApplicationController
|
||||
# Add pending role if approval method and is a new user
|
||||
if approval_registration && !@user_exists
|
||||
user.add_role :pending
|
||||
|
||||
# Inform admins that a user signed up if emails are turned on
|
||||
send_approval_user_signup_email(user) if Rails.configuration.enable_email_verification
|
||||
|
||||
return redirect_to root_path, flash: { success: I18n.t("registration.approval.signup") }
|
||||
end
|
||||
|
||||
send_invite_user_signup_email(user) if Rails.configuration.enable_email_verification &&
|
||||
invite_registration && !@user_exists
|
||||
|
||||
login(user)
|
||||
rescue => e
|
||||
logger.error "Error authenticating via omniauth: #{e}"
|
||||
|
@ -50,6 +50,8 @@ class UsersController < ApplicationController
|
||||
flash: { success: I18n.t("registration.approval.signup") } unless Rails.configuration.enable_email_verification
|
||||
end
|
||||
|
||||
send_registration_email if Rails.configuration.enable_email_verification
|
||||
|
||||
# Sign in automatically if email verification is disabled or if user is already verified.
|
||||
login(@user) && return if !Rails.configuration.enable_email_verification || @user.email_verified
|
||||
|
||||
@ -193,6 +195,19 @@ class UsersController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def send_registration_email
|
||||
begin
|
||||
if invite_registration
|
||||
send_invite_user_signup_email(@user)
|
||||
elsif approval_registration
|
||||
send_approval_user_signup_email(@user)
|
||||
end
|
||||
rescue => e
|
||||
logger.error "Error in email delivery: #{e}"
|
||||
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error"))
|
||||
end
|
||||
end
|
||||
|
||||
# Add validation errors to model if they exist
|
||||
def valid_user_or_captcha
|
||||
valid_user = @user.valid?
|
||||
|
Reference in New Issue
Block a user