@@ -56,19 +56,18 @@ defmodule Front.Models.User do
56
56
metadata = Keyword . get ( opts , :metadata , nil )
57
57
fields = Keyword . get ( opts , :fields , @ fields )
58
58
use_cache = Keyword . get ( opts , :use_cache , true )
59
- organization_id = Keyword . get ( opts , :organization_id , "" )
60
59
61
- find_ ( id , metadata , fields , use_cache , organization_id: organization_id )
60
+ find_ ( id , metadata , fields , use_cache )
62
61
end )
63
62
end
64
63
65
- def find ( id , metadata \\ nil , fields \\ @ fields , use_cache \\ true , opts \\ [ ] ) do
64
+ def find ( id , metadata \\ nil , fields \\ @ fields , use_cache \\ true ) do
66
65
Watchman . benchmark ( "fetch_user.duration" , fn ->
67
- find_ ( id , metadata , fields , use_cache , opts )
66
+ find_ ( id , metadata , fields , use_cache )
68
67
end )
69
68
end
70
69
71
- defp find_ ( id , metadata , fields , true , opts ) do
70
+ defp find_ ( id , metadata , fields , true ) do
72
71
cache_keys = Enum . map ( fields , fn f -> cache_key ( id , f ) end )
73
72
74
73
case Front.Cache . get_all ( cache_keys ) do
@@ -78,15 +77,15 @@ defmodule Front.Models.User do
78
77
struct! ( __MODULE__ , user )
79
78
80
79
{ :not_cached , _ } ->
81
- find ( id , metadata , fields , false , opts )
80
+ find ( id , metadata , fields , false )
82
81
end
83
82
end
84
83
85
- defp find_ ( id , metadata , _fields , false , opts ) do
84
+ defp find_ ( id , metadata , _fields , false ) do
86
85
alias InternalApi.User.UserService.Stub
87
86
req = InternalApi.User.DescribeRequest . new ( user_id: id )
88
87
89
- { :ok , channel } = build_user_channel ( opts )
88
+ { :ok , channel } = channel ( )
90
89
91
90
case Stub . describe ( channel , req , metadata: metadata , timeout: 30_000 ) do
92
91
{ :ok , res } ->
@@ -104,19 +103,16 @@ defmodule Front.Models.User do
104
103
end
105
104
end
106
105
107
- def find_user_with_providers ( user_id , organization_id \\ nil ) do
106
+ def find_user_with_providers ( user_id ) do
108
107
alias Front.Async
109
108
110
109
fetch_user = Async . run ( fn -> find ( user_id ) end )
111
110
112
- fetch_github_provider =
113
- Async . run ( fn -> refresh_repository_provider ( user_id , "github" , organization_id ) end )
111
+ fetch_github_provider = Async . run ( fn -> refresh_repository_provider ( user_id , "github" ) end )
114
112
115
- fetch_bb_provider =
116
- Async . run ( fn -> refresh_repository_provider ( user_id , "bitbucket" , organization_id ) end )
113
+ fetch_bb_provider = Async . run ( fn -> refresh_repository_provider ( user_id , "bitbucket" ) end )
117
114
118
- fetch_gitlab_provider =
119
- Async . run ( fn -> refresh_repository_provider ( user_id , "gitlab" , organization_id ) end )
115
+ fetch_gitlab_provider = Async . run ( fn -> refresh_repository_provider ( user_id , "gitlab" ) end )
120
116
121
117
{ :ok , user } = Async . await ( fetch_user )
122
118
{ :ok , github_provider } = Async . await ( fetch_github_provider )
@@ -139,7 +135,7 @@ defmodule Front.Models.User do
139
135
integration_type: IntegrationType . value ( project . integration_type )
140
136
)
141
137
142
- { :ok , channel } = build_user_channel ( organization_id: project . organization_id )
138
+ { :ok , channel } = channel ( )
143
139
144
140
case Stub . get_repository_token ( channel , req , timeout: 30_000 ) do
145
141
{ :ok , res } ->
@@ -167,7 +163,7 @@ defmodule Front.Models.User do
167
163
kind: kind
168
164
)
169
165
170
- { :ok , channel } = build_user_channel ( organization_id: organization_id )
166
+ { :ok , channel } = channel ( )
171
167
172
168
{ :ok , _ } =
173
169
InternalApi.User.UserService.Stub . create_favorite ( channel , favorite ,
@@ -193,7 +189,7 @@ defmodule Front.Models.User do
193
189
kind: kind
194
190
)
195
191
196
- { :ok , channel } = build_user_channel ( organization_id: organization_id )
192
+ { :ok , channel } = channel ( )
197
193
198
194
{ :ok , _ } =
199
195
InternalApi.User.UserService.Stub . delete_favorite ( channel , favorite ,
@@ -211,7 +207,7 @@ defmodule Front.Models.User do
211
207
organization_id: organization_id
212
208
)
213
209
214
- { :ok , channel } = build_user_channel ( organization_id: organization_id )
210
+ { :ok , channel } = channel ( )
215
211
216
212
{ :ok , response } =
217
213
InternalApi.User.UserService.Stub . list_favorites ( channel , request ,
@@ -223,14 +219,14 @@ defmodule Front.Models.User do
223
219
end )
224
220
end
225
221
226
- def find_many ( ids , tracing_headers \\ nil , organization_id \\ nil ) do
222
+ def find_many ( ids , tracing_headers \\ nil ) do
227
223
Watchman . benchmark ( "fetch_many_users.duration" , fn ->
228
224
request = InternalApi.User.DescribeManyRequest . new ( user_ids: ids )
229
225
230
226
Logger . debug ( "Sending request to User API" )
231
227
Logger . debug ( inspect ( request ) )
232
228
233
- { :ok , channel } = build_user_channel ( organization_id: organization_id )
229
+ { :ok , channel } = channel ( )
234
230
235
231
{ :ok , response } =
236
232
InternalApi.User.UserService.Stub . describe_many ( channel , request ,
@@ -249,7 +245,7 @@ defmodule Front.Models.User do
249
245
end )
250
246
end
251
247
252
- def update ( user , fields , metadata \\ nil , organization_id \\ nil ) do
248
+ def update ( user , fields , metadata \\ nil ) do
253
249
alias Front.Form.RequiredParams , as: RP
254
250
alias Google.Rpc.Status
255
251
alias InternalApi.User.UpdateRequest , as: UpdateRequest
@@ -270,7 +266,7 @@ defmodule Front.Models.User do
270
266
name: fields [ :name ]
271
267
)
272
268
) ,
273
- { :ok , channel } <- build_user_channel ( organization_id: organization_id ) ,
269
+ { :ok , channel } <- channel ( ) ,
274
270
{ :ok , res = % UpdateResponse { status: % Status { code: 0 } } } <-
275
271
InternalApi.User.UserService.Stub . update ( channel , req ,
276
272
metadata: metadata ,
@@ -292,11 +288,11 @@ defmodule Front.Models.User do
292
288
end )
293
289
end
294
290
295
- def regenerate_token ( user_id , metadata \\ nil , organization_id \\ nil ) do
291
+ def regenerate_token ( user_id , metadata \\ nil ) do
296
292
Watchman . benchmark ( "regenerate_token.duration" , fn ->
297
293
req = InternalApi.User.RegenerateTokenRequest . new ( user_id: user_id )
298
294
299
- { :ok , channel } = build_user_channel ( organization_id: organization_id )
295
+ { :ok , channel } = channel ( )
300
296
301
297
{ :ok , res } =
302
298
InternalApi.User.UserService.Stub . regenerate_token ( channel , req ,
@@ -318,7 +314,8 @@ defmodule Front.Models.User do
318
314
319
315
req = InternalApi.User.CheckGithubTokenRequest . new ( user_id: user_id )
320
316
321
- { :ok , channel } = GRPC.Stub . connect ( Application . fetch_env! ( :front , :user_grpc_endpoint ) )
317
+ { :ok , channel } =
318
+ GRPC.Stub . connect ( Application . fetch_env! ( :front , :guard_user_grpc_endpoint ) )
322
319
323
320
case Stub . check_github_token ( channel , req , metadata: metadata , timeout: 30_000 ) do
324
321
{ :ok , res } ->
@@ -330,7 +327,7 @@ defmodule Front.Models.User do
330
327
end )
331
328
end
332
329
333
- defp refresh_repository_provider ( user_id , provider , organization_id ) do
330
+ defp refresh_repository_provider ( user_id , provider ) do
334
331
Watchman . benchmark ( "refresh_repository_provider.duration" , fn ->
335
332
alias InternalApi.User.UserService.Stub
336
333
@@ -346,7 +343,7 @@ defmodule Front.Models.User do
346
343
type: type
347
344
)
348
345
349
- { :ok , channel } = build_user_channel ( organization_id: organization_id )
346
+ { :ok , channel } = channel ( )
350
347
351
348
case Stub . refresh_repository_provider ( channel , req , timeout: 30_000 ) do
352
349
{ :ok , res } ->
@@ -473,18 +470,5 @@ defmodule Front.Models.User do
473
470
end
474
471
end
475
472
476
- def build_user_channel ( opts \\ [ ] ) do
477
- organization_id = Keyword . get ( opts , :organization_id , "" ) || ""
478
-
479
- cond do
480
- organization_id == "" ->
481
- GRPC.Stub . connect ( Application . fetch_env! ( :front , :user_grpc_endpoint ) )
482
-
483
- FeatureProvider . feature_enabled? ( :use_new_user_api , param: organization_id ) ->
484
- GRPC.Stub . connect ( Application . fetch_env! ( :front , :guard_user_grpc_endpoint ) )
485
-
486
- true ->
487
- GRPC.Stub . connect ( Application . fetch_env! ( :front , :user_grpc_endpoint ) )
488
- end
489
- end
473
+ def channel , do: GRPC.Stub . connect ( Application . fetch_env! ( :front , :guard_user_grpc_endpoint ) )
490
474
end
0 commit comments