Make version part of config
This commit is contained in:
parent
03425fc2c6
commit
3b4e1e01d2
@ -18,7 +18,7 @@ func GenerateAtomFeed(c *Config, db *DB) (*string, error) {
|
||||
|
||||
feed.Generator = atom.NewGenerator("cpolis")
|
||||
feed.Generator.URI = "https://git.streifling.com/jason/cpolis"
|
||||
feed.Generator.Version = "0.13"
|
||||
feed.Generator.Version = c.Version
|
||||
|
||||
articles, err := db.GetCertainArticles("published", true)
|
||||
if err != nil {
|
||||
|
@ -27,6 +27,7 @@ type Config struct {
|
||||
PicsDir string
|
||||
Port string
|
||||
Title string
|
||||
Version string
|
||||
WebDir string
|
||||
MaxImgHeight int
|
||||
MaxImgWidth int
|
||||
@ -47,6 +48,7 @@ func newConfig() *Config {
|
||||
PDFDir: "/var/www/cpolis/pdfs",
|
||||
PicsDir: "/var/www/cpolis/pics",
|
||||
Port: ":8080",
|
||||
Version: "v0.13.0",
|
||||
WebDir: "/var/www/cpolis/web",
|
||||
}
|
||||
}
|
||||
|
@ -146,9 +146,12 @@ func SubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -225,9 +228,12 @@ func ResubmitArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -469,9 +475,12 @@ func PublishArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -501,9 +510,12 @@ func RejectArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -698,9 +710,12 @@ func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -755,8 +770,11 @@ func AllowEditArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl := template.Must(template.ParseFiles(c.WebDir + "/templates/hub.html"))
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -110,9 +110,12 @@ func PublishLatestIssue(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFun
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -56,12 +56,18 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
data := new(struct {
|
||||
Version string
|
||||
Role int
|
||||
})
|
||||
data.Version = c.Version
|
||||
|
||||
files := make([]string, 2)
|
||||
files[0] = c.WebDir + "/templates/index.html"
|
||||
if numRows == 0 {
|
||||
files[1] = c.WebDir + "/templates/first-user.html"
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
if err = template.Must(tmpl, err).Execute(w, nil); err != nil {
|
||||
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -74,9 +80,10 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
if auth, ok := session.Values["authenticated"].(bool); auth && ok {
|
||||
data.Role = session.Values["role"].(int)
|
||||
files[1] = c.WebDir + "/templates/hub.html"
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
if err = template.Must(tmpl, err).Execute(w, session.Values["role"]); err != nil {
|
||||
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -84,7 +91,7 @@ func HomePage(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
} else {
|
||||
files[1] = c.WebDir + "/templates/login.html"
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
if err = template.Must(tmpl, err).Execute(w, nil); err != nil {
|
||||
if err = template.Must(tmpl, err).Execute(w, data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -125,7 +132,7 @@ func Login(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user.Role); err != nil {
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", user); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -174,8 +181,11 @@ func ShowHub(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -41,9 +41,12 @@ func AddTag(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
}
|
||||
db.AddTag(tag)
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"]); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -101,9 +101,12 @@ func AddUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -183,9 +186,12 @@ func UpdateSelf(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -245,8 +251,11 @@ func AddFirstUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = 0
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", 0); err != nil {
|
||||
if err = template.Must(tmpl, err).ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -374,8 +383,11 @@ func UpdateUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl := template.Must(template.ParseFiles(c.WebDir + "/templates/hub.html"))
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
@ -405,9 +417,12 @@ func DeleteUser(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
data := new(struct{ Role int })
|
||||
data.Role = session.Values["role"].(int)
|
||||
|
||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
||||
tmpl = template.Must(tmpl, err)
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int)); err != nil {
|
||||
if err = tmpl.ExecuteTemplate(w, "page-content", data); err != nil {
|
||||
log.Println(err)
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
|
@ -2,30 +2,31 @@
|
||||
<div class="flex flex-col gap-4">
|
||||
<button class="btn" hx-get="/logout" hx-target="#page-content">Abmelden</button>
|
||||
|
||||
{{if lt . 4}}
|
||||
{{if lt .Role 4}}
|
||||
<div class="mb-3">
|
||||
<h2>Artikel</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||
<button class="btn" hx-get="/article/write" hx-target="#page-content">Artikel schreiben</button>
|
||||
<button class="btn" hx-get="/article/all-rejected" hx-target="#page-content">Artikel bearbeiten</button>
|
||||
{{if lt . 3}}<button class="btn" hx-get="/article/all-unpublished-unrejected-and-published-rejected"
|
||||
{{if lt .Role 3}}<button class="btn" hx-get="/article/all-unpublished-unrejected-and-published-rejected"
|
||||
hx-target="#page-content">Artikel veröffentlichen</button>{{end}}
|
||||
{{if lt . 2}}<button class="btn" hx-get="/article/all-published/delete" hx-target="#page-content">Artikel
|
||||
löschen</button>{{end}}
|
||||
{{if lt . 2}}<button class="btn" hx-get="/article/all-published/review-edit"
|
||||
{{if lt .Role 2}}<button class="btn" hx-get="/article/all-published/delete"
|
||||
hx-target="#page-content">Artikel löschen</button>{{end}}
|
||||
{{if lt .Role 2}}<button class="btn" hx-get="/article/all-published/review-edit"
|
||||
hx-target="#page-content">Artikel bearbeiten lassen</button>{{end}}
|
||||
{{if lt . 3}}<button class="btn" hx-get="/tag/create" hx-target="#page-content">Neuer Tag</button>{{end}}
|
||||
{{if lt .Role 3}}<button class="btn" hx-get="/tag/create" hx-target="#page-content">Neuer
|
||||
Tag</button>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
|
||||
{{if lt . 2}}
|
||||
{{if lt .Role 2}}
|
||||
<div class="mb-3">
|
||||
<h2>Ausgabe</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||
<button class="btn" hx-get="/issue/this" hx-target="#page-content">Diese Ausgabe</button>
|
||||
<form class="flex" hx-encoding="multipart/form-data">
|
||||
<label class="btn cursor-pointer text-center" for="pdf-upload">PDF hochladen</label>
|
||||
<label class="btn text-center" for="pdf-upload">PDF hochladen</label>
|
||||
<input accept=".pdf" class="hidden" id="pdf-upload" name="pdf-upload" type="file"
|
||||
hx-post="/pdf/upload" />
|
||||
</form>
|
||||
@ -33,16 +34,16 @@
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{if lt . 4}}
|
||||
{{if lt .Role 4}}
|
||||
<div class="mb-3">
|
||||
<h2>Benutzer</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-4 gap-y-2">
|
||||
<button class="btn" hx-get="/user/edit/self" hx-target="#page-content">Mein Profil bearbeiten</button>
|
||||
{{if eq . 0}}<button class="btn" hx-get="/user/create" hx-target="#page-content">Benutzer
|
||||
{{if eq .Role 0}}<button class="btn" hx-get="/user/create" hx-target="#page-content">Benutzer
|
||||
hinzufügen</button>{{end}}
|
||||
{{if eq . 0}}<button class="btn" hx-get="/user/show-all/edit" hx-target="#page-content">Benutzer
|
||||
{{if eq .Role 0}}<button class="btn" hx-get="/user/show-all/edit" hx-target="#page-content">Benutzer
|
||||
bearbeiten</button>{{end}}
|
||||
{{if eq . 0}}<button class="btn" hx-get="/user/show-all/delete" hx-target="#page-content">Benutzer
|
||||
{{if eq .Role 0}}<button class="btn" hx-get="/user/show-all/delete" hx-target="#page-content">Benutzer
|
||||
löschen</button>{{end}}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
<footer class="text-center text-gray-500 my-8">
|
||||
<p>© 2024 Jason Streifling. Alle Rechte vorbehalten.</p>
|
||||
<p>v0.13.0 - <strong>Alpha: Drastische Änderungen und Fehler vorbehalten.</strong></p>
|
||||
<p>{{.Version}} - <strong>Alpha: Drastische Änderungen und Fehler vorbehalten.</strong></p>
|
||||
</footer>
|
||||
|
||||
<script src="https://unpkg.com/htmx.org@2.0.2"></script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user