added a permissions unit test
[gwvp.git] / gwvplib / gwvpgitcontrol.php
index 18956b9..d1b0699 100644 (file)
@@ -30,8 +30,9 @@ function gwvp_repoPermissionCheck($repo, $user)
 function gwvp_gitBackendInterface_new()
 {
        // and this is where i re-code the git backend interface from scratch
-       global $repo_base, $BASE_URL;
+       global $BASE_URL;
        
+       $repo_base = gwvp_getConfigVal("repodir");
        
        $repo = "";
        $newloc = "/";
@@ -50,8 +51,9 @@ function gwvp_gitBackendInterface_new()
 
 function gwvp_gitBackendInterface()
 {
-       global $repo_base, $BASE_URL;
+       global $BASE_URL;
        
+       $repo_base = gwvp_getConfigVal("repodir");
        
        $repo = "";
        $newloc = "/";
@@ -324,7 +326,7 @@ function gwvp_callGitBackend($repo)
 
 function gwvp_repoExists($name)
 {
-       global $repo_base;
+       $repo_base = gwvp_getConfigVal("repodir");
        
        if(file_exists("$repo_base/$name.git")) return true;
        else return false;
@@ -336,7 +338,7 @@ function gwvp_repoExists($name)
 // 2 - only owner can see anything
 function gwvp_createGitRepo($name, $ownerid, $desc, $bundle=null, $defaultperms=0)
 {
-       global $repo_base;
+       $repo_base = gwvp_getConfigVal("repodir");
        
        // phew, this works, but i tell you this - bundles arent quite as nice as they should be
        if($bundle == null) {
@@ -377,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