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.
|
455835e7
Keenan Nemetz
15d ago
|
1 | package 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 | |
|
9579c1f9
Keenan Nemetz
14d ago
|
5 | // sent straight to the repository's Settings page, where access rules live. |
|
455835e7
Keenan Nemetz
15d ago
|
6 | |
| 7 | import ( | |
| 8 | "net/http" | |
| 9 | "strings" | |
| 10 | ||
|
d37d301f
Keenan Nemetz
16h ago
|
11 | "rodent.software/vole/forge/identity" |
|
455835e7
Keenan Nemetz
15d ago
|
12 | ) |
| 13 | ||
| 14 | type adminRepoNewView struct { | |
| 15 | Page | |
| 16 | Accounts []*identity.Account | |
| 17 | Name string | |
| 18 | Description string | |
| 19 | Owner string | |
| 20 | Error string | |
| 21 | } | |
| 22 | ||
| 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 | } | |
| 29 | } | |
| 30 | return adminRepoNewView{Page: w.page(r, "New repository"), Accounts: accounts, Error: msg} | |
| 31 | } | |
| 32 | ||
| 33 | func (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 | ||
| 40 | func (w *Web) CreateAdminRepo(rw http.ResponseWriter, r *http.Request) { | |
|
c717d4eb
Keenan Nemetz
13d ago
|
41 | pr, ok := w.beginAdminPost(rw, r, maxSmallForm) |
|
455835e7
Keenan Nemetz
15d ago
|
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 | } | |
|
62576fa8
Keenan Nemetz
14d ago
|
61 | m, err := w.Repos.Create(name, owner.Name, description) |
|
455835e7
Keenan Nemetz
15d ago
|
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 | } | |
|
b1499c72
Keenan Nemetz
12d ago
|
72 | w.audit("web.admin.repo.create", pr.account.Name, m.Name, "owner="+owner.Name) |
|
ed03b3d1
Keenan Nemetz
3h ago
|
73 | http.Redirect(rw, r, "/"+m.Name+"/settings", http.StatusSeeOther) |
|
455835e7
Keenan Nemetz
15d ago
|
74 | } |