Add delete links on poll pages
authorAdam Chlipala <adamc@hcoop.net>
Tue, 4 Aug 2009 15:44:00 +0000 (15:44 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Tue, 4 Aug 2009 15:44:00 +0000 (15:44 +0000)
poll.mlt
poll.sml

index dac0ede..200c96a 100644 (file)
--- a/poll.mlt
+++ b/poll.mlt
@@ -142,15 +142,15 @@ elseif $"mod" <> "" then
        end
 
 elseif $"del" <> "" then
-       Group.requireGroupName "poll";
        showNormal := false;
-       val poll = Poll.lookupPoll (Web.stoi ($"del")) %>
+       val poll = Poll.lookupPoll (Web.stoi ($"del"));
+       Poll.requireCanModify poll %>
        <h3>Are you sure you want to delete poll <a href="poll?id=<% #id poll %>"><% Web.html (#title poll) %></a>?</h3>
        <a href="poll?del2=<% $"del" %>">Yes, delete <% Web.html (#title poll) %>!</a>
 
 <% elseif $"del2" <> "" then
-       Group.requireGroupName "poll";
        val poll = Poll.lookupPoll (Web.stoi ($"del2"));
+       Poll.requireCanModify poll;
        Poll.deletePoll (Web.stoi ($"del2")) %>
        <h3><% Web.html (#title poll) %> deleted!</h3>
 
@@ -320,6 +320,8 @@ end %>
 
 <% if canModify then %>
 <br><hr><br>
+<h3><a href="?del=<% id %>">Delete this poll</a></h3>
+
 <h3>Add a new choice</h3>
 
 <form action="poll" method="post">
index 74fcaa9..34868cf 100644 (file)
--- a/poll.sml
+++ b/poll.sml
@@ -177,9 +177,9 @@ fun dateLtNow d =
 
 fun canModify (poll : poll) =
     Group.inGroupName "poll"
-    orelse (#usr poll = Init.getUserId()
-           andalso (dateLtNow (#starts poll)
-                    orelse not (#ready poll)))
+    orelse ((#usr poll = Init.getUserId()
+            andalso (dateLtNow (#starts poll)
+                     orelse not (#ready poll))))
 
 fun requireCanModify poll =
     if canModify poll then