Compare commits
No commits in common. "1b29e328cfc2ec0f78b768bb46da55895a800976" and "e50cb819f3138c0aba021e495e80853a8131eb27" have entirely different histories.
1b29e328cf
...
e50cb819f3
@ -256,21 +256,3 @@ func (db *DB) AddArticleToCurrentIssue(id int64) error {
|
|||||||
|
|
||||||
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
return fmt.Errorf("error: %v unsuccessful retries for DB operation, aborting", TxMaxRetries)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) DeleteArticle(id int64) error {
|
|
||||||
articlesTagsQuery := "DELETE FROM articles_tags WHERE article_id = ?"
|
|
||||||
|
|
||||||
_, err := db.Exec(articlesTagsQuery, id)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error deleting article %v from DB: %v", id, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
articlesQuery := "DELETE FROM articles WHERE id = ?"
|
|
||||||
|
|
||||||
_, err = db.Exec(articlesQuery, id)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("error deleting article %v from DB: %v", id, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -14,8 +14,8 @@ type Client struct {
|
|||||||
|
|
||||||
func NewClient(c *Config) (*Client, error) {
|
func NewClient(c *Config) (*Client, error) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
client := new(Client)
|
client := new(Client)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
opt := option.WithCredentialsFile(c.FirebaseKey)
|
opt := option.WithCredentialsFile(c.FirebaseKey)
|
||||||
|
|
||||||
|
@ -476,114 +476,3 @@ func UploadImage(c *b.Config, s *b.CookieStore) http.HandlerFunc {
|
|||||||
json.NewEncoder(w).Encode(url)
|
json.NewEncoder(w).Encode(url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func ShowPublishedArticles(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if _, err := getSession(w, r, c, s); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
publishedArticles, err := db.GetCertainArticles(true, false)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/published-articles.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", publishedArticles)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func ReviewArticleForDeletion(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if _, err := getSession(w, r, c, s); err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
type htmlData struct {
|
|
||||||
Title string
|
|
||||||
Description string
|
|
||||||
Content template.HTML
|
|
||||||
Tags []*b.Tag
|
|
||||||
ID int64
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
data := new(htmlData)
|
|
||||||
|
|
||||||
data.ID, err = strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
article, err := db.GetArticle(data.ID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Title, err = b.ConvertToPlain(article.Title)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Description, err = b.ConvertToPlain(article.Description)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
content, err := b.ConvertToHTML(article.Content)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
data.Content = template.HTML(content)
|
|
||||||
|
|
||||||
data.Tags, err = db.GetArticleTags(data.ID)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/to-be-deleted.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", data)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func DeleteArticle(c *b.Config, db *b.DB, s *b.CookieStore) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
session, err := getSession(w, r, c, s)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
id, err := strconv.ParseInt(r.PathValue("id"), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = db.DeleteArticle(id); err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpl, err := template.ParseFiles(c.WebDir + "/templates/hub.html")
|
|
||||||
tmpl = template.Must(tmpl, err)
|
|
||||||
tmpl.ExecuteTemplate(w, "page-content", session.Values["role"].(int))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -51,10 +51,9 @@ func main() {
|
|||||||
|
|
||||||
mux.HandleFunc("GET /create-tag", f.CreateTag(config, store))
|
mux.HandleFunc("GET /create-tag", f.CreateTag(config, store))
|
||||||
mux.HandleFunc("GET /create-user", f.CreateUser(config, store))
|
mux.HandleFunc("GET /create-user", f.CreateUser(config, store))
|
||||||
mux.HandleFunc("GET /delete-article/{id}", f.DeleteArticle(config, db, store))
|
|
||||||
mux.HandleFunc("GET /delete-user/{id}", f.DeleteUser(config, db, store))
|
|
||||||
mux.HandleFunc("GET /edit-self", f.EditSelf(config, db, store))
|
mux.HandleFunc("GET /edit-self", f.EditSelf(config, db, store))
|
||||||
mux.HandleFunc("GET /edit-user/{id}", f.EditUser(config, db, store))
|
mux.HandleFunc("GET /edit-user/{id}", f.EditUser(config, db, store))
|
||||||
|
mux.HandleFunc("GET /delete-user/{id}", f.DeleteUser(config, db, store))
|
||||||
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
mux.HandleFunc("GET /hub", f.ShowHub(config, db, store))
|
||||||
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
mux.HandleFunc("GET /logout", f.Logout(config, store))
|
||||||
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
mux.HandleFunc("GET /pdf/get-list", c.ServePDFList(config))
|
||||||
@ -62,10 +61,8 @@ func main() {
|
|||||||
mux.HandleFunc("GET /pics/{pic}", f.ServeImage(config, store))
|
mux.HandleFunc("GET /pics/{pic}", f.ServeImage(config, store))
|
||||||
mux.HandleFunc("GET /publish-article/{id}", f.PublishArticle(config, db, store))
|
mux.HandleFunc("GET /publish-article/{id}", f.PublishArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /publish-issue", f.PublishLatestIssue(config, db, store))
|
mux.HandleFunc("GET /publish-issue", f.PublishLatestIssue(config, db, store))
|
||||||
mux.HandleFunc("GET /published-articles", f.ShowPublishedArticles(config, db, store))
|
|
||||||
mux.HandleFunc("GET /reject-article/{id}", f.RejectArticle(config, db, store))
|
mux.HandleFunc("GET /reject-article/{id}", f.RejectArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /rejected-articles", f.ShowRejectedArticles(config, db, store))
|
mux.HandleFunc("GET /rejected-articles", f.ShowRejectedArticles(config, db, store))
|
||||||
mux.HandleFunc("GET /review-article-for-deletion/{id}", f.ReviewArticleForDeletion(config, db, store))
|
|
||||||
mux.HandleFunc("GET /review-rejected-article/{id}", f.ReviewRejectedArticle(config, db, store))
|
mux.HandleFunc("GET /review-rejected-article/{id}", f.ReviewRejectedArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /review-unpublished-article/{id}", f.ReviewUnpublishedArticle(config, db, store))
|
mux.HandleFunc("GET /review-unpublished-article/{id}", f.ReviewUnpublishedArticle(config, db, store))
|
||||||
mux.HandleFunc("GET /rss", c.ServeRSS(config))
|
mux.HandleFunc("GET /rss", c.ServeRSS(config))
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
<h2>Herausgeber</h2>
|
<h2>Herausgeber</h2>
|
||||||
<div class="grid grid-cols-2 gap-4">
|
<div class="grid grid-cols-2 gap-4">
|
||||||
<button class="btn" hx-get="/this-issue" hx-target="#page-content">Diese Ausgabe</button>
|
<button class="btn" hx-get="/this-issue" hx-target="#page-content">Diese Ausgabe</button>
|
||||||
<button class="btn" hx-get="/published-articles" hx-target="#page-content">Artikel löschen</button>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
<h2>Artikel löschen</h2>
|
|
||||||
|
|
||||||
<div class="flex flex-col gap-4">
|
|
||||||
{{range .}}
|
|
||||||
<button class="btn" hx-get="/review-article-for-deletion/{{.ID}}" hx-target="#page-content">
|
|
||||||
<h1 class="font-bold text-2xl">{{.Title}}</h1>
|
|
||||||
<p>{{.Description}}</p>
|
|
||||||
</button>
|
|
||||||
{{end}}
|
|
||||||
<button class="action-btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
@ -1,36 +0,0 @@
|
|||||||
{{define "page-content"}}
|
|
||||||
<h2>Artikel löschen</h2>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<span>Titel</span>
|
|
||||||
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
|
||||||
{{.Title}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span>Beschreibung</span>
|
|
||||||
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
|
||||||
{{.Description}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span>Artikel</span>
|
|
||||||
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
|
||||||
<div class="prose">
|
|
||||||
{{.Content}}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<span>Tags</span>
|
|
||||||
<div class="bg-white border mb-3 px-2 py-2 rounded-md w-full">
|
|
||||||
{{range .Tags}}
|
|
||||||
{{.Name}}
|
|
||||||
<br>
|
|
||||||
{{end}}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="btn-area">
|
|
||||||
<input class="action-btn" type="submit" value="Löschen" hx-get="/delete-article/{{.ID}}"
|
|
||||||
hx-target="#page-content" />
|
|
||||||
<button class="btn" hx-get="/hub" hx-target="#page-content">Zurück</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{end}}
|
|
Loading…
x
Reference in New Issue
Block a user