Commit a0a9494e authored by Dravere's avatar Dravere

Added setting to set new users by default as external

As requested by the issue #14508 this adds an option in the application
settings to set newly registered users by default as external. The
default setting is set to false to stay backward compatible.
parent 062c7a30
......@@ -49,6 +49,7 @@ v 8.10.0 (unreleased)
- Fix importer for GitHub Pull Requests when a branch was reused across Pull Requests
- Add date when user joined the team on the member page
- Fix 404 redirect after validation fails importing a GitLab project
- Added setting to set new users by default as external !4545 (Dravere)
v 8.9.5
- Add more debug info to import/export and memory killer. !5108
......@@ -87,6 +87,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
......@@ -142,6 +142,7 @@ class ApplicationSetting < ActiveRecord::Base
send_user_confirmation_email: false,
container_registry_token_expire_delay: 5,
repository_storage: 'default',
user_default_external: false,
......@@ -15,7 +15,7 @@ class User < ActiveRecord::Base
add_authentication_token_field :authentication_token
default_value_for :admin, false
default_value_for :external, false
default_value_for(:external) { current_application_settings.user_default_external }
default_value_for :can_create_group, gitlab_config.default_can_create_group
default_value_for :can_create_team, false
default_value_for :hide_no_ssh_key, false
......@@ -100,6 +100,13 @@
= f.label :user_oauth_applications do
= f.check_box :user_oauth_applications
Allow users to register any application to use GitLab as an OAuth provider
= f.label :user_default_external, 'New users set to external', class: 'control-label col-sm-2'
= f.label :user_default_external do
= f.check_box :user_default_external
Newly registered users will by default be external
%legend Sign-in Restrictions
class AddUserDefaultExternalToApplicationSettings < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
def up
add_column_with_default(:application_settings, :user_default_external, :boolean,
default: false, allow_null: false)
def down
remove_column(:application_settings, :user_default_external)
......@@ -84,6 +84,7 @@ ActiveRecord::Schema.define(version: 20160705163108) do
t.string "health_check_access_token"
t.boolean "send_user_confirmation_email", default: false
t.integer "container_registry_token_expire_delay", default: 5
t.boolean "user_default_external", default: false, null: false
t.text "after_sign_up_text"
t.string "repository_storage", default: "default"
t.string "enabled_git_access_protocol"
......@@ -99,3 +99,6 @@ An administrator can flag a user as external [through the API](../api/
or by checking the checkbox on the admin panel. As an administrator, navigate
to **Admin > Users** to create a new user or edit an existing one. There, you
will find the option to flag the user as external.
By default new users are not set as external users. This behavior can be changed
by an administrator under **Admin > Application Settings**.
\ No newline at end of file
......@@ -48,6 +48,7 @@ module Gitlab
akismet_enabled: false,
repository_checks_enabled: true,
container_registry_token_expire_delay: 5,
user_default_external: false,
......@@ -446,6 +446,7 @@ describe User, models: true do
it { expect(user.can_create_group?).to be_truthy }
it { expect(user.can_create_project?).to be_truthy }
it { expect(user.first_name).to eq('John') }
it { expect(user.external).to be_falsey }
describe 'with defaults' do
......@@ -468,6 +469,26 @@ describe User, models: true do
expect(user.theme_id).to eq(1)
context 'when current_application_settings.user_default_external is true' do
before do
stub_application_setting(user_default_external: true)
it "creates external user by default" do
user = build(:user)
expect(user.external).to be_truthy
describe 'with default overrides' do
it "creates a non-external user" do
user = build(:user, external: false)
expect(user.external).to be_falsey
describe '.find_by_any_email' do
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