added a permissions unit test
[gwvp.git] / gwvplib / gwvpgitcontrol.php
index 6383f9e..d1b0699 100644 (file)
@@ -379,12 +379,49 @@ function gwvp_resolvRepoPerms($userid, $repoid)
        $usergroups = gwvp_getGroupsForUser(null, $userid);
 
        $maxperm = 0;
-       foreach($repoperms as $perm) {
+       if($repoperms != false) foreach($repoperms as $perm) {
                // need to go thru each perm, then check it agains the user we're trying to figure
                // the perms on
+               switch($perm["type"]) {
+                       case "read":
+                               $permval = 2;
+                               break;
+                       case "visible":
+                               $permval = 1;
+                               break;
+                       case "write":
+                               $permval = 3;
+                               break;
+                       default:
+                               $permval = 0;
+               }
                
-               
+               // we only var if permval is greater then current
+               if($permval > $maxperm) {
+                       //error_log("going into check for $maxperm/$permval, ".$perm["ref"]);
+                       if($perm["ref"] == "anon") {
+                               $maxperm = $permval;
+                       } else if($perm["ref"] == "authed") {
+                               $maxperm = $permval;
+                       } else {
+                               // now we do splits
+                               $spl = explode(":", $perm["ref"]);
+                               $idtype = $spl[0];
+                               $idval = $spl[1];
+                               if($idtype == "group") {
+                                       // function gwvp_IsGroupMember($email, $groupname)
+                                       if(gwvp_IsGroupMemberById($userid, $idval)) $maxperm = $permval;
+                               } else if ($idtype == "user") {
+                                       //error_log("checking $userid, $idval");
+                                       if($userid == $idval) $maxperm = $permval;
+                               }
+                       }
+               }
        }
+       
+       // thats TOTALLY going to work... -_0 we should really write a unit test for this, but thats a bit
+       // hard given the db req's so for now, we'll leave it as is
+       return $maxperm;
 }
 
 ?>
\ No newline at end of file