Skip to content

Commit 6e9f0bb

Browse files
toil(front): Remove all references to deprecated user_api_endpoint (#312)
## 📝 Description The issue was discovered while working on renderedtext/project-tasks#2405 Largely a revert of this PR renderedtext/alles#1713 ## ✅ Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent cc5d6bf commit 6e9f0bb

File tree

8 files changed

+41
-70
lines changed

8 files changed

+41
-70
lines changed

front/config/dev.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ config :front,
6666
self_hosted_agents_grpc_endpoint: "127.0.0.1:50052",
6767
superjerry_grpc_endpoint: "127.0.0.1:50051",
6868
task_grpc_endpoint: "127.0.0.1:50052",
69-
user_grpc_endpoint: "127.0.0.1:50052",
7069
velocity_grpc_endpoint: "127.0.0.1:50052",
7170
workflow_api_grpc_endpoint: "127.0.0.1:50052",
7271
jwt_grpc_endpoint: "127.0.0.1:50052"

front/config/runtime.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ if config_env() == :prod do
111111
self_hosted_agents_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_SELFHOSTEDHUB"),
112112
superjerry_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_SUPERJERRY"),
113113
task_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_TASK"),
114-
user_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_USER"),
115114
velocity_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_VELOCITY"),
116115
workflow_api_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_PLUMBER"),
117116
jwt_grpc_endpoint: System.fetch_env!("INTERNAL_API_URL_SECRETHUB")

front/config/test.exs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ config :front,
4747
superjerry_grpc_endpoint: "127.0.0.1:50051",
4848
task_grpc_endpoint: "127.0.0.1:50052",
4949
usage_grpc_endpoint: "127.0.0.1:50052",
50-
user_grpc_endpoint: "127.0.0.1:50052",
5150
velocity_grpc_endpoint: "127.0.0.1:50052",
5251
workflow_api_grpc_endpoint: "127.0.0.1:50052",
5352
jwt_grpc_endpoint: "127.0.0.1:50052"

front/lib/front/activity_monitor/repo.ex

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ defmodule Front.ActivityMonitor.Repo do
3636
ppl_ids <- Enum.map(active_pipelines, fn %{ppl_id: id} -> id end),
3737
debugged_ppl_ids <- Enum.map(debug_sessions, fn debug -> debug.debugged_job.ppl_id end),
3838
fetch_users <-
39-
Async.run(fn ->
40-
list_authors_of(active_pipelines, debug_sessions, tracing_headers, org_id)
41-
end),
39+
Async.run(fn -> list_authors_of(active_pipelines, debug_sessions, tracing_headers) end),
4240
fetch_jobs <- Async.run(fn -> list_active_jobs(tracing_headers, org_id, ppl_ids) end),
4341
fetch_debugged_ppls <-
4442
Async.run(fn -> describe_many_ppls(debugged_ppl_ids, tracing_headers) end),
@@ -251,7 +249,7 @@ defmodule Front.ActivityMonitor.Repo do
251249

252250
# List Users
253251

254-
def list_authors_of(active_pipelines, debug_sessions, tracing_headers, organization_id \\ nil) do
252+
def list_authors_of(active_pipelines, debug_sessions, tracing_headers) do
255253
active_pipelines
256254
|> Enum.reduce([], fn ppl, acc ->
257255
if ppl.promoter_id != "" do
@@ -262,14 +260,14 @@ defmodule Front.ActivityMonitor.Repo do
262260
end)
263261
|> Enum.concat(Enum.map(debug_sessions, fn debug -> debug.debug_user_id end))
264262
|> Enum.uniq()
265-
|> get_users(tracing_headers, organization_id)
263+
|> get_users(tracing_headers)
266264
|> ok_err_tuple()
267265
end
268266

269-
defp get_users(list, tracing_headers, organization_id) when is_list(list) and length(list) > 0,
270-
do: User.find_many(list, tracing_headers, organization_id)
267+
defp get_users(list, tracing_headers) when is_list(list) and length(list) > 0,
268+
do: User.find_many(list, tracing_headers)
271269

272-
defp get_users(_, _, _), do: []
270+
defp get_users(_, _), do: []
273271

274272
defp ok_err_tuple(nil), do: {:error, nil}
275273
defp ok_err_tuple(list), do: {:ok, list}

front/lib/front/models/user.ex

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,18 @@ defmodule Front.Models.User do
5656
metadata = Keyword.get(opts, :metadata, nil)
5757
fields = Keyword.get(opts, :fields, @fields)
5858
use_cache = Keyword.get(opts, :use_cache, true)
59-
organization_id = Keyword.get(opts, :organization_id, "")
6059

61-
find_(id, metadata, fields, use_cache, organization_id: organization_id)
60+
find_(id, metadata, fields, use_cache)
6261
end)
6362
end
6463

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
6665
Watchman.benchmark("fetch_user.duration", fn ->
67-
find_(id, metadata, fields, use_cache, opts)
66+
find_(id, metadata, fields, use_cache)
6867
end)
6968
end
7069

