summaryrefslogtreecommitdiff
path: root/poll.go
diff options
context:
space:
mode:
authorJoe Robinson <joe@mumsnet.com>2014-07-21 10:20:48 +0100
committerJoe Robinson <joe@mumsnet.com>2014-07-21 10:20:48 +0100
commitbfbd9cbdc79d0af254ee387ae840efe4702b2b3e (patch)
treea5e120e9506da8360aabf31b509c9a569c29c1d0 /poll.go
parent9c64140e68d236b6b8bbe90157b60cb9eb35506d (diff)
Check if user is an admin or added the poll to allow them to remove one
Diffstat (limited to 'poll.go')
-rw-r--r--poll.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/poll.go b/poll.go
index 9ca9aeb..803cf6c 100644
--- a/poll.go
+++ b/poll.go
@@ -1,9 +1,10 @@
package main
import "github.com/mxk/go-sqlite/sqlite3"
+import "fmt"
type Poll struct {
- id int
+ id int64
title string
userId int64
}
@@ -60,7 +61,7 @@ func getPollFromTitle(db *sqlite3.Conn, title string) Poll {
row := make(sqlite3.RowMap)
for ; err == nil ; err = s.Next() {
- var rowid int
+ var rowid int64
s.Scan(&rowid, row) // Assigns 1st column to rowid, the rest to row
poll := Poll{id:rowid, title:row["title"].(string), userId:row["user_id"].(int64)}
@@ -80,7 +81,7 @@ func getPollFromId(db *sqlite3.Conn, id int) Poll {
row := make(sqlite3.RowMap)
for ; err == nil ; err = s.Next() {
- var rowid int
+ var rowid int64
s.Scan(&rowid, row) // Assigns 1st column to rowid, the rest to row
poll := Poll{id:rowid, title:row["title"].(string), userId:row["user_id"].(int64)}
@@ -92,16 +93,25 @@ func getPollFromId(db *sqlite3.Conn, id int) Poll {
}
-func deletePoll(db *sqlite3.Conn, id int) error {
+func deletePoll(db *sqlite3.Conn, id int, nick string) error {
+ user := getUserForName(db, nick)
poll := getPollFromId(db, id)
- if (poll.id == 0) {
- return nil
+
+ if (user.isAdmin || poll.userId == user.id) {
+ if (poll.id == 0) {
+ return nil
+ } else {
+ sql := "DELETE FROM polls WHERE id = $a"
+ args := sqlite3.NamedArgs{"$a": id}
+ db.Exec(sql, args)
+ return nil
+ }
} else {
- sql := "DELETE FROM polls WHERE id = $a"
- args := sqlite3.NamedArgs{"$a": id}
- db.Exec(sql, args)
+ fmt.Println("denied")
return nil
}
+
+
} \ No newline at end of file