1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-05 17:40:26 +00:00

Categories: Do not let anons add to/remove from categories

This commit is contained in:
Timur Ismagilov 2022-03-26 18:39:33 +03:00
parent 59bb34b920
commit be7b2cc295
2 changed files with 15 additions and 4 deletions

View File

@ -64,11 +64,13 @@ func localizedCatTemplateAsString(meta Meta, name string, datum ...interface{})
func categoryCard(meta Meta, hyphaName string) string {
var buf strings.Builder
err := localizedCatTemplates(meta).ExecuteTemplate(&buf, "category card", struct {
HyphaName string
Categories []string
HyphaName string
Categories []string
GivenPermissionToModify bool
}{
hyphaName,
categories.WithHypha(hyphaName),
meta.U.CanProceed("add-to-category"),
})
if err != nil {
log.Println(err)
@ -79,11 +81,13 @@ func categoryCard(meta Meta, hyphaName string) string {
func CategoryPage(meta Meta, catName string) {
var buf strings.Builder
err := localizedCatTemplates(meta).ExecuteTemplate(&buf, "category page", struct {
CatName string
Hyphae []string
CatName string
Hyphae []string
GivenPermissionToModify bool
}{
catName,
categories.Contents(catName),
meta.U.CanProceed("add-to-category"),
})
if err != nil {
log.Println(err)

View File

@ -2,6 +2,7 @@
{{define "category card"}}
{{$hyphaName := .HyphaName}}
{{$givenPermission := .GivenPermissionToModify}}
<aside class="layout-card categories-card">
<h2 class="layout-card__title">{{block `categories` .}}Categories{{end}}</h2>
<ul class="categories-card__entries">
@ -12,11 +13,14 @@
<input type="hidden" name="cat" value="{{.}}">
<input type="hidden" name="hypha" value="{{$hyphaName}}">
<input type="hidden" name="redirect-to" value="/hypha/{{$hyphaName}}">
{{if $givenPermission}}
<input type="submit" value="x" class="btn categories-card__btn"
title="{{block `remove from category title` .}}Remove the hypha from this category{{end}}">
{{end}}
</form>
</li>
{{end}}
{{if .GivenPermissionToModify}}
<li class="categories-card__entry categories-card__add-to-cat">
<form method="POST" action="/add-to-category" class="categories-card__add-form">
<input type="text" name="cat" id="_cat-name"
@ -27,6 +31,7 @@
title="{{block `add to category title` .}}Add the hypha to this category{{end}}">
</form>
</li>
{{end}}
</ul>
</aside>
{{end}}
@ -44,6 +49,7 @@
<a class="wikilink" href="/hypha/{{.}}">{{beautifulName .}}</a>
</li>
{{end}}
{{if .GivenPermissionToModify}}
<li class="category__entry category__add-to-cat">
<form method="POST" action="/add-to-category" class="category__add-form">
<input type="text" name="hypha" id="_hypha-name"
@ -53,6 +59,7 @@
<input type="submit" class="btn" value="{{block `add hypha` .}}Add to the category{{end}}">
</form>
</li>
{{end}}
</ul>
</main>
{{end}}