diff --git a/lib/gitlab.rb b/lib/gitlab.rb index b87ba9538..02c9bdace 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -49,8 +49,10 @@ def self.http_proxy(address = nil, port = nil, username = nil, password = nil) # # @return [Array] def self.actions + # rubocop:disable Layout/LineLength hidden = - /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|\Adelete\z|validate\z|request_defaults|httparty/ + /endpoint|private_token|auth_token|user_agent|sudo|get|post|put|patch|\Adelete\z|validate\z|request_defaults|httparty/ + # rubocop:enable Layout/LineLength (Gitlab::Client.instance_methods - Object.methods).reject { |e| e[hidden] } end end diff --git a/lib/gitlab/client/users.rb b/lib/gitlab/client/users.rb index 39eb701a5..917f26285 100644 --- a/lib/gitlab/client/users.rb +++ b/lib/gitlab/client/users.rb @@ -393,5 +393,16 @@ def create_user_impersonation_token(user_id, name, scopes, expires_at = nil) def revoke_user_impersonation_token(user_id, impersonation_token_id) delete("/users/#{user_id}/impersonation_tokens/#{impersonation_token_id}") end + + # Disables two factor authentication (2FA) for the specified user. + # + # @example + # Gitlab.disable_two_factor(1) + # + # @param [Integer] id The ID of a user. + # @return [Gitlab::ObjectifiedHash] + def disable_two_factor(user_id) + patch("/users/#{user_id}/disable_two_factor") + end end end diff --git a/lib/gitlab/request.rb b/lib/gitlab/request.rb index 3d2abfcc1..218b81ba0 100644 --- a/lib/gitlab/request.rb +++ b/lib/gitlab/request.rb @@ -38,7 +38,7 @@ def self.decode(response) raise Error::Parsing, 'The response is not a valid JSON' end - %w[get post put delete].each do |method| + %w[get post put patch delete].each do |method| define_method method do |path, options = {}| params = options.dup diff --git a/spec/gitlab/client/users_spec.rb b/spec/gitlab/client/users_spec.rb index 715360738..63fe7a6fc 100644 --- a/spec/gitlab/client/users_spec.rb +++ b/spec/gitlab/client/users_spec.rb @@ -632,4 +632,18 @@ expect(@token.to_hash).to be_empty end end + + describe '.disable_two_factor' do + before do + stub_request(:patch, "#{Gitlab.endpoint}/users/1/disable_two_factor") + .with(headers: { 'PRIVATE-TOKEN' => Gitlab.private_token }) + .to_return(status: 204) + @token = Gitlab.disable_two_factor(1) + end + + it 'successfully disabled 2fa' do + expect(a_response(:patch, '/users/1/disable_two_factor')).to have_been_made + expect(@token.to_hash).to be_empty + end + end end