diff --git a/lib/admin.go b/lib/admin.go index 704ac39..f5ab7fc 100644 --- a/lib/admin.go +++ b/lib/admin.go @@ -16,7 +16,7 @@ const ( ) func deleteHandler(h handler) { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } @@ -54,7 +54,7 @@ func deleteHandler(h handler) { func editHandler(h handler) { id := mux.Vars(h.r)["id"] - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } @@ -83,7 +83,7 @@ func cleanEmptyStr(s []string) []string { func saveHandler(h handler) { id := mux.Vars(h.r)["id"] - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } @@ -133,7 +133,7 @@ type newData struct { } func newHandler(h handler) { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } @@ -177,7 +177,7 @@ func newHandler(h handler) { } func storeHandler(h handler) { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } diff --git a/lib/cover.go b/lib/cover.go index 9fdc6e4..053a8c2 100644 --- a/lib/cover.go +++ b/lib/cover.go @@ -39,7 +39,7 @@ func coverHandler(h handler) { } if !book.Active { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } diff --git a/lib/reader.go b/lib/reader.go index bd70e72..fffc59a 100644 --- a/lib/reader.go +++ b/lib/reader.go @@ -182,7 +182,7 @@ func openReadEpub(h handler) (*epubgo.Epub, database.Book) { return nil, book } if !book.Active { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { return nil, book } } @@ -227,7 +227,7 @@ func openEpubFile(h handler, id string, file string) error { return err } if !book.Active { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { return err } } diff --git a/lib/session.go b/lib/session.go index 2338d9c..802ed71 100644 --- a/lib/session.go +++ b/lib/session.go @@ -81,3 +81,11 @@ func (s *Session) Id() string { func (s *Session) IsAdmin() bool { return s.Role == "admin" } + +func (s *Session) IsModerator() bool { + admin := map[string]bool{ + "admin": true, + "moderator": true, + } + return admin[s.Role] +} diff --git a/lib/template.go b/lib/template.go index 75d5b69..e6cf989 100644 --- a/lib/template.go +++ b/lib/template.go @@ -21,7 +21,7 @@ type Status struct { Title string Search string User string - IsAdmin bool + Role string Notif []Notification Updated string Home bool @@ -39,7 +39,7 @@ func GetStatus(h handler) Status { s.FullURL = s.BaseURL + h.r.RequestURI s.Title = "Imperial Library of Trantor" s.User = h.sess.User - s.IsAdmin = h.sess.IsAdmin() + s.Role = h.sess.Role s.Notif = h.sess.GetNotif() s.Updated = time.Now().UTC().Format("2006-01-02T15:04:05Z") h.sess.Save(h.w, h.r) diff --git a/lib/trantor.go b/lib/trantor.go index dda0ac9..13fb53b 100644 --- a/lib/trantor.go +++ b/lib/trantor.go @@ -87,7 +87,7 @@ func downloadHandler(h handler) { } if !book.Active { - if !h.sess.IsAdmin() { + if !h.sess.IsModerator() { notFound(h) return } diff --git a/templates/book.html b/templates/book.html index 6fdaed2..907c8f8 100644 --- a/templates/book.html +++ b/templates/book.html @@ -1,6 +1,6 @@ {{template "header.html" .S}} -{{$isAdmin := .S.IsAdmin}} +{{$role := .S.Role}} {{$flaggedBadQuality := .FlaggedBadQuality}} {{with .Book}}