From 68e6dc7d705311a5e1718680e4abc481cbea9fc4 Mon Sep 17 00:00:00 2001
From: Las Zenow <zenow@tormail.org>
Date: Fri, 19 Jul 2013 00:37:07 +0200
Subject: [PATCH] Display only the options of your role

---
 template.go           | 20 +++++++++++---------
 templates/book.html   |  4 ++--
 templates/header.html |  2 ++
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/template.go b/template.go
index 4d1ecaa..b5b6cd7 100644
--- a/template.go
+++ b/template.go
@@ -6,15 +6,16 @@ import (
 )
 
 type Status struct {
-	Search string
-	User   string
-	Notif  []Notification
-	Home   bool
-	About  bool
-	News   bool
-	Upload bool
-	Stats  bool
-	Help   bool
+	Search  string
+	User    string
+	IsAdmin bool
+	Notif   []Notification
+	Home    bool
+	About   bool
+	News    bool
+	Upload  bool
+	Stats   bool
+	Help    bool
 }
 
 func GetStatus(w http.ResponseWriter, r *http.Request) Status {
@@ -22,6 +23,7 @@ func GetStatus(w http.ResponseWriter, r *http.Request) Status {
 	sess := GetSession(r)
 	sess.Save(w, r)
 	s.User = sess.User
+	s.IsAdmin = sess.IsAdmin()
 	s.Notif = sess.Notif
 	return s
 }
diff --git a/templates/book.html b/templates/book.html
index efb4eed..14b534b 100644
--- a/templates/book.html
+++ b/templates/book.html
@@ -1,6 +1,6 @@
 {{template "header.html" .S}}
 
-{{$user := .S.User}}
+{{$isAdmin := .S.IsAdmin}}
 {{with .Book}}
 <script>
 function delBook(){
@@ -43,7 +43,7 @@ function delBook(){
 		</dl>
 	</div>
 	<div class="span3">
-		{{if $user}}
+		{{if $isAdmin}}
 		<div class="row">
 		<div class="btn-group pull-right">
 		<a href="/edit/{{.Id}}" class="btn btn-primary"><i class="icon-pencil"></i> Edit</a>
diff --git a/templates/header.html b/templates/header.html
index 25d97c3..d1bb60e 100644
--- a/templates/header.html
+++ b/templates/header.html
@@ -65,9 +65,11 @@
 					<i class="icon-user icon-white"></i> {{.User}}<b class="caret"></b>
 				</a>
 				<ul class="dropdown-menu">
+					{{if .IsAdmin}}
 					<li><a href="/new/"><i class="icon-book"></i> New books</a></li>
 					<li><a href="/news/edit"><i class="icon-certificate"></i> Edit news</a></li>
 					<li class="divider"></li>
+ 					{{end}}
 					<li><a href="/settings/"><i class="icon-wrench"></i> Settings</a></li>
 					<li class="divider"></li>
 					<li><a href="/logout/"><i class="icon-off"></i> Log Out</a></li>