Commit 4bc16881 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'bvl-display-username-instead-of-fullname' into 'master'

Display the username instead of fullname

Closes #131

See merge request gitlab-org/gitlab-shell!204
parents aa1a39a9 4ba42756
v7.1.3
- Use username instead of full name for identifying users (!204)
v7.1.2 v7.1.2
- Add missing GitlabLogger#error method (!200) - Add missing GitlabLogger#error method (!200)
......
...@@ -18,7 +18,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -18,7 +18,7 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
API_COMMANDS = %w(2fa_recovery_codes).freeze API_COMMANDS = %w(2fa_recovery_codes).freeze
GL_PROTOCOL = 'ssh'.freeze GL_PROTOCOL = 'ssh'.freeze
attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access, :username attr_accessor :key_id, :gl_repository, :repo_name, :command, :git_access
attr_reader :repo_path attr_reader :repo_path
def initialize(key_id) def initialize(key_id)
...@@ -196,8 +196,14 @@ class GitlabShell # rubocop:disable Metrics/ClassLength ...@@ -196,8 +196,14 @@ class GitlabShell # rubocop:disable Metrics/ClassLength
end end
end end
def username_from_discover
return nil unless user && user['username']
"@#{user['username']}"
end
def username def username
user && user['name'] || 'Anonymous' @username ||= username_from_discover || 'Anonymous'
end end
# User identifier to be used in log messages. # User identifier to be used in log messages.
......
...@@ -31,7 +31,7 @@ describe GitlabShell do ...@@ -31,7 +31,7 @@ describe GitlabShell do
let(:api) do let(:api) do
double(GitlabNet).tap do |api| double(GitlabNet).tap do |api|
api.stub(discover: { 'name' => 'John Doe' }) api.stub(discover: { 'name' => 'John Doe', 'username' => 'testuser' })
api.stub(check_access: GitAccessStatus.new( api.stub(check_access: GitAccessStatus.new(
true, true,
'ok', 'ok',
...@@ -167,7 +167,7 @@ describe GitlabShell do ...@@ -167,7 +167,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -202,7 +202,7 @@ describe GitlabShell do ...@@ -202,7 +202,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -248,7 +248,7 @@ describe GitlabShell do ...@@ -248,7 +248,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -275,7 +275,7 @@ describe GitlabShell do ...@@ -275,7 +275,7 @@ describe GitlabShell do
it "should use usernames if configured to do so" do it "should use usernames if configured to do so" do
GitlabConfig.any_instance.stub(audit_usernames: true) GitlabConfig.any_instance.stub(audit_usernames: true)
$logger.should_receive(:info).with("executing git command", hash_including(user: 'John Doe')) $logger.should_receive(:info).with("executing git command", hash_including(user: 'testuser'))
end end
end end
...@@ -452,7 +452,7 @@ describe GitlabShell do ...@@ -452,7 +452,7 @@ describe GitlabShell do
before do before do
Kernel.stub(:exec) Kernel.stub(:exec)
shell.gl_repository = gl_repository shell.gl_repository = gl_repository
shell.username = gl_username shell.instance_variable_set(:@username, gl_username)
end end
it "uses Kernel::exec method" do it "uses Kernel::exec method" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment