summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2016-04-21 15:55:54 -0300
committerFelipe Artur <felipefac@gmail.com>2016-05-16 14:56:32 -0300
commit71ca2de7aabf3191c4f486ca15a78a5b7f6abd94 (patch)
treef6520c7169d91aecaa3f9c3960cff11c29f5088f
parent78a67fc48dab434b43a080e5b15491963656661a (diff)
downloadgitlab-ce-71ca2de7aabf3191c4f486ca15a78a5b7f6abd94.tar.gz
Toggle email signup confirmation in admin settings
-rw-r--r--CHANGELOG1
-rw-r--r--app/controllers/admin/application_settings_controller.rb1
-rw-r--r--app/models/user.rb5
-rw-r--r--app/views/admin/application_settings/_form.html.haml6
-rw-r--r--db/migrate/20160421141709_add_skip_confirmation_email_to_application_settings.rb8
-rw-r--r--spec/controllers/registrations_controller_spec.rb33
6 files changed, 54 insertions, 0 deletions
diff --git a/CHANGELOG b/CHANGELOG
index ca59f488e0f..7a86263c0a9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -189,6 +189,7 @@ v 8.7.0
- Add Slack notifications when Wiki is edited (Sebastian Klier)
- Diffs load at the correct point when linking from from number
- Selected diff rows highlight
+ - Toggle sign-up confirmation emails in application settings
- Fix emoji categories in the emoji picker
- API: Properly display annotated tags for GET /projects/:id/repository/tags (Robert Schilling)
- Add encrypted credentials for imported projects and migrate old ones
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index 8c973f0e4a8..956d145f029 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -106,6 +106,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:email_author_in_body,
:repository_checks_enabled,
:metrics_packet_size,
+ :skip_user_confirmation_email,
restricted_visibility_levels: [],
import_sources: [],
disabled_oauth_sign_in_sources: []
diff --git a/app/models/user.rb b/app/models/user.rb
index 489bff3fa4a..470734f5c2f 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -112,6 +112,7 @@ class User < ActiveRecord::Base
before_save :ensure_external_user_rights
after_save :ensure_namespace_correct
after_initialize :set_projects_limit
+ before_create :check_confirmation_email
after_create :post_create_hook
after_destroy :post_destroy_hook
@@ -307,6 +308,10 @@ class User < ActiveRecord::Base
@reset_token
end
+ def check_confirmation_email
+ skip_confirmation! if current_application_settings.skip_user_confirmation_email
+ end
+
def recently_sent_password_reset?
reset_password_sent_at.present? && reset_password_sent_at >= 1.minute.ago
end
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
index f7c799c968f..6d6d87cdd5a 100644
--- a/app/views/admin/application_settings/_form.html.haml
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -106,6 +106,12 @@
.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
+ .col-sm-offset-2.col-sm-10
+ .checkbox
= f.label :signin_enabled do
= f.check_box :signin_enabled
Sign-in enabled
diff --git a/db/migrate/20160421141709_add_skip_confirmation_email_to_application_settings.rb b/db/migrate/20160421141709_add_skip_confirmation_email_to_application_settings.rb
new file mode 100644
index 00000000000..953f1cea896
--- /dev/null
+++ b/db/migrate/20160421141709_add_skip_confirmation_email_to_application_settings.rb
@@ -0,0 +1,8 @@
+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
diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb
new file mode 100644
index 00000000000..b4ab767f73e
--- /dev/null
+++ b/spec/controllers/registrations_controller_spec.rb
@@ -0,0 +1,33 @@
+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