From e3847cb9b10a7813ac00b510834e6b2929f11ace Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 19 Jun 2002 02:44:54 +0000 Subject: [PATCH] Adding karma. --- lib/WebGUI/Privilege.pm | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/WebGUI/Privilege.pm b/lib/WebGUI/Privilege.pm index fafdf92a7..23d2bdc65 100644 --- a/lib/WebGUI/Privilege.pm +++ b/lib/WebGUI/Privilege.pm @@ -108,19 +108,34 @@ sub insufficient { #------------------------------------------------------------------- sub isInGroup { - my ($gid, $uid, $result); + my ($gid, $uid, @data, %group, %user); ($gid, $uid) = @_; if ($uid eq "") { $uid = $session{user}{userId}; } + ### The "Everyone" group automatically returns true. if ($gid == 7) { - return 1; # If the "Everyone" group is specified then return true regardless of the user. + return 1; } - ($result) = WebGUI::SQL->quickArray("select count(*) from groupings where groupId='$gid' and userId='$uid' and expireDate>".time()); - if ($result < 1 && $gid != 3) { # admins can - $result = isInGroup(3, $uid); # do anything any - } # user can do - return $result; + ### Lookup the actual grouping. + @data = WebGUI::SQL->quickArray("select count(*) from groupings where groupId='$gid' and userId='$uid' and expireDate>".time()); + if ($data[0] > 0) { + return 1; + } + ### Get data for auxillary checks. + tie %group, 'Tie::CPHash'; + %group = WebGUI::SQL->quickHash("select karmaThreshold from groups where groupId='$gid'"); + tie %user, 'Tie::CPHash'; + %user = WebGUI::SQL->quickHash("select karma from users where userId='$uid'"); + ### Check karma levels. + if ($user{karma} >= $group{karmaThreshold}) { + return 1; + } + ### Admins can do anything! + if ($gid != 3) { + return isInGroup(3, $uid); + } + return 0; } #-------------------------------------------------------------------