Member of root group who aren't board members may not vote on applicants
authorAdam Chlipala <adamc@hcoop.net>
Sat, 19 Jan 2008 20:36:23 +0000 (20:36 +0000)
committerAdam Chlipala <adamc@hcoop.net>
Sat, 19 Jan 2008 20:36:23 +0000 (20:36 +0000)
apps.mlt
group.sig
group.sml

index 82dccaa..c5c5d4c 100644 (file)
--- a/apps.mlt
+++ b/apps.mlt
@@ -1,7 +1,7 @@
 <% @header [("title", ["Membership applications"])];
 
 val you = Init.getUserId ();
-val board = Group.inGroupName "board";
+val board = Group.reallyInGroupName "board";
 val root = Group.inGroupNum 0;
 
 ref showNormal = true;
index d914acb..64e315d 100644 (file)
--- a/group.sig
+++ b/group.sig
@@ -14,6 +14,7 @@ sig
 
     val userInGroupNum : int * int -> bool
     val userInGroupName : int * string -> bool
+    val userReallyInGroupName : int * string -> bool (* Doesn't count root group *)
 
     val addToGroup : membership -> unit
     val addToGroups : int * int list -> unit
@@ -22,8 +23,9 @@ sig
 
     val inGroupNum : int -> bool
     val inGroupName : string -> bool
+    val reallyInGroupName : string -> bool
 
     (* These raise Access if the check fails *)
     val requireGroupNum : int -> unit
     val requireGroupName : string -> unit
-end
\ No newline at end of file
+end
index 33cc13e..75f412a 100644 (file)
--- a/group.sml
+++ b/group.sml
@@ -73,6 +73,18 @@ fun userInGroupName (usr, grp) =
           | _ => false)
     end
 
+fun userReallyInGroupName (usr, grp) =
+    let
+       val c = getDb ()
+    in
+       (case C.oneOrNoRows c ($`SELECT COUNT( * )
+                                   FROM Membership, WebGroup
+                                   WHERE (name = ^(C.stringToSql grp) AND grp = id)
+                                      AND usr = ^(C.intToSql usr)`) of
+            SOME[x] => not (C.isNull x) andalso C.intFromSql x <> 0
+          | _ => false)
+    end
+
 
 (* Managing group memberships *)
 
@@ -118,6 +130,7 @@ fun groupMembers grp =
 
 fun inGroupNum grp = userInGroupNum (getUserId(), grp)
 fun inGroupName grp = userInGroupName (getUserId(), grp)
+fun reallyInGroupName grp = userReallyInGroupName (getUserId(), grp)
 
 fun requireGroupNum grp =
     if inGroupNum grp then