71-
defp find_(id, metadata, fields, true, opts) do
70+
defp find_(id, metadata, fields, true) do
7271
cache_keys = Enum.map(fields, fn f -> cache_key(id, f) end)
7372

7473
case Front.Cache.get_all(cache_keys) do
@@ -78,15 +77,15 @@ defmodule Front.Models.User do
7877
struct!(__MODULE__, user)
7978

8079
{:not_cached, _} ->
81-
find(id, metadata, fields, false, opts)
80+
find(id, metadata, fields, false)
8281
end
8382
end
8483

85-
defp find_(id, metadata, _fields, false, opts) do
84+
defp find_(id, metadata, _fields, false) do
8685
alias InternalApi.User.UserService.Stub
8786
req = InternalApi.User.DescribeRequest.new(user_id: id)
8887

89-
{:ok, channel} = build_user_channel(opts)
88+
{:ok, channel} = channel()
9089

9190
case Stub.describe(channel, req, metadata: metadata, timeout: 30_000) do
9291
{:ok, res} ->
@@ -104,19 +103,16 @@ defmodule Front.Models.User do
104103
end
105104
end
106105

107-
def find_user_with_providers(user_id, organization_id \\ nil) do
106+
def find_user_with_providers(user_id) do
108107
alias Front.Async
109108

110109
fetch_user = Async.run(fn -> find(user_id) end)
111110

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)
114112

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)
117114

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)
120116

121117
{:ok, user} = Async.await(fetch_user)
122118
{:ok, github_provider} = Async.await(fetch_github_provider)
@@ -139,7 +135,7 @@ defmodule Front.Models.User do
139135
integration_type: IntegrationType.value(project.integration_type)
140136
)
141137

142-
{:ok, channel} = build_user_channel(organization_id: project.organization_id)
138+
{:ok, channel} = channel()
143139

144140
case Stub.get_repository_token(channel, req, timeout: 30_000) do
145141
{:ok, res} ->
@@ -167,7 +163,7 @@ defmodule Front.Models.User do
167163
kind: kind
168164
)
169165

170-
{:ok, channel} = build_user_channel(organization_id: organization_id)
166+
{:ok, channel} = channel()
171167

172168
{:ok, _} =
173169
InternalApi.User.UserService.Stub.create_favorite(channel, favorite,
@@ -193,7 +189,7 @@ defmodule Front.Models.User do
193189
kind: kind
194190
)
195191

196-
{:ok, channel} = build_user_channel(organization_id: organization_id)
192+
{:ok, channel} = channel()
197193

198194
{:ok, _} =
199195
InternalApi.User.UserService.Stub.delete_favorite(channel, favorite,
@@ -211,7 +207,7 @@ defmodule Front.Models.User do
211207
organization_id: organization_id
212208
)
213209

