diff options
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 |