Skip to content

Commit 929de8f

Browse files
authored
Negative balance notification fix (#1134)
fix + allowance also in minimal owner representation - for repositories endpoint
1 parent d9891d7 commit 929de8f

File tree

15 files changed

+272
-4
lines changed

15 files changed

+272
-4
lines changed

lib/travis/api/app/endpoint/authorization.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,10 @@ def vcs_handshake
210210
redirect to(vcs_data['redirect_uri'])
211211
return
212212
end
213+
214+
user = User.find(vcs_data['user']['id'])
213215
update_first_login(user)
214-
yield serialize_user(User.find(vcs_data['user']['id'])), vcs_data['token'], payload(params[:provider])
216+
yield serialize_user(user), vcs_data['token'], payload(params[:provider])
215217
else
216218
state = vcs_create_state(params[:origin] || params[:redirect_uri])
217219

lib/travis/api/v3/billing_client.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def initialize(user_id)
88

99
def allowance(owner_type, owner_id)
1010
response = connection.get("/usage/#{owner_type.downcase}s/#{owner_id}/allowance")
11-
return default_allowance_response unless response.status == 200
11+
return BillingClient.default_allowance_response unless response.status == 200
1212

1313
Travis::API::V3::Models::Allowance.new(2, response.body)
1414
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Travis::API::V3
44
class Renderer::Owner < ModelRenderer
55
include Renderer::AvatarURL
66

7-
representation(:minimal, :id, :login, :vcs_type)
7+
representation(:minimal, :id, :login, :vcs_type, :allowance)
88
representation(:standard, :id, :login, :name, :github_id, :vcs_id, :vcs_type, :avatar_url, :education,
99
:allow_migration, :allowance)
1010
representation(:additional, :repositories, :installation)

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def owner
7575
if included_owner? and owner_href
7676
{ :@href => owner_href }
7777
else
78-
result = { :@type => owner_type, :id => model.owner_id, :login => model.owner_name }
78+
result = { :@type => owner_type, :id => model.owner_id, :login => model.owner_name, :allowance => owner_allowance }
7979
result[:@href] = owner_href if owner_href
8080
result
8181
end
@@ -96,6 +96,16 @@ def owner_type
9696
@owner_type ||= model.owner_type.downcase if model.owner_type
9797
end
9898

99+
def owner_allowance
100+
@owner_allowance ||= begin
101+
return BillingClient.default_allowance_response if Travis.config.org?
102+
return BillingClient.default_allowance_response unless access_control.user
103+
104+
client = BillingClient.new(access_control.user.id)
105+
client.allowance(owner_type, model.owner_id)
106+
end
107+
end
108+
99109
def managed_by_installation
100110
model.managed_by_installation?
101111
end

spec/v3/services/installation/find_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
"github_id" => installation.github_id,
1919
"owner" => {
2020
"@type"=>"user",
21+
"allowance" => {
22+
"@representation" => "minimal",
23+
"@type" => "allowance",
24+
"concurrency_limit" => 1,
25+
"private_repos" => false,
26+
"public_repos" => true,
27+
"subscription_type" => 1
28+
},
2129
"@href"=>"/v3/user/#{user.id}",
2230
"@representation"=>"minimal",
2331
"id"=>user.id,

spec/v3/services/job/find_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@
102102
"committed_at" => "2010-11-12T11:50:00Z"},
103103
"owner" => {
104104
"@type" => owner_type.to_s.downcase,
105+
"allowance" => {
106+
"@representation" => "minimal",
107+
"@type" => "allowance",
108+
"concurrency_limit" => 1,
109+
"private_repos" => false,
110+
"public_repos" => true,
111+
"subscription_type" => 1
112+
},
105113
"@href" => "/v3/#{owner_href}/#{owner.id}",
106114
"@representation" => "minimal",
107115
"id" => owner.id,
@@ -214,6 +222,14 @@
214222
"committed_at" => "2010-11-12T11:50:00Z"},
215223
"owner" => {
216224
"@type" => owner_type.to_s.downcase,
225+
"allowance" => {
226+
"@representation" => "minimal",
227+
"@type" => "allowance",
228+
"concurrency_limit" => 1,
229+
"private_repos" => false,
230+
"public_repos" => true,
231+
"subscription_type" => 1
232+
},
217233
"@href" => "/v3/#{owner_href}/#{owner.id}",
218234
"@representation" => "minimal",
219235
"id" => owner.id,
@@ -289,6 +305,14 @@
289305
"committed_at" => "2010-11-12T11:50:00Z"},
290306
"owner" => {
291307
"@type" => owner_type.to_s.downcase,
308+
"allowance" => {
309+
"@representation" => "minimal",
310+
"@type" => "allowance",
311+
"concurrency_limit" => 1,
312+
"private_repos" => false,
313+
"public_repos" => true,
314+
"subscription_type" => 1
315+
},
292316
"@href" => "/v3/#{owner_href}/#{owner.id}",
293317
"@representation" => "minimal",
294318
"id" => owner.id,

spec/v3/services/jobs/find_spec.rb

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@
9292
"committed_at" => "2010-11-12T12:55:00Z"},
9393
"owner" => {
9494
"@type" => "user",
95+
"allowance" => {
96+
"@representation" => "minimal",
97+
"@type" => "allowance",
98+
"concurrency_limit" => 1,
99+
"private_repos" => false,
100+
"public_repos" => true,
101+
"subscription_type" => 1
102+
},
95103
"@href" => "/v3/user/1",
96104
"@representation" => "minimal",
97105
"id" => 1,
@@ -165,6 +173,14 @@
165173
"committed_at" => "2010-11-12T12:55:00Z"},
166174
"owner" => {
167175
"@type" => "user",
176+
"allowance" => {
177+
"@representation" => "minimal",
178+
"@type" => "allowance",
179+
"concurrency_limit" => 1,
180+
"private_repos" => false,
181+
"public_repos" => true,
182+
"subscription_type" => 1
183+
},
168184
"@href" => "/v3/user/1",
169185
"@representation" => "minimal",
170186
"id" => 1,
@@ -238,6 +254,14 @@
238254
"committed_at" => "2010-11-12T12:55:00Z"},
239255
"owner" => {
240256
"@type" => "user",
257+
"allowance" => {
258+
"@representation" => "minimal",
259+
"@type" => "allowance",
260+
"concurrency_limit" => 1,
261+
"private_repos" => false,
262+
"public_repos" => true,
263+
"subscription_type" => 1
264+
},
241265
"@href" => "/v3/user/1",
242266
"@representation" => "minimal",
243267
"id" => 1,
@@ -311,6 +335,14 @@
311335
"committed_at" => "2010-11-12T12:55:00Z"},
312336
"owner" => {
313337
"@type" => "user",
338+
"allowance" => {
339+
"@representation" => "minimal",
340+
"@type" => "allowance",
341+
"concurrency_limit" => 1,
342+
"private_repos" => false,
343+
"public_repos" => true,
344+
"subscription_type" => 1
345+
},
314346
"@href" => "/v3/user/1",
315347
"@representation" => "minimal",
316348
"id" => 1,
@@ -402,6 +434,14 @@
402434
"committed_at" => "2010-11-12T12:55:00Z"},
403435
"owner" => {
404436
"@type" => "user",
437+
"allowance" => {
438+
"@representation" => "minimal",
439+
"@type" => "allowance",
440+
"concurrency_limit" => 1,
441+
"private_repos" => false,
442+
"public_repos" => true,
443+
"subscription_type" => 1
444+
},
405445
"@href" => "/v3/user/1",
406446
"@representation" => "minimal",
407447
"id" => 1,
@@ -475,6 +515,14 @@
475515
"committed_at" => "2010-11-12T12:55:00Z"},
476516
"owner" => {
477517
"@type" => "user",
518+
"allowance" => {
519+
"@representation" => "minimal",
520+
"@type" => "allowance",
521+
"concurrency_limit" => 1,
522+
"private_repos" => false,
523+
"public_repos" => true,
524+
"subscription_type" => 1
525+
},
478526
"@href" => "/v3/user/1",
479527
"@representation" => "minimal",
480528
"id" => 1,
@@ -548,6 +596,14 @@
548596
"committed_at" => "2010-11-12T12:55:00Z"},
549597
"owner" => {
550598
"@type" => "user",
599+
"allowance" => {
600+
"@representation" => "minimal",
601+
"@type" => "allowance",
602+
"concurrency_limit" => 1,
603+
"private_repos" => false,
604+
"public_repos" => true,
605+
"subscription_type" => 1
606+
},
551607
"@href" => "/v3/user/1",
552608
"@representation" => "minimal",
553609
"id" => 1,
@@ -621,6 +677,14 @@
621677
"committed_at" => "2010-11-12T12:55:00Z"},
622678
"owner" => {
623679
"@type" => "user",
680+
"allowance" => {
681+
"@representation" => "minimal",
682+
"@type" => "allowance",
683+
"concurrency_limit" => 1,
684+
"private_repos" => false,
685+
"public_repos" => true,
686+
"subscription_type" => 1
687+
},
624688
"@href" => "/v3/user/1",
625689
"@representation" => "minimal",
626690
"id" => 1,
@@ -714,6 +778,14 @@
714778
"committed_at" =>"2010-11-12T12:55:00Z"},
715779
"owner" =>{
716780
"@type" => "user",
781+
"allowance" => {
782+
"@type" => "allowance",
783+
"@representation" => "minimal",
784+
"subscription_type" => 1,
785+
"public_repos" => true,
786+
"private_repos" => false,
787+
"concurrency_limit" => 1
788+
},
717789
"@href" => "/v3/user/1",
718790
"@representation"=> "minimal",
719791
"id" => 1,
@@ -787,6 +859,14 @@
787859
"committed_at" =>"2010-11-12T12:55:00Z"},
788860
"owner" =>{
789861
"@type" => "user",
862+
"allowance" => {
863+
"@representation" => "minimal",
864+
"@type" => "allowance",
865+
"concurrency_limit" => 1,
866+
"private_repos" => false,
867+
"public_repos" => true,
868+
"subscription_type" => 1
869+
},
790870
"@href" => "/v3/user/1",
791871
"@representation"=> "minimal",
792872
"id" => 1,
@@ -860,6 +940,14 @@
860940
"committed_at" =>"2010-11-12T12:55:00Z"},
861941
"owner" =>{
862942
"@type" => "user",
943+
"allowance" => {
944+
"@representation" => "minimal",
945+
"@type" => "allowance",
946+
"concurrency_limit" => 1,
947+
"private_repos" => false,
948+
"public_repos" => true,
949+
"subscription_type" => 1
950+
},
863951
"@href" => "/v3/user/1",
864952
"@representation"=> "minimal",
865953
"id" => 1,
@@ -933,6 +1021,14 @@
9331021
"committed_at" =>"2010-11-12T12:55:00Z"},
9341022
"owner" =>{
9351023
"@type" => "user",
1024+
"allowance" => {
1025+
"@representation" => "minimal",
1026+
"@type" => "allowance",
1027+
"concurrency_limit" => 1,
1028+
"private_repos" => false,
1029+
"public_repos" => true,
1030+
"subscription_type" => 1
1031+
},
9361032
"@href" => "/v3/user/1",
9371033
"@representation"=> "minimal",
9381034
"id" => 1,

spec/v3/services/repositories/for_current_user_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@
6666
"shared" => false,
6767
"owner" => {
6868
"@type" => "user",
69+
"allowance" => {
70+
"@representation" => "minimal",
71+
"@type" => "allowance",
72+
"concurrency_limit" => 1,
73+
"private_repos" => false,
74+
"public_repos" => true,
75+
"subscription_type" => 1
76+
},
6977
"@href" => "/v3/user/#{repo.owner_id}",
7078
"id" => repo.owner_id,
7179
"login" => "svenfuchs" },

0 commit comments

Comments
 (0)