Add the moderator role

This commit is contained in:
Las Zenow 2016-10-16 20:05:45 -04:00
parent baf2b5a6a9
commit dcc2d3b9dc
9 changed files with 28 additions and 16 deletions

View file

@ -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
}

View file

@ -39,7 +39,7 @@ func coverHandler(h handler) {
}
if !book.Active {
if !h.sess.IsAdmin() {
if !h.sess.IsModerator() {
notFound(h)
return
}

View file

@ -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
}
}

View file

@ -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]
}

View file

@ -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)

View file

@ -87,7 +87,7 @@ func downloadHandler(h handler) {
}
if !book.Active {
if !h.sess.IsAdmin() {
if !h.sess.IsModerator() {
notFound(h)
return
}