Add the avility to edit metadata and delete books after submission
This commit is contained in:
parent
de58f0251e
commit
8d126fbe7a
7 changed files with 93 additions and 48 deletions
28
lib/admin.go
28
lib/admin.go
|
@ -17,14 +17,15 @@ const (
|
|||
)
|
||||
|
||||
func deleteHandler(h handler) {
|
||||
if !h.sess.IsModerator() {
|
||||
ids := strings.Split(mux.Vars(h.r)["ids"], "/")
|
||||
submissionID := mux.Vars(h.r)["submissionID"]
|
||||
if !h.sess.IsModerator() && !h.booksInSubmission(ids, submissionID) {
|
||||
notFound(h)
|
||||
return
|
||||
}
|
||||
|
||||
var titles []string
|
||||
var isNew bool
|
||||
ids := strings.Split(mux.Vars(h.r)["ids"], "/")
|
||||
for _, id := range ids {
|
||||
if id == "" {
|
||||
continue
|
||||
|
@ -50,16 +51,25 @@ func deleteHandler(h handler) {
|
|||
h.sess.Notify("Removed books!", "The books "+strings.Join(titles, ", ")+" are completly removed", "success")
|
||||
}
|
||||
h.sess.Save(h.w, h.r)
|
||||
if isNew {
|
||||
if submissionID != "" {
|
||||
http.Redirect(h.w, h.r, "/submission/"+submissionID, http.StatusFound)
|
||||
} else if isNew {
|
||||
http.Redirect(h.w, h.r, h.r.Referer(), http.StatusFound)
|
||||
} else {
|
||||
http.Redirect(h.w, h.r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
||||
type editData struct {
|
||||
S Status
|
||||
Book database.Book
|
||||
SubmissionID string
|
||||
}
|
||||
|
||||
func editHandler(h handler) {
|
||||
id := mux.Vars(h.r)["id"]
|
||||
if !h.sess.IsModerator() {
|
||||
submissionID := mux.Vars(h.r)["submissionID"]
|
||||
if !h.sess.IsModerator() && !h.booksInSubmission([]string{id}, submissionID) {
|
||||
notFound(h)
|
||||
return
|
||||
}
|
||||
|
@ -69,9 +79,10 @@ func editHandler(h handler) {
|
|||
return
|
||||
}
|
||||
|
||||
var data bookData
|
||||
var data editData
|
||||
data.Book = book
|
||||
data.S = GetStatus(h)
|
||||
data.SubmissionID = submissionID
|
||||
author := ""
|
||||
if len(book.Authors) > 0 {
|
||||
author = " by " + book.Authors[0]
|
||||
|
@ -93,7 +104,8 @@ func cleanEmptyStr(s []string) []string {
|
|||
func saveHandler(h handler) {
|
||||
// XXX: check for errors (ISBN, length(lang), ...)
|
||||
id := mux.Vars(h.r)["id"]
|
||||
if !h.sess.IsModerator() {
|
||||
submissionID := mux.Vars(h.r)["submissionID"]
|
||||
if !h.sess.IsModerator() && !h.booksInSubmission([]string{id}, submissionID) {
|
||||
notFound(h)
|
||||
return
|
||||
}
|
||||
|
@ -123,7 +135,9 @@ func saveHandler(h handler) {
|
|||
}
|
||||
|
||||
h.sess.Save(h.w, h.r)
|
||||
if h.db.IsBookActive(id) {
|
||||
if submissionID != "" {
|
||||
http.Redirect(h.w, h.r, "/submission/"+submissionID, http.StatusFound)
|
||||
} else if h.db.IsBookActive(id) {
|
||||
http.Redirect(h.w, h.r, "/book/"+id, http.StatusFound)
|
||||
} else {
|
||||
// XXX: I can't use a referer here :(
|
||||
|
|
Reference in a new issue