Skip to content

Commit

Permalink
Revert "Notify admins when a approval/invite user signs up"
Browse files Browse the repository at this point in the history
This reverts commit 251d85d.
  • Loading branch information
shawn-higgins1 committed May 21, 2019
1 parent 251d85d commit 0360c78
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 270 deletions.
19 changes: 0 additions & 19 deletions app/controllers/concerns/emailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,32 +41,13 @@ def send_user_approved_email(user)
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, root_url, logo_image, user_color, admin_emails).deliver_now
end

def send_invite_user_signup_email(user)
UserMailer.invite_user_signup(user, root_url, logo_image, user_color, admin_emails).deliver_now
end

private

# Returns the link the user needs to click to verify their account
def user_verification_link
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
Expand Down
11 changes: 2 additions & 9 deletions app/controllers/sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

class SessionsController < ApplicationController
include Registrar
include Emailer

skip_before_action :verify_authenticity_token, only: [:omniauth, :fail]

Expand Down Expand Up @@ -50,24 +49,18 @@ def omniauth
begin
@auth = request.env['omniauth.auth']
@user_exists = check_user_exists

# If using invitation registration method, make sure user is invited
return redirect_to root_path, flash: { alert: I18n.t("registration.invite.no_invite") } unless passes_invite_reqs

user = User.from_omniauth(@auth)

# 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}"
Expand Down
15 changes: 0 additions & 15 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def create
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

Expand Down Expand Up @@ -195,19 +193,6 @@ def send_verification
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?
Expand Down
18 changes: 0 additions & 18 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,4 @@ def approve_user(user, url, image, color)
@color = color
mail to: user.email, subject: t('mailer.user.approve.subject')
end

def approval_user_signup(user, url, image, color, admin_emails)
@user = user
@url = url + "admins"
@image = image
@color = color

mail to: admin_emails, subject: t('mailer.user.approve.signup.subject')
end

def invite_user_signup(user, url, image, color, admin_emails)
@user = user
@url = url + "admins"
@image = image
@color = color

mail to: admin_emails, subject: t('mailer.user.invite.signup.subject')
end
end
43 changes: 0 additions & 43 deletions app/views/user_mailer/approval_user_signup.html.erb

This file was deleted.

27 changes: 0 additions & 27 deletions app/views/user_mailer/approval_user_signup.text.erb

This file was deleted.

39 changes: 0 additions & 39 deletions app/views/user_mailer/invite_user_signup.html.erb

This file was deleted.

25 changes: 0 additions & 25 deletions app/views/user_mailer/invite_user_signup.text.erb

This file was deleted.

11 changes: 0 additions & 11 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,12 @@ en:
info: Your account has been approved.
signin: To access your personal rooms, click the button below and sign in.
signin_link: Sign In
signup:
info: A new user has signed up to use Greenlight.
more-info: To allow this user to access Greenlight you must approve their account in organization settings.
admins_link: Visit the Organization Page
subject: New Greenlight User Sign Up
username: The user signed up with the name %{name} and the email %{email}.
subject: Account Approved
username: Your username is %{email}.
invite:
info: You have been invited to your own personal space by %{name}
signup: To signup using your email, click the button below and follow the steps.
signup_link: Sign Up
signup:
info: A user that was invited has signed up to use Greenlight.
admins_link: Visit the Organization Page
subject: New Greenlight User Sign Up
username: The user signed up with the name %{name} and the email %{email}.
subject: Invitation to join BigBlueButton
username: Your username is %{email}.
password_reset:
Expand Down
28 changes: 0 additions & 28 deletions spec/controllers/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,34 +223,6 @@

expect(response).to redirect_to(root_path)
end

context 'registration notification emails' do
before do
allow(Rails.configuration).to receive(:enable_email_verification).and_return(true)
@user = create(:user, provider: "greenlight")
@admin = create(:user, provider: "greenlight", email: "[email protected]")
@admin.add_role :admin
end

it "should notify admin on new user signup with approve/reject registration" do
allow_any_instance_of(Registrar).to receive(:approval_registration).and_return(true)

request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:bn_launcher]

expect { get :omniauth, params: { provider: 'bn_launcher' } }.to change { ActionMailer::Base.deliveries.count }.by(1)
end

it "should notify admin on new user signup with invite registration" do
allow_any_instance_of(Registrar).to receive(:invite_registration).and_return(true)

invite = Invitation.create(email: "[email protected]", provider: "greenlight")
@request.session[:invite_token] = invite.invite_token

request.env["omniauth.auth"] = OmniAuth.config.mock_auth[:bn_launcher]

expect { get :omniauth, params: { provider: 'bn_launcher' } }.to change { ActionMailer::Base.deliveries.count }.by(1)
end
end
end

it "should not create session without omniauth env set for bn_launcher" do
Expand Down
22 changes: 0 additions & 22 deletions spec/controllers/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,6 @@ def random_valid_user_params
before do
allow_any_instance_of(Registrar).to receive(:invite_registration).and_return(true)
allow(Rails.configuration).to receive(:allow_user_signup).and_return(true)
@user = create(:user, provider: "greenlight")
@admin = create(:user, provider: "greenlight", email: "[email protected]")
@admin.add_role :admin
end

it "should notify admins that user signed up" do
params = random_valid_user_params
invite = Invitation.create(email: params[:user][:email], provider: "greenlight")
@request.session[:invite_token] = invite.invite_token

expect { post :create, params: params }.to change { ActionMailer::Base.deliveries.count }.by(1)
end

it "rejects the user if they are not invited" do
Expand Down Expand Up @@ -251,9 +240,6 @@ def random_valid_user_params
before do
allow_any_instance_of(Registrar).to receive(:approval_registration).and_return(true)
allow(Rails.configuration).to receive(:allow_user_signup).and_return(true)
@user = create(:user, provider: "greenlight")
@admin = create(:user, provider: "greenlight", email: "[email protected]")
@admin.add_role :admin
end

it "allows any user to sign up" do
Expand All @@ -279,14 +265,6 @@ def random_valid_user_params

expect(u.has_role?(:pending)).to eq(true)
end

it "notifies admins that a user signed up" do
allow(Rails.configuration).to receive(:enable_email_verification).and_return(true)

params = random_valid_user_params

expect { post :create, params: params }.to change { ActionMailer::Base.deliveries.count }.by(2)
end
end
end

Expand Down
14 changes: 0 additions & 14 deletions test/mailers/previews/user_mailer_preview.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,4 @@ def approve_user
user = User.first
UserMailer.approve_user(user, "http://example.com/", @logo, @color)
end

# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/approval_user_signup
def approval_user_signup
user = User.first
UserMailer.approval_user_signup(user, "http://example.com/", @logo, @color, "[email protected]")
end

# Preview this email at
# http://localhost:3000/rails/mailers/user_mailer/invite_user_signup
def invite_user_signup
user = User.first
UserMailer.invite_user_signup(user, "http://example.com/", @logo, @color, "[email protected]")
end
end

0 comments on commit 0360c78

Please sign in to comment.