Commit 5a614293 authored by Patrick Bair's avatar Patrick Bair

Merge branch 'vfazio-suppress-deactivation-emails' into 'master'

Make user deactivation emails opt-in

See merge request gitlab-org/gitlab!68089
parents c686a69f 2ef7c260
......@@ -383,7 +383,8 @@ module ApplicationSettingsHelper
:container_registry_expiration_policies_worker_capacity,
:container_registry_cleanup_tags_service_max_list_size,
:keep_latest_artifact,
:whats_new_variant
:whats_new_variant,
:user_deactivation_emails_enabled
].tap do |settings|
settings << :deactivate_dormant_users unless Gitlab.com?
end
......
......@@ -208,7 +208,8 @@ module ApplicationSettingImplementation
kroki_url: nil,
kroki_formats: { blockdiag: false, bpmn: false, excalidraw: false },
rate_limiting_response_text: nil,
whats_new_variant: 0
whats_new_variant: 0,
user_deactivation_emails_enabled: true
}
end
......
......@@ -383,6 +383,8 @@ class User < ApplicationRecord
end
after_transition any => :deactivated do |user|
next unless Gitlab::CurrentSettings.user_deactivation_emails_enabled
NotificationService.new.user_deactivated(user.name, user.notification_email)
end
# rubocop: enable CodeReuse/ServiceClass
......
......@@ -33,4 +33,12 @@
.form-text.text-muted
= _('Send emails to help guide new users through the onboarding process.')
.form-group
.form-check
= f.check_box :user_deactivation_emails_enabled, class: 'form-check-input'
= f.label :user_deactivation_emails_enabled, class: 'form-check-label' do
= _('Enable user deactivation emails')
.form-text.text-muted
= _('Send emails to users upon account deactivation.')
= f.submit _('Save changes'), class: "gl-button btn btn-confirm", data: { qa_selector: 'save_changes_button' }
# frozen_string_literal: true
# See https://docs.gitlab.com/ee/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class AddUserDeactivationEmailOptionToApplicationSettings < ActiveRecord::Migration[6.1]
def change
add_column :application_settings, :user_deactivation_emails_enabled, :boolean, default: true, null: false
end
end
43d152f4235a07111a401be7b52a527571be04861c71381c311d6a48c8574dc9
\ No newline at end of file
......@@ -10372,6 +10372,7 @@ CREATE TABLE application_settings (
throttle_authenticated_git_lfs_requests_per_period integer DEFAULT 1000 NOT NULL,
throttle_authenticated_git_lfs_period_in_seconds integer DEFAULT 60 NOT NULL,
throttle_authenticated_git_lfs_enabled boolean DEFAULT false NOT NULL,
user_deactivation_emails_enabled boolean DEFAULT true NOT NULL,
CONSTRAINT app_settings_container_reg_cleanup_tags_max_list_size_positive CHECK ((container_registry_cleanup_tags_service_max_list_size >= 0)),
CONSTRAINT app_settings_ext_pipeline_validation_service_url_text_limit CHECK ((char_length(external_pipeline_validation_service_url) <= 255)),
CONSTRAINT app_settings_registry_exp_policies_worker_capacity_positive CHECK ((container_registry_expiration_policies_worker_capacity >= 0)),
......@@ -421,6 +421,7 @@ listed in the descriptions of the relevant settings.
| `unique_ips_limit_per_user` | integer | required by: `unique_ips_limit_enabled` | Maximum number of IPs per user. |
| `unique_ips_limit_time_window` | integer | required by: `unique_ips_limit_enabled` | How many seconds an IP is counted towards the limit. |
| `usage_ping_enabled` | boolean | no | Every week GitLab reports license usage back to GitLab, Inc. |
| `user_deactivation_emails_enabled` | boolean | no | Send an email to users upon account deactivation. |
| `user_default_external` | boolean | no | Newly registered users are external by default. |
| `user_default_internal_regex` | string | no | Specify an email address regex pattern to identify default internal users. |
| `user_oauth_applications` | boolean | no | Allow users to register any application to use GitLab as an OAuth provider. |
......
......@@ -153,6 +153,9 @@ For the deactivation option to be visible to an admin, the user:
NOTE:
Users can also be deactivated using the [GitLab API](../../api/users.md#deactivate-user).
NOTE:
Users can be notified about account deactivation if [user deactivation emails](settings/email.md#enable-user-deactivation-emails) are enabled.
### Automatically deactivate dormant users
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/320875) in GitLab 14.0.
......
......@@ -72,6 +72,18 @@ To add additional text to emails:
1. Enter your text in the **Additional text** field.
1. Select **Save changes**.
## Enable user deactivation emails **(FREE SELF)**
GitLab can send email notifications to users when their account has been deactivated.
To enable these notifications:
1. On the top bar, select **Menu > Admin**.
1. On the left sidebar, select **Settings > Preferences** (`/admin/application_settings/preferences`).
1. Expand **Email**.
1. Select **Enable user deactivation emails**.
1. Select **Save changes**.
<!-- ## Troubleshooting
Include any troubleshooting steps that you can foresee. If you know beforehand what issues
......
......@@ -176,6 +176,7 @@ module API
optional :require_admin_approval_after_user_signup, type: Boolean, desc: 'Require explicit admin approval for new signups'
optional :whats_new_variant, type: String, values: ApplicationSetting.whats_new_variants.keys, desc: "What's new variant, possible values: `all_tiers`, `current_tier`, and `disabled`."
optional :floc_enabled, type: Grape::API::Boolean, desc: 'Enable FloC (Federated Learning of Cohorts)'
optional :user_deactivation_emails_enabled, type: Boolean, desc: 'Send emails to users upon account deactivation'
ApplicationSetting::SUPPORTED_KEY_TYPES.each do |type|
optional :"#{type}_key_restriction",
......
......@@ -12544,6 +12544,9 @@ msgstr ""
msgid "Enable unauthenticated request rate limit"
msgstr ""
msgid "Enable user deactivation emails"
msgstr ""
msgid "Enable version check"
msgstr ""
......@@ -30347,6 +30350,9 @@ msgstr ""
msgid "Send emails to help guide new users through the onboarding process."
msgstr ""
msgid "Send emails to users upon account deactivation."
msgstr ""
msgid "Send message"
msgstr ""
......
......@@ -1858,6 +1858,17 @@ RSpec.describe User do
expect(user.deactivated?).to be_truthy
end
context "when user deactivation emails are disabled" do
before do
stub_application_setting(user_deactivation_emails_enabled: false)
end
it 'does not send deactivated user an email' do
expect(NotificationService).not_to receive(:new)
user.deactivate
end
end
context "when user deactivation emails are enabled" do
it 'sends deactivated user an email' do
expect_next_instance_of(NotificationService) do |notification|
allow(notification).to receive(:user_deactivated).with(user.name, user.notification_email)
......@@ -1866,6 +1877,7 @@ RSpec.describe User do
user.deactivate
end
end
end
context "a user who is blocked" do
before do
......
......@@ -47,6 +47,7 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting do
expect(json_response['personal_access_token_prefix']).to be_nil
expect(json_response['admin_mode']).to be(false)
expect(json_response['whats_new_variant']).to eq('all_tiers')
expect(json_response['user_deactivation_emails_enabled']).to be(true)
end
end
......@@ -133,6 +134,7 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting do
import_sources: 'github,bitbucket',
wiki_page_max_content_bytes: 12345,
personal_access_token_prefix: "GL-",
user_deactivation_emails_enabled: false,
admin_mode: true
}
......@@ -184,6 +186,7 @@ RSpec.describe API::Settings, 'Settings', :do_not_mock_admin_mode_setting do
expect(json_response['wiki_page_max_content_bytes']).to eq(12345)
expect(json_response['personal_access_token_prefix']).to eq("GL-")
expect(json_response['admin_mode']).to be(true)
expect(json_response['user_deactivation_emails_enabled']).to be(false)
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