diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb index fa8951bf64242155e262be64e0d7d5bcdc2be15b..29a759fa18ac1d573f2469ae5dbc47fb8c90a91d 100644 --- a/app/models/application_setting.rb +++ b/app/models/application_setting.rb @@ -410,6 +410,13 @@ def self.kroki_formats_attributes allow_nil: false, inclusion: { in: [true, false], message: _('must be a boolean value') } + # rubocop:disable Cop/StaticTranslationDefinition + validates :deactivate_dormant_users_period, + presence: true, + numericality: { only_integer: true, greater_than_or_equal_to: 90, message: _("'%{value}' days of inactivity must be greater than or equal to 90") }, + if: :deactivate_dormant_users? + # rubocop:enable Cop/StaticTranslationDefinition + Gitlab::SSHPublicKey.supported_types.each do |type| validates :"#{type}_key_restriction", presence: true, key_restriction: { type: type } end diff --git a/app/views/admin/application_settings/_account_and_limit.html.haml b/app/views/admin/application_settings/_account_and_limit.html.haml index e676dae37b3ac355e2d108e0c55d7f6cabb364fe..0959453b34c3aeabc5f33e0e69cc509973dfa893 100644 --- a/app/views/admin/application_settings/_account_and_limit.html.haml +++ b/app/views/admin/application_settings/_account_and_limit.html.haml @@ -54,10 +54,10 @@ - dormant_users_help_link_start = ''.html_safe % { url: dormant_users_help_link } = f.gitlab_ui_checkbox_component :deactivate_dormant_users, _('Deactivate dormant users after a period of inactivity'), help_text: _('Users can reactivate their account by signing in. %{link_start}Learn more.%{link_end}').html_safe % { link_start: dormant_users_help_link_start, link_end: ''.html_safe } .form-group - = f.label :deactivate_dormant_users_period, _('Period of inactivity (days)'), class: 'label-light' - = f.number_field :deactivate_dormant_users_period, class: 'form-control gl-form-input', min: '1' + = f.label :deactivate_dormant_users_period, _('Days of inactivity before deactivation'), class: 'label-light' + = f.number_field :deactivate_dormant_users_period, class: 'form-control gl-form-input', min: '90', step: '1' .form-text.text-muted - = _('Period of inactivity before deactivation.') + = _('Must be 90 days or more.') .form-group = f.label :personal_access_token_prefix, _('Personal Access Token prefix'), class: 'label-light' diff --git a/db/post_migrate/20221013154159_update_invalid_dormant_user_setting.rb b/db/post_migrate/20221013154159_update_invalid_dormant_user_setting.rb new file mode 100644 index 0000000000000000000000000000000000000000..1f1e47fdac113ba526749abe89a4d857bef1205b --- /dev/null +++ b/db/post_migrate/20221013154159_update_invalid_dormant_user_setting.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +class UpdateInvalidDormantUserSetting < Gitlab::Database::Migration[2.0] + disable_ddl_transaction! + + restrict_gitlab_migration gitlab_schema: :gitlab_main + + # rubocop:disable Layout/LineLength + def up + execute("update application_settings set deactivate_dormant_users_period=90 where deactivate_dormant_users_period < 90") + end + # rubocop:enable Layout/LineLength + + def down + # no-op + end +end diff --git a/db/schema_migrations/20221013154159 b/db/schema_migrations/20221013154159 new file mode 100644 index 0000000000000000000000000000000000000000..2e147bb199dc736c3363de67369bfba33a947f29 --- /dev/null +++ b/db/schema_migrations/20221013154159 @@ -0,0 +1 @@ +dbf241baf6d3deb1ef29a7cdca012050cab51c5f86762a0363d9dc4dc14fd804 \ No newline at end of file diff --git a/doc/user/admin_area/moderate_users.md b/doc/user/admin_area/moderate_users.md index fa2bf4b9616e94568cb4611c97580673d705f27a..ace1c6be5f84e24eeb07c54dc284b1ff319e20e2 100644 --- a/doc/user/admin_area/moderate_users.md +++ b/doc/user/admin_area/moderate_users.md @@ -171,11 +171,12 @@ Users can also be deactivated using the [GitLab API](../../api/users.md#deactiva > - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/320875) in GitLab 14.0. > - Customizable time period [introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/336747) in GitLab 15.4 +> - The lower limit for inactive period set to 90 days [introduced](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/100793) in GitLab 15.5 Administrators can enable automatic deactivation of users who either: - Were created more than a week ago and have not signed in. -- Have no activity for a specified period of time (defaults to 90 days). +- Have no activity for a specified period of time (default and minimum is 90 days). To do this: @@ -183,7 +184,7 @@ To do this: 1. On the left sidebar, select **Settings > General**. 1. Expand the **Account and limit** section. 1. Under **Dormant users**, check **Deactivate dormant users after a period of inactivity**. -1. Under **Period of inactivity (days)**, enter a period of time before deactivation. +1. Under **Days of inactivity before deactivation**, enter the number of days before deactivation. Minimum value is 90 days. 1. Select **Save changes**. When this feature is enabled, GitLab runs a job once a day to deactivate the dormant users. diff --git a/locale/gitlab.pot b/locale/gitlab.pot index e40527d7301d5559b4e90d198b56ecbba8d37b51..90e238273923d7574dcb3236a0fe8a83b881e73c 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -1253,6 +1253,9 @@ msgstr "" msgid "'%{template_name}' is unknown or invalid" msgstr "" +msgid "'%{value}' days of inactivity must be greater than or equal to 90" +msgstr "" + msgid "(%d closed)" msgid_plural "(%d closed)" msgstr[0] "" @@ -12556,6 +12559,9 @@ msgstr "" msgid "Days" msgstr "" +msgid "Days of inactivity before deactivation" +msgstr "" + msgid "Days to merge" msgstr "" @@ -26414,6 +26420,9 @@ msgstr "" msgid "Multiplier to apply to polling intervals. Decimal values are supported. Defaults to 1." msgstr "" +msgid "Must be 90 days or more." +msgstr "" + msgid "My awesome group" msgstr "" @@ -29342,12 +29351,6 @@ msgstr "" msgid "Period in seconds" msgstr "" -msgid "Period of inactivity (days)" -msgstr "" - -msgid "Period of inactivity before deactivation." -msgstr "" - msgid "Permalink" msgstr "" diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 9e7666b920fa25b62f657509957782c63f19b08a..94c5f397670814cf190a13b6a145adcf4eaa091a 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -177,10 +177,10 @@ end it 'change Dormant users period' do - expect(page).to have_field _('Period of inactivity (days)') + expect(page).to have_field _('Days of inactivity before deactivation') page.within(find('[data-testid="account-limit"]')) do - fill_in _('application_setting_deactivate_dormant_users_period'), with: '35' + fill_in _('application_setting_deactivate_dormant_users_period'), with: '90' click_button 'Save changes' end @@ -188,7 +188,7 @@ page.refresh - expect(page).to have_field _('Period of inactivity (days)'), with: '35' + expect(page).to have_field _('Days of inactivity before deactivation'), with: '90' end end end diff --git a/spec/migrations/20221013154159_update_invalid_dormant_user_setting_spec.rb b/spec/migrations/20221013154159_update_invalid_dormant_user_setting_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..eac71e428be9164df2648595b05a690057d088a7 --- /dev/null +++ b/spec/migrations/20221013154159_update_invalid_dormant_user_setting_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe UpdateInvalidDormantUserSetting, :migration do + let(:settings) { table(:application_settings) } + + context 'with no rows in the application_settings table' do + it 'does not insert a row' do + expect { migrate! }.to not_change { settings.count } + end + end + + context 'with a row in the application_settings table' do + before do + settings.create!(deactivate_dormant_users_period: days) + end + + context 'with deactivate_dormant_users_period set to a value greater than or equal to 90' do + let(:days) { 90 } + + it 'does not update the row' do + expect { migrate! } + .to not_change { settings.count } + .and not_change { settings.first.deactivate_dormant_users_period } + end + end + + context 'with deactivate_dormant_users_period set to a value less than or equal to 90' do + let(:days) { 1 } + + it 'updates the existing row' do + expect { migrate! } + .to not_change { settings.count } + .and change { settings.first.deactivate_dormant_users_period } + end + end + end +end diff --git a/spec/models/application_setting_spec.rb b/spec/models/application_setting_spec.rb index 687ffbe87bfb89c489491acc2b8dde332caca1f8..77bb6b502b5d0ed482a41b8e62fca871e2f2bb5e 100644 --- a/spec/models/application_setting_spec.rb +++ b/spec/models/application_setting_spec.rb @@ -203,6 +203,17 @@ def many_usernames(num = 100) it { is_expected.to allow_value([]).for(:valid_runner_registrars) } it { is_expected.to allow_value(%w(project group)).for(:valid_runner_registrars) } + context 'when deactivate_dormant_users is enabled' do + before do + stub_application_setting(deactivate_dormant_users: true) + end + + it { is_expected.not_to allow_value(nil).for(:deactivate_dormant_users_period) } + it { is_expected.to allow_value(90).for(:deactivate_dormant_users_period) } + it { is_expected.to allow_value(365).for(:deactivate_dormant_users_period) } + it { is_expected.not_to allow_value(89).for(:deactivate_dormant_users_period) } + end + context 'help_page_documentation_base_url validations' do it { is_expected.to allow_value(nil).for(:help_page_documentation_base_url) } it { is_expected.to allow_value('https://docs.gitlab.com').for(:help_page_documentation_base_url) } diff --git a/spec/models/ci/variable_spec.rb b/spec/models/ci/variable_spec.rb index f0af229ff2cb4b9d2efe627224b06e77ee486ea7..5f2b5971508272c99bfe4ef07d0835af3e8464f5 100644 --- a/spec/models/ci/variable_spec.rb +++ b/spec/models/ci/variable_spec.rb @@ -47,7 +47,7 @@ context 'loose foreign key on ci_variables.project_id' do it_behaves_like 'cleanup by a loose foreign key' do - let!(:parent) { create(:project) } + let!(:parent) { create(:project, namespace: create(:group)) } let!(:model) { create(:ci_variable, project: parent) } end end