Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Let repo create choose visibility, not an owner

d74e7e231de16fa00366dc8ccc392fc9c637b52d · Keenan Nemetz · 3d ago · parent 3455902a

Let repo create choose visibility, not an owner

A repository has no owner: the argument only seeded one admin entry in the
ACL store, and instance admins can already administer every repository. The
create command therefore asked for a fact the repository does not keep.

Replace --owner with --visibility private|public on `vole admin repo create`,
the remote admin command, and the web form. The initial rule set is written
once, inside the store, so a public repository is never briefly private. An
admin who wants to hand a repository to someone grants a role with the acl
commands, exactly as for any later access change.

closes: 01M82CC7G9W46PRP89GQ5CNMDE

server/admin_repos_test.go +29−10

@@ -15,18 +15,17 @@ func TestAdminCreatesRepository(t *testing.T) {
15 15 if _, err := f.srv.Identity.SetAdmin(f.ownerID, true, "test"); err != nil {
16 16 t.Fatal(err)
17 17 }
18 f.addWriter(t)
19 18 sess, cookie := f.browserSession(t, f.ownerID)
20 19
21 20 resp, body := f.browserGet(t, "/-/repos/new", cookie)
22 if resp.StatusCode != 200 || !strings.Contains(body, "New repository") || !strings.Contains(body, "wilbur") {
21 if resp.StatusCode != 200 || !strings.Contains(body, "New repository") || !strings.Contains(body, "Visibility") {
23 22 t.Fatalf("new repository page = %d:\n%s", resp.StatusCode, body)
24 23 }
25 24
26 25 form := url.Values{
27 26 "csrf": {sess.CSRF},
28 27 "name": {"demo-two"},
29 "owner": {"wilbur"},
28 "visibility": {"private"},
30 29 "description": {"second repository"},
31 30 }
32 31 resp, _ = f.browserPost(t, "/-/repos", cookie, form)
@@ -44,8 +43,8 @@ func TestAdminCreatesRepository(t *testing.T) {
44 43 if err != nil {
45 44 t.Fatal(err)
46 45 }
47 if acl.Entries[f.writerID] != "admin" {
48 t.Fatalf("owner role = %v", acl.Entries)
46 if acl.Default != "none" || len(acl.Entries) != 0 {
47 t.Fatalf("new repository rules = %+v", acl)
49 48 }
50 49 if acl.Can("", access.Read) {
51 50 t.Fatal("new repository is not private")
@@ -61,7 +60,7 @@ func TestAdminCreatesRepository(t *testing.T) {
61 60 if err != nil {
62 61 t.Fatal(err)
63 62 }
64 if !strings.Contains(string(audit), "web.admin.repo.create") {
63 if !strings.Contains(string(audit), "web.admin.repo.create") || !strings.Contains(string(audit), "visibility=private") {
65 64 t.Fatalf("creation was not audited:\n%s", audit)
66 65 }
67 66
@@ -73,11 +72,31 @@ func TestAdminCreatesRepository(t *testing.T) {
73 72 if resp, _ := f.browserPost(t, "/-/repos", cookie, form); resp.StatusCode != 400 {
74 73 t.Fatalf("invalid name = %d, want 400", resp.StatusCode)
75 74 }
76 form.Set("name", "third")
77 form.Set("owner", "nobody")
78 if resp, body := f.browserPost(t, "/-/repos", cookie, form); resp.StatusCode != 400 || !strings.Contains(body, "active account") {
79 t.Fatalf("unknown owner = %d:\n%s", resp.StatusCode, body)
75
76 form.Set("name", "demo-public")
77 form.Set("visibility", "public")
78 resp, _ = f.browserPost(t, "/-/repos", cookie, form)
79 if resp.StatusCode != 303 || resp.Header.Get("Location") != "/demo-public/settings" {
80 t.Fatalf("public create = %d %q", resp.StatusCode, resp.Header.Get("Location"))
81 }
82 public, err := f.srv.Repos.Open("demo-public")
83 if err != nil {
84 t.Fatal(err)
85 }
86 publicACL, err := public.ACL()
87 if err != nil {
88 t.Fatal(err)
89 }
90 if !publicACL.Can("", access.Read) || len(publicACL.Entries) != 0 {
91 t.Fatalf("public repository rules = %+v", publicACL)
80 92 }
93
94 form.Set("name", "fourth")
95 form.Set("visibility", "internal")
96 if resp, body := f.browserPost(t, "/-/repos", cookie, form); resp.StatusCode != 400 || !strings.Contains(body, "private or public") {
97 t.Fatalf("unknown visibility = %d:\n%s", resp.StatusCode, body)
98 }
99
81 100 form.Del("csrf")
82 101 if resp, _ := f.browserPost(t, "/-/repos", cookie, form); resp.StatusCode != 403 {
83 102 t.Fatalf("missing CSRF = %d, want 403", resp.StatusCode)