214-
{:ok, channel} = build_user_channel(organization_id: organization_id)
210+
{:ok, channel} = channel()
215211

216212
{:ok, response} =
217213
InternalApi.User.UserService.Stub.list_favorites(channel, request,
@@ -223,14 +219,14 @@ defmodule Front.Models.User do
223219
end)
224220
end
225221

226-
def find_many(ids, tracing_headers \\ nil, organization_id \\ nil) do
222+
def find_many(ids, tracing_headers \\ nil) do
227223
Watchman.benchmark("fetch_many_users.duration", fn ->
228224
request = InternalApi.User.DescribeManyRequest.new(user_ids: ids)
229225

230226
Logger.debug("Sending request to User API")
231227
Logger.debug(inspect(request))
232228

233-
{:ok, channel} = build_user_channel(organization_id: organization_id)
229+
{:ok, channel} = channel()
234230

235231
{:ok, response} =
236232
InternalApi.User.UserService.Stub.describe_many(channel, request,
@@ -249,7 +245,7 @@ defmodule Front.Models.User do
249245
end)
250246
end
251247

252-
def update(user, fields, metadata \\ nil, organization_id \\ nil) do
248+
def update(user, fields, metadata \\ nil) do
253249
alias Front.Form.RequiredParams, as: RP
254250
alias Google.Rpc.Status
255251
alias InternalApi.User.UpdateRequest, as: UpdateRequest
@@ -270,7 +266,7 @@ defmodule Front.Models.User do
270266
name: fields[:name]
271267
)
272268
),
273-
{:ok, channel} <- build_user_channel(organization_id: organization_id),
269+
{:ok, channel} <- channel(),
274270
{:ok, res = %UpdateResponse{status: %Status{code: 0}}} <-
275271
InternalApi.User.UserService.Stub.update(channel, req,
276272
metadata: metadata,
@@ -292,11 +288,11 @@ defmodule Front.Models.User do
292288
end)
293289
end
294290

295-
def regenerate_token(user_id, metadata \\ nil, organization_id \\ nil) do
291+
def regenerate_token(user_id, metadata \\ nil) do
296292
Watchman.benchmark("regenerate_token.duration", fn ->
297293
req = InternalApi.User.RegenerateTokenRequest.new(user_id: user_id)
298294

299-
{:ok, channel} = build_user_channel(organization_id: organization_id)
295+
{:ok, channel} = channel()
300296

301297
{:ok, res} =
302298
InternalApi.User.UserService.Stub.regenerate_token(channel, req,
@@ -318,7 +314,8 @@ defmodule Front.Models.User do
318314

319315
req = InternalApi.User.CheckGithubTokenRequest.new(user_id: user_id)
320316

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))
322319

323320
case Stub.check_github_token(channel, req, metadata: metadata, timeout: 30_000) do
324321
{:ok, res} ->
@@ -330,7 +327,7 @@ defmodule Front.Models.User do
330327
end)
331328
end
332329

333-
defp refresh_repository_provider(user_id, provider, organization_id) do
330+
defp refresh_repository_provider(user_id, provider) do
334331
Watchman.benchmark("refresh_repository_provider.duration", fn ->
335332
alias InternalApi.User.UserService.Stub
336333

@@ -346,7 +343,7 @@ defmodule Front.Models.User do
346343
type: type
347344
)
348345

349-
{:ok, channel} = build_user_channel(organization_id: organization_id)
346+
{:ok, channel} = channel()
350347

351348
case Stub.refresh_repository_provider(channel, req, timeout: 30_000) do
352349
{:ok, res} ->
@@ -473,18 +470,5 @@ defmodule Front.Models.User do
473470
end
474471
end
475472

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))
490474
end

