diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-09-20 14:18:08 +0300 |
commit | 5afcbe03ead9ada87621888a31a62652b10a7e4f (patch) | |
tree | 9918b67a0d0f0bafa6542e839a8be37adf73102d /lib/bulk_imports/groups/loaders/group_loader.rb | |
parent | c97c0201564848c1f53226fe19d71fdcc472f7d0 (diff) |
Add latest changes from gitlab-org/gitlab@16-4-stable-eev16.4.0-rc42
Diffstat (limited to 'lib/bulk_imports/groups/loaders/group_loader.rb')
-rw-r--r-- | lib/bulk_imports/groups/loaders/group_loader.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/bulk_imports/groups/loaders/group_loader.rb b/lib/bulk_imports/groups/loaders/group_loader.rb index 5f5307123a5..85d85f0f703 100644 --- a/lib/bulk_imports/groups/loaders/group_loader.rb +++ b/lib/bulk_imports/groups/loaders/group_loader.rb @@ -4,6 +4,8 @@ module BulkImports module Groups module Loaders class GroupLoader + TWO_FACTOR_KEY = 'require_two_factor_authentication' + GroupCreationError = Class.new(StandardError) def load(context, data) @@ -16,6 +18,10 @@ module BulkImports raise(GroupCreationError, 'User not allowed to create group') unless user_can_create_group?(current_user, data) raise(GroupCreationError, 'Group exists') if group_exists?(destination_namespace, path) + unless two_factor_requirements_met?(current_user, data) + raise(GroupCreationError, 'User requires Two-Factor Authentication') + end + group = ::Groups::CreateService.new(current_user, data).execute raise(GroupCreationError, group.errors.full_messages.to_sentence) if group.errors.any? @@ -37,6 +43,12 @@ module BulkImports end end + def two_factor_requirements_met?(current_user, data) + return true unless data.has_key?(TWO_FACTOR_KEY) && data[TWO_FACTOR_KEY] + + current_user.two_factor_enabled? + end + def group_exists?(destination_namespace, path) full_path = destination_namespace.present? ? File.join(destination_namespace, path) : path |