Skip to content

Commit

Permalink
Use the default organization as default for new notebooks (#2183)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristineguadelupe authored Aug 25, 2023
1 parent 867f091 commit b7f5a44
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/livebook/session.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions test/livebook/session_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
2 changes: 1 addition & 1 deletion test/livebook_teams/web/hub/edit_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b7f5a44

Please sign in to comment.