Skip to content

Commit a4a2206

Browse files
authored
Disable Teams org creation (#3193)
1 parent 93e0951 commit a4a2206

5 files changed

Lines changed: 68 additions & 264 deletions

File tree

lib/livebook/teams.ex

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,6 @@ defmodule Livebook.Teams do
1313

1414
@teams_key_prefix Teams.Constants.teams_key_prefix()
1515

16-
@doc """
17-
Creates an Org.
18-
19-
With success, returns the response from Livebook Teams API to continue the org creation flow.
20-
Otherwise, it will return an error tuple with changeset.
21-
"""
22-
@spec create_org(Org.t(), map()) ::
23-
{:ok, map()}
24-
| {:error, Ecto.Changeset.t()}
25-
| {:transport_error, String.t()}
26-
def create_org(%Org{} = org, attrs) do
27-
create_org_request(org, attrs, &Requests.create_org/1)
28-
end
29-
3016
@doc """
3117
Joins an Org.
3218
@@ -38,14 +24,10 @@ defmodule Livebook.Teams do
3824
| {:error, Ecto.Changeset.t()}
3925
| {:transport_error, String.t()}
4026
def join_org(%Org{} = org, attrs) do
41-
create_org_request(org, attrs, &Requests.join_org/1)
42-
end
43-
44-
defp create_org_request(%Org{} = org, attrs, callback) when is_function(callback, 1) do
4527
changeset = Org.changeset(org, attrs)
4628

4729
with {:ok, %Org{} = org} <- apply_action(changeset, :insert) do
48-
case callback.(org) do
30+
case Requests.join_org(org) do
4931
{:ok, response} ->
5032
{:ok, response}
5133

lib/livebook/teams/requests.ex

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ defmodule Livebook.Teams.Requests do
1616
@doc false
1717
def error_message(), do: @error_message
1818

19-
@doc """
20-
Send a request to Livebook Team API to create a new org.
21-
"""
22-
@spec create_org(Teams.Org.t()) :: api_result()
23-
def create_org(org) do
24-
post("/api/v1/org-request", %{name: org.name, key_hash: Teams.Org.key_hash(org)})
25-
end
26-
2719
@doc """
2820
Send a request to Livebook Team API to join an org.
2921
"""

lib/livebook_web/live/hub/new_live.ex

Lines changed: 26 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,18 @@ defmodule LivebookWeb.Hub.NewLive do
1515

1616
@impl true
1717
def mount(_params, _session, socket) do
18-
socket =
19-
assign(socket,
20-
selected_option: "new-org",
21-
page_title: "Workspace - Livebook",
22-
requested_code: false,
23-
org: nil,
24-
verification_uri: nil,
25-
form: nil,
26-
button_label: nil,
27-
request_code_info: nil
28-
)
29-
30-
socket = assign_form(socket, "new-org")
31-
32-
{:ok, socket}
18+
{:ok,
19+
socket
20+
|> assign(
21+
page_title: "Workspace - Livebook",
22+
requested_code: false,
23+
org: nil,
24+
verification_uri: nil,
25+
form: nil,
26+
button_label: nil,
27+
request_code_info: nil
28+
)
29+
|> assign_form()}
3330
end
3431

3532
@impl true
@@ -60,38 +57,31 @@ defmodule LivebookWeb.Hub.NewLive do
6057
Livebook Teams</a> enables you to deploy notebooks as internal apps or turn Livebook into a controlled environment for runbooks and production operations.
6158
</p>
6259
<p class="mt-4 text-gray-700">
63-
To use it, you need to create or join a Teams organization.
60+
To use it, you need to join a Teams organization.
6461
</p>
6562
</div>
66-
<!-- TABS -->
6763
<div class="flex flex-col space-y-4">
6864
<div class="flex flex-col justify-center sm:items-center sm:m-auto">
6965
<div class="flex rounded-xl bg-gray-100 p-1">
7066
<ul class="flex flex-col sm:flex-row md:flex-col lg:flex-row w-full list-none gap-1">
71-
<!-- New Org -->
72-
<.tab_button
73-
id="new-org"
74-
selected={@selected_option}
75-
title="Create a new organization"
76-
icon="lightbulb-flash-line"
77-
/>
78-
<!-- Join Org -->
79-
<.tab_button
80-
id="join-org"
81-
selected={@selected_option}
82-
title="Join an existing organization"
83-
icon="organization-chart"
84-
/>
67+
<li class="group button flex w-full sm:w-72 items-center justify-center gap-1 md:gap-2 rounded-lg border py-3 md:py-2.5 px-5 transition-opacity duration-100 border-black/10 bg-white drop-shadow-sm hover:opacity-100!">
68+
<.remix_icon
69+
icon="organization-chart"
70+
class="group-hover:text-blue-600 text-lg text-blue-600"
71+
/>
72+
<span class="truncate text-sm font-medium">
73+
Join an existing organization
74+
</span>
75+
</li>
8576
</ul>
8677
</div>
8778
</div>
8879
</div>
89-
<!-- FORMS -->
90-
<div :if={@selected_option} class="flex flex-col space-y-4">
80+
<div class="flex flex-col space-y-4">
9181
<.form
9282
:let={f}
9383
for={@form}
94-
id={"#{@selected_option}-form"}
84+
id="join-org-form"
9585
class="flex flex-col space-y-4"
9686
phx-submit="save"
9787
phx-change="validate"
@@ -102,7 +92,6 @@ defmodule LivebookWeb.Hub.NewLive do
10292
</div>
10393
10494
<.password_field
105-
:if={@selected_option == "join-org"}
10695
field={f[:teams_key]}
10796
label="Livebook Teams key"
10897
/>
@@ -168,56 +157,7 @@ defmodule LivebookWeb.Hub.NewLive do
168157
"""
169158
end
170159

171-
defp tab_button(assigns) do
172-
~H"""
173-
<li class="group/toggle w-full">
174-
<button
175-
type="button"
176-
id={@id}
177-
aria-haspopup="menu"
178-
aria-expanded="false"
179-
data-state="closed"
180-
class="w-full"
181-
phx-click="select_option"
182-
phx-value-option={@id}
183-
>
184-
<div class={[
185-
"group button flex w-full sm:w-72 items-center justify-center gap-1 md:gap-2 rounded-lg border py-3 md:py-2.5 px-5 transition-opacity duration-100",
186-
selected_tab_button(@id, @selected)
187-
]}>
188-
<.remix_icon
189-
icon={@icon}
190-
class={[
191-
"group-hover:text-blue-600 text-lg",
192-
if @selected == @id do
193-
"text-blue-600"
194-
else
195-
"text-gray-500"
196-
end
197-
]}
198-
/>
199-
<span class="truncate text-sm font-medium">
200-
{@title}
201-
</span>
202-
</div>
203-
</button>
204-
</li>
205-
"""
206-
end
207-
208-
defp selected_tab_button(id, id),
209-
do: "border-black/10 bg-white drop-shadow-sm hover:opacity-100!"
210-
211-
defp selected_tab_button(_, _), do: "border-transparent text-gray-500 hover:text-gray-800"
212-
213160
@impl true
214-
def handle_event("select_option", %{"option" => option}, socket) do
215-
{:noreply,
216-
socket
217-
|> assign(selected_option: option, requested_code: false, verification_uri: nil)
218-
|> assign_form(option)}
219-
end
220-
221161
def handle_event("validate", %{"org" => attrs}, socket) do
222162
changeset =
223163
socket.assigns.org
@@ -228,13 +168,7 @@ defmodule LivebookWeb.Hub.NewLive do
228168
end
229169

230170
def handle_event("save", %{"org" => attrs}, socket) do
231-
result =
232-
case socket.assigns.selected_option do
233-
"new-org" -> Teams.create_org(socket.assigns.org, attrs)
234-
"join-org" -> Teams.join_org(socket.assigns.org, attrs)
235-
end
236-
237-
case result do
171+
case Teams.join_org(socket.assigns.org, attrs) do
238172
{:ok, %{"device_code" => device_code} = response} ->
239173
attrs = Map.merge(attrs, response)
240174
changeset = Teams.change_org(socket.assigns.org, attrs)
@@ -314,7 +248,7 @@ defmodule LivebookWeb.Hub.NewLive do
314248

315249
def handle_info(_any, socket), do: {:noreply, socket}
316250

317-
defp assign_form(socket, "join-org") do
251+
defp assign_form(socket) do
318252
org = %Org{emoji: random_emoji()}
319253
changeset = Teams.change_org(org)
320254

@@ -327,19 +261,6 @@ defmodule LivebookWeb.Hub.NewLive do
327261
|> assign_form(changeset)
328262
end
329263

330-
defp assign_form(socket, "new-org") do
331-
org = %Org{emoji: random_emoji(), teams_key: Org.teams_key()}
332-
changeset = Teams.change_org(org)
333-
334-
socket
335-
|> assign(
336-
org: org,
337-
button_label: "Create",
338-
request_code_info: "Verify your new organization"
339-
)
340-
|> assign_form(changeset)
341-
end
342-
343264
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
344265
assign(socket, form: to_form(changeset))
345266
end

test/livebook_teams/teams_test.exs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,6 @@ defmodule Livebook.TeamsTest do
1111
@moduletag subscribe_to_hubs_topics: [:connection, :file_systems, :secrets]
1212
@moduletag subscribe_to_teams_topics: [:clients, :deployment_groups, :app_deployments, :agents]
1313

14-
describe "create_org/1" do
15-
test "returns the device flow data to confirm the org creation" do
16-
org = build(:org)
17-
18-
assert {:ok,
19-
%{
20-
"device_code" => _device_code,
21-
"expires_in" => 300,
22-
"id" => _org_id,
23-
"user_code" => _user_code,
24-
"verification_uri" => _verification_uri
25-
}} = Teams.create_org(org, %{})
26-
end
27-
28-
test "returns changeset errors when data is invalid" do
29-
org = build(:org)
30-
31-
assert {:error, changeset} = Teams.create_org(org, %{name: nil})
32-
assert "can't be blank" in errors_on(changeset).name
33-
end
34-
end
35-
3614
describe "join_org/1" do
3715
test "returns the device flow data to confirm the org creation", %{node: node} do
3816
org = build(:org)

0 commit comments

Comments
 (0)