Use the default organization as default for new notebooks (#2183)

This commit is contained in:
Cristine Guadelupe 2023-08-25 19:46:59 +07:00 committed by GitHub
parent 867f091557
commit b7f5a44b9e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 2 deletions

View file

@ -891,7 +891,11 @@ defmodule Livebook.Session do
"""
@spec default_notebook() :: Notebook.t()
def default_notebook() do
%{Notebook.new() | sections: [%{Section.new() | cells: [Cell.new(:code)]}]}
%{
Notebook.new()
| sections: [%{Section.new() | cells: [Cell.new(:code)]}],
hub_id: Livebook.Hubs.get_default_hub().id
}
end
defp schedule_autosave(state) do

View file

@ -1906,6 +1906,40 @@ defmodule Livebook.SessionTest do
assert_receive {:operation, {:add_cell_evaluation_output, _, ^cell_id, ^expected_output}}
end
defmodule Global do
use ExUnit.Case, async: false
describe "default hub for new notebooks" do
test "use the default hub as default for new notebooks" do
hub = Livebook.Factory.insert_hub(:team)
Livebook.Hubs.set_default_hub(hub.id)
notebook = Livebook.Session.default_notebook()
assert notebook.hub_id == hub.id
Livebook.Hubs.delete_hub(hub.id)
end
test "fallback to personal-hub when there's no default" do
hub = Livebook.Factory.insert_hub(:team)
Livebook.Hubs.unset_default_hub(hub.id)
notebook = Livebook.Session.default_notebook()
assert notebook.hub_id == "personal-hub"
Livebook.Hubs.delete_hub(hub.id)
end
test "fallback to personal-hub when the default doesn't exist" do
hub = Livebook.Factory.insert_hub(:team)
Livebook.Hubs.set_default_hub(hub.id)
Livebook.Hubs.delete_hub(hub.id)
notebook = Livebook.Session.default_notebook()
refute Livebook.Hubs.hub_exists?(hub.id)
assert notebook.hub_id == "personal-hub"
end
end
end
defp start_session(opts \\ []) do
opts = Keyword.merge([id: Utils.random_id()], opts)
pid = start_supervised!({Session, opts}, id: opts[:id])

View file

@ -7,7 +7,7 @@ defmodule LivebookWeb.Integration.Hub.EditLiveTest do
alias Livebook.Hubs
setup %{user: user, node: node} do
Livebook.Hubs.subscribe([:crud, :connection, :secrets, :default])
Livebook.Hubs.subscribe([:crud, :connection, :secrets])
hub = create_team_hub(user, node)
id = hub.id