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/web/admin_repos.go +23−18
| @@ -1,33 +1,31 @@ | |||
| 1 | 1 | package web | |
| 2 | 2 | ||
| 3 | 3 | // Creating a repository is an instance-admin operation because it chooses the | |
| 4 | // owner and the name that every clone URL will use. After creation the admin is | ||
| 5 | // sent straight to the repository's Settings page, where access rules live. | ||
| 4 | // name that every clone URL will use and the visibility everyone starts with. | ||
| 5 | // After creation the admin is sent straight to the repository's Settings page, | ||
| 6 | // where access rules live. | ||
| 6 | 7 | ||
| 7 | 8 | import ( | |
| 8 | 9 | "net/http" | |
| 9 | 10 | "strings" | |
| 10 | 11 | ||
| 11 | "rodent.software/vole/forge/identity" | ||
| 12 | "rodent.software/vole/forge/repo" | ||
| 12 | 13 | ) | |
| 13 | 14 | ||
| 14 | 15 | type adminRepoNewView struct { | |
| 15 | 16 | Page | |
| 16 | Accounts []*identity.Account | ||
| 17 | 17 | Name string | |
| 18 | 18 | Description string | |
| 19 | Owner string | ||
| 19 | Visibility string | ||
| 20 | 20 | Error string | |
| 21 | 21 | } | |
| 22 | 22 | ||
| 23 | 23 | func (w *Web) adminRepoNewView(r *http.Request, msg string) adminRepoNewView { | |
| 24 | var accounts []*identity.Account | ||
| 25 | for _, acct := range w.Ident.All() { | ||
| 26 | if acct.Active() { | ||
| 27 | accounts = append(accounts, acct) | ||
| 28 | } | ||
| 24 | return adminRepoNewView{ | ||
| 25 | Page: w.page(r, "New repository"), | ||
| 26 | Visibility: string(repo.Private), | ||
| 27 | Error: msg, | ||
| 29 | 28 | } | |
| 30 | return adminRepoNewView{Page: w.page(r, "New repository"), Accounts: accounts, Error: msg} | ||
| 31 | 29 | } | |
| 32 | 30 | ||
| 33 | 31 | func (w *Web) AdminNewRepoPage(rw http.ResponseWriter, r *http.Request) { | |
| @@ -43,22 +41,29 @@ func (w *Web) CreateAdminRepo(rw http.ResponseWriter, r *http.Request) { | |||
| 43 | 41 | return | |
| 44 | 42 | } | |
| 45 | 43 | name := strings.TrimSpace(r.PostFormValue("name")) | |
| 46 | ownerName := strings.TrimSpace(r.PostFormValue("owner")) | ||
| 44 | visibilityName := strings.TrimSpace(r.PostFormValue("visibility")) | ||
| 47 | 45 | description := strings.TrimSpace(r.PostFormValue("description")) | |
| 46 | if visibilityName == "" { | ||
| 47 | visibilityName = string(repo.Private) | ||
| 48 | } | ||
| 48 | 49 | ||
| 49 | 50 | view := w.adminRepoNewView(r, "") | |
| 50 | view.Name, view.Owner, view.Description = name, ownerName, description | ||
| 51 | view.Name, view.Visibility, view.Description = name, visibilityName, description | ||
| 51 | 52 | fail := func(msg string) { | |
| 52 | 53 | view.Error = msg | |
| 53 | 54 | w.render(rw, "admin_repo_new", view, http.StatusBadRequest) | |
| 54 | 55 | } | |
| 55 | 56 | ||
| 56 | owner, err := w.Ident.Find(ownerName) | ||
| 57 | if err != nil || !owner.Active() { | ||
| 58 | fail("Choose an active account as the owner.") | ||
| 57 | visibility, err := repo.ParseVisibility(visibilityName) | ||
| 58 | if err != nil { | ||
| 59 | fail("Choose private or public visibility.") | ||
| 59 | 60 | return | |
| 60 | 61 | } | |
| 61 | m, err := w.Repos.Create(name, owner.Name, description) | ||
| 62 | m, err := w.Repos.Create(name, repo.CreateOptions{ | ||
| 63 | Description: description, | ||
| 64 | Visibility: visibility, | ||
| 65 | Actor: pr.account.Name, | ||
| 66 | }) | ||
| 62 | 67 | if err != nil { | |
| 63 | 68 | fail(err.Error()) | |
| 64 | 69 | return | |
| @@ -69,6 +74,6 @@ func (w *Web) CreateAdminRepo(rw http.ResponseWriter, r *http.Request) { | |||
| 69 | 74 | return | |
| 70 | 75 | } | |
| 71 | 76 | } | |
| 72 | w.audit("web.admin.repo.create", pr.account.Name, m.Name, "owner="+owner.Name) | ||
| 77 | w.audit("web.admin.repo.create", pr.account.Name, m.Name, "visibility="+string(visibility)) | ||
| 73 | 78 | http.Redirect(rw, r, "/"+m.Name+"/settings", http.StatusSeeOther) | |
| 74 | 79 | } | |