Commit 71ca2de7 authored by Felipe Artur's avatar Felipe Artur

Toggle email signup confirmation in admin settings

parent 78a67fc4
...@@ -189,6 +189,7 @@ v 8.7.0 ...@@ -189,6 +189,7 @@ v 8.7.0
- Add Slack notifications when Wiki is edited (Sebastian Klier) - Add Slack notifications when Wiki is edited (Sebastian Klier)
- Diffs load at the correct point when linking from from number - Diffs load at the correct point when linking from from number
- Selected diff rows highlight - Selected diff rows highlight
- Toggle sign-up confirmation emails in application settings
- Fix emoji categories in the emoji picker - Fix emoji categories in the emoji picker
- API: Properly display annotated tags for GET /projects/:id/repository/tags (Robert Schilling) - API: Properly display annotated tags for GET /projects/:id/repository/tags (Robert Schilling)
- Add encrypted credentials for imported projects and migrate old ones - Add encrypted credentials for imported projects and migrate old ones
......
...@@ -106,6 +106,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController ...@@ -106,6 +106,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:email_author_in_body, :email_author_in_body,
:repository_checks_enabled, :repository_checks_enabled,
:metrics_packet_size, :metrics_packet_size,
:skip_user_confirmation_email,
restricted_visibility_levels: [], restricted_visibility_levels: [],
import_sources: [], import_sources: [],
disabled_oauth_sign_in_sources: [] disabled_oauth_sign_in_sources: []
......
...@@ -112,6 +112,7 @@ class User < ActiveRecord::Base ...@@ -112,6 +112,7 @@ class User < ActiveRecord::Base
before_save :ensure_external_user_rights before_save :ensure_external_user_rights
after_save :ensure_namespace_correct after_save :ensure_namespace_correct
after_initialize :set_projects_limit after_initialize :set_projects_limit
before_create :check_confirmation_email
after_create :post_create_hook after_create :post_create_hook
after_destroy :post_destroy_hook after_destroy :post_destroy_hook
...@@ -307,6 +308,10 @@ class User < ActiveRecord::Base ...@@ -307,6 +308,10 @@ class User < ActiveRecord::Base
@reset_token @reset_token
end end
def check_confirmation_email
skip_confirmation! if current_application_settings.skip_user_confirmation_email
end
def recently_sent_password_reset? def recently_sent_password_reset?
reset_password_sent_at.present? && reset_password_sent_at >= 1.minute.ago reset_password_sent_at.present? && reset_password_sent_at >= 1.minute.ago
end end
......
...@@ -103,6 +103,12 @@ ...@@ -103,6 +103,12 @@
= f.label :signup_enabled do = f.label :signup_enabled do
= f.check_box :signup_enabled = f.check_box :signup_enabled
Sign-up enabled Sign-up enabled
.form-group
.col-sm-offset-2.col-sm-10
.checkbox
= f.label :skip_confirmation_email do
= f.check_box :skip_user_confirmation_email
Skip sign-up email confirmation
.form-group .form-group
.col-sm-offset-2.col-sm-10 .col-sm-offset-2.col-sm-10
.checkbox .checkbox
......
class AddSkipConfirmationEmailToApplicationSettings < ActiveRecord::Migration
def change
#Skip confirmation emails just for new installations
default_value = User.count > 0 ? false : true
add_column :application_settings, :skip_user_confirmation_email, :boolean, default: default_value
end
end
require 'spec_helper'
describe RegistrationsController do
describe '#create' do
around(:each) do |example|
perform_enqueued_jobs do
example.run
end
end
let(:user_params) { { "user"=> {"name"=>"new_user", "username"=>"new_username", "email"=>"new@user.com", "password"=>"Any_password"} } }
context 'when skipping email confirmation' do
before { allow(current_application_settings).to receive(:skip_user_confirmation_email).and_return(true) }
it 'logs user in directly' do
post(:create, user_params)
expect(ActionMailer::Base.deliveries.last).to be_nil
expect(subject.current_user).to be
end
end
context 'when not skipping email confirmation' do
before { allow(current_application_settings).to receive(:skip_user_confirmation_email).and_return(false) }
it 'does not authenticate user and sends confirmation email' do
post(:create, user_params)
expect(ActionMailer::Base.deliveries.last.to.first).to eq(user_params["user"]["email"])
expect(subject.current_user).to be_nil
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment