Skip to content

Commit 331dd0b

Browse files
committed
Apply review comments
1 parent 33ab1b8 commit 331dd0b

3 files changed

Lines changed: 18 additions & 36 deletions

File tree

lib/livebook/apps.ex

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ defmodule Livebook.Apps do
7676

7777
@doc """
7878
Returns if the given running app is authorized to given user.
79+
80+
Teams apps have authorization rules that can restrict access on
81+
per-user basis. This kind of authorization is not applicable to
82+
other types of apps, for those this function always returns `true`.
7983
"""
8084
@spec authorized?(App.t(), Livebook.Users.User.t()) :: boolean()
8185
def authorized?(app, user)
@@ -86,7 +90,7 @@ defmodule Livebook.Apps do
8690
Livebook.Hubs.TeamClient.user_app_access?(id, user.groups, slug)
8791
end
8892

89-
def authorized?(%{permanent: false}, _user), do: true
93+
def authorized?(_app, _user), do: true
9094

9195
@doc """
9296
Updates the given app info across the cluster.

lib/livebook/hubs.ex

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,28 +124,20 @@ defmodule Livebook.Hubs do
124124
if get_default_hub().id == hub_id, do: unset_default_hub(), else: :ok
125125
end
126126

127-
if Mix.env() == :test do
128-
# In test environment, disconnect synchronously to avoid race conditions
129-
# during test cleanup where other processes might still be accessing hubs
130-
defp disconnect_hub(hub) do
131-
Provider.disconnect(hub)
132-
end
133-
else
134-
defp disconnect_hub(hub) do
135-
# We use a task supervisor because the hub connection itself
136-
# calls delete_hub (which calls this function), otherwise we deadlock.
137-
Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
138-
# Since other processes may have been communicating
139-
# with the hub, we don't want to terminate abruptly and
140-
# make them crash, so we give it some time to shut down.
141-
#
142-
# The default backoff is 5.5s, so we round it down to 5s.
143-
Process.sleep(30_000)
144-
:ok = Provider.disconnect(hub)
145-
end)
127+
defp disconnect_hub(hub) do
128+
# We use a task supervisor because the hub connection itself
129+
# calls delete_hub (which calls this function), otherwise we deadlock.
130+
Task.Supervisor.start_child(Livebook.TaskSupervisor, fn ->
131+
# Since other processes may have been communicating
132+
# with the hub, we don't want to terminate abruptly and
133+
# make them crash, so we give it some time to shut down.
134+
#
135+
# The default backoff is 5.5s, so we round it down to 5s.
136+
Process.sleep(30_000)
137+
:ok = Provider.disconnect(hub)
138+
end)
146139

147-
:ok
148-
end
140+
:ok
149141
end
150142

151143
defp to_struct(%{id: "personal-" <> _} = fields) do

lib/livebook/hubs/team_client.ex

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ defmodule Livebook.Hubs.TeamClient do
9393
@spec get_deployment_groups(String.t()) :: list(Teams.DeploymentGroup.t())
9494
def get_deployment_groups(id) do
9595
GenServer.call(registry_name(id), :get_deployment_groups)
96-
catch
97-
:exit, _ -> []
9896
end
9997

10098
@doc """
@@ -103,8 +101,6 @@ defmodule Livebook.Hubs.TeamClient do
103101
@spec get_app_deployments(String.t()) :: list(Teams.AppDeployment.t())
104102
def get_app_deployments(id) do
105103
GenServer.call(registry_name(id), :get_app_deployments)
106-
catch
107-
:exit, _ -> []
108104
end
109105

110106
@doc """
@@ -134,8 +130,6 @@ defmodule Livebook.Hubs.TeamClient do
134130
@spec get_agents(String.t()) :: list(Teams.Agent.t())
135131
def get_agents(id) do
136132
GenServer.call(registry_name(id), :get_agents)
137-
catch
138-
:exit, _ -> []
139133
end
140134

141135
@doc """
@@ -144,8 +138,6 @@ defmodule Livebook.Hubs.TeamClient do
144138
@spec identity_enabled?(String.t()) :: boolean()
145139
def identity_enabled?(id) do
146140
GenServer.call(registry_name(id), :identity_enabled?)
147-
catch
148-
:exit, _ -> false
149141
end
150142

151143
@doc """
@@ -154,8 +146,6 @@ defmodule Livebook.Hubs.TeamClient do
154146
@spec get_environment_variables(String.t()) :: list(Teams.EnvironmentVariable.t())
155147
def get_environment_variables(id) do
156148
GenServer.call(registry_name(id), :get_environment_variables)
157-
catch
158-
:exit, _ -> []
159149
end
160150

161151
@doc """
@@ -164,8 +154,6 @@ defmodule Livebook.Hubs.TeamClient do
164154
@spec user_full_access?(String.t(), list(map())) :: boolean()
165155
def user_full_access?(id, groups) do
166156
GenServer.call(registry_name(id), {:check_full_access, groups})
167-
catch
168-
:exit, _ -> false
169157
end
170158

171159
@doc """
@@ -174,8 +162,6 @@ defmodule Livebook.Hubs.TeamClient do
174162
@spec user_app_access?(String.t(), list(map()), String.t()) :: boolean()
175163
def user_app_access?(id, groups, slug) do
176164
GenServer.call(registry_name(id), {:check_app_access, groups, slug})
177-
catch
178-
:exit, _ -> false
179165
end
180166

181167
@doc """

0 commit comments

Comments
 (0)