Sign in

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

vole
Clone

Read only, no credentials:

https://rodent.software/git/vole.git

Write over SSH with a registered key:

git clone ssh://git@0.0.0.0:2222/vole.git

A free and open-source forge that lives in your Git repo.

Code

392 commit(s) on main

Merge change request 01M70WES5ZZDJ6RP226WB11BBZ: Let people rename and remove their own passkeys keenan · 53m ago 4b8c9e1d
history blame raw 2.0 KiB
1package web
2
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.
6
7import (
8 "net/http"
9 "strings"
10
11 "rodent.software/vole/forge/identity"
12)
13
14type adminRepoNewView struct {
15 Page
16 Accounts []*identity.Account
17 Name string
18 Description string
19 Owner string
20 Error string
21}
22
23func (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 }
29 }
30 return adminRepoNewView{Page: w.page(r, "New repository"), Accounts: accounts, Error: msg}
31}
32
33func (w *Web) AdminNewRepoPage(rw http.ResponseWriter, r *http.Request) {
34 if _, ok := w.requireInstanceAdmin(rw, r); !ok {
35 return
36 }
37 w.render(rw, "admin_repo_new", w.adminRepoNewView(r, ""), 0)
38}
39
40func (w *Web) CreateAdminRepo(rw http.ResponseWriter, r *http.Request) {
41 pr, ok := w.beginAdminPost(rw, r, maxSmallForm)
42 if !ok {
43 return
44 }
45 name := strings.TrimSpace(r.PostFormValue("name"))
46 ownerName := strings.TrimSpace(r.PostFormValue("owner"))
47 description := strings.TrimSpace(r.PostFormValue("description"))
48
49 view := w.adminRepoNewView(r, "")
50 view.Name, view.Owner, view.Description = name, ownerName, description
51 fail := func(msg string) {
52 view.Error = msg
53 w.render(rw, "admin_repo_new", view, http.StatusBadRequest)
54 }
55
56 owner, err := w.Ident.Find(ownerName)
57 if err != nil || !owner.Active() {
58 fail("Choose an active account as the owner.")
59 return
60 }
61 m, err := w.Repos.Create(name, owner.Name, description)
62 if err != nil {
63 fail(err.Error())
64 return
65 }
66 if w.Index != nil {
67 if err := w.Index.Upsert(m); err != nil {
68 w.serverError(rw, r, "repository created but the index was not updated: "+err.Error())
69 return
70 }
71 }
72 w.audit("web.admin.repo.create", pr.account.Name, m.Name, "owner="+owner.Name)
73 http.Redirect(rw, r, "/"+m.Name+"/settings", http.StatusSeeOther)
74}
75