front/lib/front_web/controllers/account_controller.ex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,12 @@ defmodule FrontWeb.AccountController do
3333
def update(conn, params) do
3434
Watchman.benchmark("account.update.duration", fn ->
3535
user_id = conn.assigns.user_id
36-
organization_id = conn.assigns.organization_id
3736

38-
fetch_user =
39-
Async.run(fn -> Models.User.find_user_with_providers(user_id, organization_id) end)
37+
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id) end)
4038

4139
{:ok, user} = Async.await(fetch_user)
4240

43-
case Models.User.update(user, %{name: params["name"]}, nil, organization_id) do
41+
case Models.User.update(user, %{name: params["name"]}) do
4442
{:ok, _updated_user} ->
4543
conn
4644
|> put_flash(:notice, "Changes saved.")
@@ -63,9 +61,8 @@ defmodule FrontWeb.AccountController do
6361
def reset_token(conn, _params) do
6462
Watchman.benchmark("account.regenerate_token.duration", fn ->
6563
user_id = conn.assigns.user_id
66-
org_id = conn.assigns.organization_id
6764

68-
case Models.User.regenerate_token(user_id, nil, org_id) do
65+
case Models.User.regenerate_token(user_id) do
6966
{:ok, new_token} ->
7067
conn
7168
|> put_flash(:notice, "Token reset.")
@@ -142,8 +139,7 @@ defmodule FrontWeb.AccountController do
142139
defp render_show(conn, user_id, errors \\ nil)
143140

144141
defp render_show(conn, user_id, errors) when is_binary(user_id) do
145-
org_id = conn.assigns.organization_id
146-
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id, org_id) end)
142+
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id) end)
147143
{:ok, user} = Async.await(fetch_user)
148144

149145
render_show(conn, user, errors)

front/lib/front_web/controllers/people_controller.ex

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -700,11 +700,10 @@ defmodule FrontWeb.PeopleController do
700700

701701
def update(conn, params = %{"user_id" => user_id}) do
702702
Watchman.benchmark("people.update", fn ->
703-
org_id = conn.assigns.organization_id
704-
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id, org_id) end)
703+
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id) end)
705704
{:ok, user} = Async.await(fetch_user)
706705

707-
case Models.User.update(user, %{name: params["name"]}, nil, org_id) do
706+
case Models.User.update(user, %{name: params["name"]}) do
708707
{:ok, _updated_user} ->
709708
conn
710709
|> put_flash(:notice, "Changes saved.")
@@ -747,9 +746,7 @@ defmodule FrontWeb.PeopleController do
747746
|> Audit.add(resource_id: user_id)
748747
|> Audit.log()
749748

750-
org_id = conn.assigns.organization_id
751-
752-
case Models.User.regenerate_token(user_id, nil, org_id) do
749+
case Models.User.regenerate_token(user_id) do
753750
{:ok, new_token} ->
754751
conn
755752
|> put_flash(:notice, "Token reset.")
@@ -924,8 +921,7 @@ defmodule FrontWeb.PeopleController do
924921
defp render_show(conn, user_id, errors \\ nil)
925922

926923
defp render_show(conn, user_id, errors) when is_binary(user_id) do
927-
org_id = conn.assigns.organization_id
928-
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id, org_id) end)
924+
fetch_user = Async.run(fn -> Models.User.find_user_with_providers(user_id) end)
929925
{:ok, user} = Async.await(fetch_user)
930926

931927
render_show(conn, user, errors)

front/lib/job_page/api/user.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule JobPage.Api.User do
55
Watchman.benchmark("fetch_user.duration", fn ->
66
req = InternalApi.User.DescribeRequest.new(user_id: id)
77

8-
{:ok, channel} = GRPC.Stub.connect(GrpcConfig.endpoint(:user_grpc_endpoint))
8+
{:ok, channel} = GRPC.Stub.connect(GrpcConfig.endpoint(:guard_user_grpc_endpoint))
99
{:ok, res} = InternalApi.User.UserService.Stub.describe(channel, req, timeout: 30_000)
1010

1111
if res.status.code == 0 do

0 commit comments

Comments
 (0)