debian-mirror-gitlab/lib/gitlab/git/user.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

45 lines
1.3 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Gitlab
module Git
class User
2021-09-30 23:02:18 +05:30
attr_reader :username, :name, :email, :gl_id, :timezone
2018-03-17 18:26:18 +05:30
def self.from_gitlab(gitlab_user)
2021-11-11 11:23:49 +05:30
new(gitlab_user.username, gitlab_user.name, gitlab_user.commit_email_or_default, Gitlab::GlId.gl_id(gitlab_user), gitlab_user.timezone)
2018-03-17 18:26:18 +05:30
end
def self.from_gitaly(gitaly_user)
new(
gitaly_user.gl_username,
Gitlab::EncodingHelper.encode!(gitaly_user.name),
Gitlab::EncodingHelper.encode!(gitaly_user.email),
2021-09-30 23:02:18 +05:30
gitaly_user.gl_id,
gitaly_user.timezone
2018-03-17 18:26:18 +05:30
)
end
2021-09-30 23:02:18 +05:30
def initialize(username, name, email, gl_id, timezone)
2018-03-17 18:26:18 +05:30
@username = username
@name = name
@email = email
@gl_id = gl_id
2021-09-30 23:02:18 +05:30
@timezone = if Feature.enabled?(:add_timezone_to_web_operations)
timezone
else
Time.zone.tzinfo.name
end
2018-03-17 18:26:18 +05:30
end
def ==(other)
2021-09-30 23:02:18 +05:30
[username, name, email, gl_id, timezone] == [other.username, other.name, other.email, other.gl_id, other.timezone]
2018-03-17 18:26:18 +05:30
end
def to_gitaly
2021-09-30 23:02:18 +05:30
Gitaly::User.new(gl_username: username, gl_id: gl_id, name: name.b, email: email.b, timezone: timezone)
2018-03-17 18:26:18 +05:30
end
end
end
end