diff --git a/app/models/user.rb b/app/models/user.rb index b54ce14f0bf..b9bb4a9e3f7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -512,7 +512,7 @@ class User < ActiveRecord::Base end def require_ssh_key? - keys.count == 0 + keys.count == 0 && Gitlab::ProtocolAccess.allowed?('ssh') end def require_password? diff --git a/changelogs/unreleased/24921-hide-prompt-to-add-ssh-key-if-ssh-protocol-is-disabled.yml b/changelogs/unreleased/24921-hide-prompt-to-add-ssh-key-if-ssh-protocol-is-disabled.yml new file mode 100644 index 00000000000..4d4019e770e --- /dev/null +++ b/changelogs/unreleased/24921-hide-prompt-to-add-ssh-key-if-ssh-protocol-is-disabled.yml @@ -0,0 +1,4 @@ +--- +title: Don't display prompt to add SSH keys if SSH protocol is disabled +merge_request: 7840 +author: Andrew Smith (EspadaV8) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 14c891994d0..2244803f90c 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -575,6 +575,23 @@ describe User, models: true do end end end + + describe '#require_ssh_key?' do + protocol_and_expectation = { + 'http' => false, + 'ssh' => true, + '' => true, + } + + protocol_and_expectation.each do |protocol, expected| + it "has correct require_ssh_key?" do + stub_application_setting(enabled_git_access_protocol: protocol) + user = build(:user) + + expect(user.require_ssh_key?).to eq(expected) + end + end + end end describe '.find_by_any_email' do