Skip to content

Commit 4bb0649

Browse files
authored
Merge pull request #1093 from travis-ci/as-add-email-to-user-renderer
Add email to user renderer
2 parents 1af3f63 + f501a29 commit 4bb0649

File tree

5 files changed

+21
-5
lines changed

5 files changed

+21
-5
lines changed

lib/travis/api/v3/renderer/user.rb

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,26 @@
22

33
module Travis::API::V3
44
class Renderer::User < Renderer::Owner
5-
representation(:standard, :is_syncing, :synced_at, :recently_signed_up, :secure_user_hash)
5+
representation(:standard, :email, :is_syncing, :synced_at, :recently_signed_up, :secure_user_hash)
66
representation(:additional, :emails)
77

8+
def email
9+
@model.email if current_user?
10+
end
11+
812
def emails
9-
return @model.emails.map(&:email) if access_control.class == Travis::API::V3::AccessControl::LegacyToken && access_control.user.id == @model.id
10-
[]
13+
current_user? ? @model.emails.map(&:email) : []
1114
end
1215

1316
def secure_user_hash
1417
hmac_secret_key = Travis.config.intercom && Travis.config.intercom.hmac_secret_key.to_s
1518
OpenSSL::HMAC.hexdigest('sha256', hmac_secret_key, @model.id.to_s) if @model.id && hmac_secret_key
1619
end
20+
21+
private
22+
23+
def current_user?
24+
access_control.class == Travis::API::V3::AccessControl::LegacyToken && access_control.user.id == @model.id
25+
end
1726
end
1827
end

spec/v3/services/installation/find_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"id" => 1,
4848
"login" => user.login,
4949
"name" => user.name,
50+
"email" => "[email protected]",
5051
"github_id" => nil,
5152
"vcs_id" => user.vcs_id,
5253
"vcs_type" => user.vcs_type,

spec/v3/services/owner/find_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@
250250
"id" => user.id,
251251
"login" => "example-user",
252252
"name" => nil,
253+
"email" => nil,
253254
"github_id" => 5678,
254255
"vcs_id" => user.vcs_id,
255256
"vcs_type" => user.vcs_type,
@@ -274,6 +275,7 @@
274275
"id" => user.id,
275276
"login" => "example-user",
276277
"name" => nil,
278+
"email" => nil,
277279
"github_id" => 5678,
278280
"vcs_id" => user.vcs_id,
279281
"vcs_type" => user.vcs_type,
@@ -298,6 +300,7 @@
298300
"id" => user.id,
299301
"login" => "example-user",
300302
"name" => nil,
303+
"email" => nil,
301304
"github_id" => 5678,
302305
"vcs_id" => user.vcs_id,
303306
"vcs_type" => user.vcs_type,
@@ -326,6 +329,7 @@
326329
"id" => user.id,
327330
"login" => "example-user",
328331
"name" => nil,
332+
"email" => nil,
329333
"github_id" => 5678,
330334
"vcs_id" => user.vcs_id,
331335
"vcs_type" => user.vcs_type,

spec/v3/services/user/current_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"@permissions" => {"read"=>true, "sync"=>true},
1515
"id" => user.id,
1616
"login" => "svenfuchs",
17-
"name" =>"Sven Fuchs",
17+
"name" => "Sven Fuchs",
18+
"email" => "[email protected]",
1819
"github_id" => user.github_id,
1920
"vcs_id" => user.vcs_id,
2021
"vcs_type" => user.vcs_type,

spec/v3/services/user/find_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"@permissions" => {"read"=>true, "sync"=>true},
2020
"id" => user.id,
2121
"login" => "svenfuchs",
22-
"name" =>"Sven Fuchs",
22+
"name" => "Sven Fuchs",
23+
"email" => "[email protected]",
2324
"github_id" => user.github_id,
2425
"vcs_id" => user.vcs_id,
2526
"vcs_type" => user.vcs_type,

0 commit comments

Comments
 (0)