Keep configured repositories publicly browsable

d497583fb30e · AtlantisPleb · · parent 9b8936795fc6

Keep configured repositories publicly browsable

Deploy story

What this commit did to the running system — joined from the forge receipt chain, the part a commit page elsewhere cannot show.

built
542 modules in 82.8 s
built
0 modules in 602 ms
built
0 modules in 0 ms

Changed files

  • modified lib/openagents_web/repository_access.ex
  • modified test/openagents_web/live/code_live_test.exs

Diff

2 files changed, +25 -5

lib/openagents_web/repository_access.ex modified +5 -5

@@ -18,18 +18,18 @@ defmodule OpenAgentsWeb.RepositoryAccess do

18 18
  def full_source?(%Repository{} = repository, user) do
19 19
    ready?(repository) and
20 20
      (member?(repository, user) or ordinary_public?(repository) or
21
         Visibility.allows?(repository.storage_key, :files))
21
         Visibility.allows?(repository.name, :files))
22 22
  end
23 23
24 24
  def ledger?(%Repository{} = repository, user) do
25 25
    full_source?(repository, user) or
26
      (ready?(repository) and Visibility.allows?(repository.storage_key, :ledger))
26
      (ready?(repository) and Visibility.allows?(repository.name, :ledger))
27 27
  end
28 28
29 29
  def allows_file?(%Repository{} = repository, user, path, ref_sha, head_sha) do
30 30
    full_source?(repository, user) or
31 31
      (ready?(repository) and
32
         Visibility.allows_file?(repository.storage_key, path, ref_sha, head_sha))
32
         Visibility.allows_file?(repository.name, path, ref_sha, head_sha))
33 33
  end
34 34
35 35
  def member?(%Repository{} = repository, user),

@@ -40,8 +40,8 @@ defmodule OpenAgentsWeb.RepositoryAccess do

40 40
      "/#{repository.namespace.slug}/#{repository.name}.git"
41 41
  end
42 42
43
  defp ordinary_public?(%Repository{visibility: "public", storage_key: storage_key}),
44
    do: storage_key not in OpenAgents.Forge.Repos.allowed_repos()
43
  defp ordinary_public?(%Repository{visibility: "public", name: name}),
44
    do: name not in OpenAgents.Forge.Repos.allowed_repos()
45 45
46 46
  defp ordinary_public?(_repository), do: false
47 47
  defp ready?(%Repository{lifecycle_state: "ready"}), do: true
test/openagents_web/live/code_live_test.exs modified +20

@@ -188,6 +188,26 @@ defmodule OpenAgentsWeb.CodeLiveTest do

188 188
      assert html =~ "Fixture readme."
189 189
    end
190 190
191
    test "keeps configured source public after the storage key joins the forge", %{conn: conn} do
192
      repository =
193
        OpenAgents.Repositories.get_by_path!("OpenAgentsInc", "openagents.com")
194
195
      previous_repos = Application.fetch_env!(:openagents, :forge_repos)
196
197
      Application.put_env(
198
        :openagents,
199
        :forge_repos,
200
        Enum.uniq(previous_repos ++ [repository.storage_key])
201
      )
202
203
      on_exit(fn -> Application.put_env(:openagents, :forge_repos, previous_repos) end)
204
205
      browsable()
206
      {:ok, view, _html} = live(conn, "/OpenAgentsInc/openagents.com")
207
208
      assert has_element?(view, "#code-repo-page")
209
    end
210
191 211
    test "renders the README as a formatted document", %{conn: conn} do
192 212
      browsable()
193 213
      {:ok, _view, html} = live(conn, "/OpenAgentsInc/openagents.com")

This page updates live while a promote is in flight · changelog