Add the moderator role
This commit is contained in:
parent
baf2b5a6a9
commit
dcc2d3b9dc
9 changed files with 28 additions and 16 deletions
10
lib/admin.go
10
lib/admin.go
|
@ -16,7 +16,7 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func deleteHandler(h handler) {
|
func deleteHandler(h handler) {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func deleteHandler(h handler) {
|
||||||
|
|
||||||
func editHandler(h handler) {
|
func editHandler(h handler) {
|
||||||
id := mux.Vars(h.r)["id"]
|
id := mux.Vars(h.r)["id"]
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func cleanEmptyStr(s []string) []string {
|
||||||
|
|
||||||
func saveHandler(h handler) {
|
func saveHandler(h handler) {
|
||||||
id := mux.Vars(h.r)["id"]
|
id := mux.Vars(h.r)["id"]
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ type newData struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func newHandler(h handler) {
|
func newHandler(h handler) {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ func newHandler(h handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func storeHandler(h handler) {
|
func storeHandler(h handler) {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ func coverHandler(h handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !book.Active {
|
if !book.Active {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,7 +182,7 @@ func openReadEpub(h handler) (*epubgo.Epub, database.Book) {
|
||||||
return nil, book
|
return nil, book
|
||||||
}
|
}
|
||||||
if !book.Active {
|
if !book.Active {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
return nil, book
|
return nil, book
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ func openEpubFile(h handler, id string, file string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !book.Active {
|
if !book.Active {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,3 +81,11 @@ func (s *Session) Id() string {
|
||||||
func (s *Session) IsAdmin() bool {
|
func (s *Session) IsAdmin() bool {
|
||||||
return s.Role == "admin"
|
return s.Role == "admin"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Session) IsModerator() bool {
|
||||||
|
admin := map[string]bool{
|
||||||
|
"admin": true,
|
||||||
|
"moderator": true,
|
||||||
|
}
|
||||||
|
return admin[s.Role]
|
||||||
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ type Status struct {
|
||||||
Title string
|
Title string
|
||||||
Search string
|
Search string
|
||||||
User string
|
User string
|
||||||
IsAdmin bool
|
Role string
|
||||||
Notif []Notification
|
Notif []Notification
|
||||||
Updated string
|
Updated string
|
||||||
Home bool
|
Home bool
|
||||||
|
@ -39,7 +39,7 @@ func GetStatus(h handler) Status {
|
||||||
s.FullURL = s.BaseURL + h.r.RequestURI
|
s.FullURL = s.BaseURL + h.r.RequestURI
|
||||||
s.Title = "Imperial Library of Trantor"
|
s.Title = "Imperial Library of Trantor"
|
||||||
s.User = h.sess.User
|
s.User = h.sess.User
|
||||||
s.IsAdmin = h.sess.IsAdmin()
|
s.Role = h.sess.Role
|
||||||
s.Notif = h.sess.GetNotif()
|
s.Notif = h.sess.GetNotif()
|
||||||
s.Updated = time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
s.Updated = time.Now().UTC().Format("2006-01-02T15:04:05Z")
|
||||||
h.sess.Save(h.w, h.r)
|
h.sess.Save(h.w, h.r)
|
||||||
|
|
|
@ -87,7 +87,7 @@ func downloadHandler(h handler) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !book.Active {
|
if !book.Active {
|
||||||
if !h.sess.IsAdmin() {
|
if !h.sess.IsModerator() {
|
||||||
notFound(h)
|
notFound(h)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{{template "header.html" .S}}
|
{{template "header.html" .S}}
|
||||||
|
|
||||||
{{$isAdmin := .S.IsAdmin}}
|
{{$role := .S.Role}}
|
||||||
{{$flaggedBadQuality := .FlaggedBadQuality}}
|
{{$flaggedBadQuality := .FlaggedBadQuality}}
|
||||||
{{with .Book}}
|
{{with .Book}}
|
||||||
<script>
|
<script>
|
||||||
|
@ -50,7 +50,7 @@ function delBook(){
|
||||||
<a href="/read/{{.Id}}" class="btn btn-large btn-warning"><i class="icon-eye-open icon-white"></i> read it!</a>
|
<a href="/read/{{.Id}}" class="btn btn-large btn-warning"><i class="icon-eye-open icon-white"></i> read it!</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{if $isAdmin}}
|
{{if eq $role "admin" "moderator"}}
|
||||||
<div class="row"><p></p></div>
|
<div class="row"><p></p></div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="btn-group pull-right">
|
<div class="btn-group pull-right">
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
<div class="span8 offset2">
|
<div class="span8 offset2">
|
||||||
<ul class="nav nav-tabs nav-stacked">
|
<ul class="nav nav-tabs nav-stacked">
|
||||||
{{if .S.IsAdmin}}
|
{{if eq .S.Role "admin" "moderator"}}
|
||||||
<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
|
<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
|
||||||
|
{{if eq .S.Role "admin"}}
|
||||||
<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
|
<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
|
||||||
|
{{end}}
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
<li><a href="/settings/"><i class="icon-wrench"></i> Settings</a></li>
|
<li><a href="/settings/"><i class="icon-wrench"></i> Settings</a></li>
|
||||||
|
|
|
@ -68,11 +68,13 @@
|
||||||
</a>
|
</a>
|
||||||
<ul class="dropdown-menu">
|
<ul class="dropdown-menu">
|
||||||
<li><a href="/dashboard/"><i class="icon-tasks"></i> Dashboard</a></li>
|
<li><a href="/dashboard/"><i class="icon-tasks"></i> Dashboard</a></li>
|
||||||
{{if .IsAdmin}}
|
{{if eq .Role "admin" "moderator"}}
|
||||||
<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
|
<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
|
||||||
|
{{if eq .Role "admin"}}
|
||||||
<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
|
<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
|
||||||
|
{{end}}
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
{{end}}
|
{{end}}
|
||||||
<li><a href="/settings/"><i class="icon-wrench"></i> Settings</a></li>
|
<li><a href="/settings/"><i class="icon-wrench"></i> Settings</a></li>
|
||||||
<li class="divider"></li>
|
<li class="divider"></li>
|
||||||
<li><a href="/logout/"><i class="icon-off"></i> Log Out</a></li>
|
<li><a href="/logout/"><i class="icon-off"></i> Log Out</a></li>
|
||||||
|
|
Reference in a new issue