changes to git management links based on perms
authorpaulr <me@pjr.cc>
Tue, 8 Nov 2011 08:45:37 +0000 (19:45 +1100)
committerpaulr <me@pjr.cc>
Tue, 8 Nov 2011 08:45:37 +0000 (19:45 +1100)
changes to debug to create a more useful db
changes to database to add more functions that return info
changes to the login form to stop the padding spam

gwvplib/gwvpauth.php
gwvplib/gwvpdatabase.php
gwvplib/gwvpdebug.php
gwvplib/gwvpgitcontrol.php
gwvplib/gwvprepoadmin.php
gwvplib/gwvpweb.php
www/css/normal.css

index 5056c06..3e0ddcd 100644 (file)
@@ -229,7 +229,7 @@ function gwvp_SingleLineLoginForm()
        echo "<form method=\"post\" action=\"$BASE_URL/login\">Username <input type=\"text\" name=\"username\" class=\"login\">";
        echo " Passowrd <input type=\"text\" name=\"password\" class=\"login\"><input type=\"submit\" name=\"login\" value=\"Login\" class=\"loginbutton\">";
        if(gwvp_IsRegistrationEnabled()) echo "<a href=\"$BASE_URL/register\">Register</a></form>";
-       else echo "</form>";
+       else echo "</form><br>";
 }
 
 
index 22db79c..acb1a7a 100644 (file)
@@ -754,6 +754,25 @@ function gwvp_IsGroupAdmin($groupname = null, $gid = null)
        return $return;
 }
 
+function gwvp_IsRepoOwner($userid, $repoid)
+{
+       $conn = gwvp_ConnectDB();
+       
+       $sql = "select repos_owner from repos where repos_id='$repoid'";
+       
+       $res = $conn->query($sql);
+       
+       $return = false;
+       foreach($res as $u_res) {
+               $return["owner"] = $u_res["repos_owner"];
+       }
+
+       if($return == false) return false;
+       if($return["owner"] == $userid) return true;
+       else return false;
+       
+       
+}
 
 function gwvp_IsUserAdmin($email=null, $username = null, $userid = null)
 {
index 71e0a93..2a56674 100644 (file)
@@ -89,26 +89,34 @@ function gwvp_DebugCall()
                                case "recreatedb":
                                        global $db_name;
                                        gwvp_forceDisconnect();
+                                       unlink("$db_name.tmp");
                                        rename("$db_name", "$db_name.tmp");
                                        gwvp_dbCreateSQLiteStructure("$db_name");
-                                       //gwvp_createGroup($group_name, $is_admin, $owner_id)
-                                       //gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
-                                       //gwvp_addGroupMember($email, $groupname)
+                                       
+                                       // admin first
                                        gwvp_createUser("admin@localhost", "adminer", "password", "admin", "initial admin user", 0);
                                        $adminid = gwvp_getUserId("admin@localhost");
                                        gwvp_createGroup("admingroup", "admingroup", 1, $adminid);
                                        error_log("adminid is $adminid");
                                        gwvp_addGroupMember("admin@localhost", "admingroup");
-                                       gwvp_createUser("user@localhost", "userer", "password", "user", "initial pleb user", 0);
-                                       $userid = gwvp_getUserId("user@localhost");
-                                       error_log("userid is $userid");
-                                       gwvp_createGroup("usergroup", "usergroup", 0, $userid);
-                                       gwvp_addGroupMember("user@localhost", "usergroup");
+                                       
+                                       // user1
+                                       gwvp_createUser("user1@localhost", "userer1", "password", "user1", "initial pleb user1", 0);
+                                       $userid1 = gwvp_getUserId("user1@localhost");
+                                       error_log("userid1 is $userid1");
+                                       gwvp_createGroup("usergroup1", "usergroup1", 0, $userid1);
+                                       gwvp_addGroupMember("user1@localhost", "usergroup1");
+                                       
+                                       // user2
+                                       gwvp_createUser("user2@localhost", "userer2", "password", "user2", "initial pleb user2", 0);
+                                       $userid2 = gwvp_getUserId("user2@localhost");
+                                       error_log("userid2 is $userid2");
+                                       
                                        gwvp_SendMessage("info", "blank db re-created");
                                        
-                                       gwvp_AddRepo("repo1", "this is a test repo1", 1);
-                                       gwvp_AddRepo("repo2", "this is a test repo2", 1);
-                                       gwvp_AddRepo("repo2", "this is a test repo3", 1);
+                                       gwvp_AddRepo("repo1", "this is a test repo1", $adminid);
+                                       gwvp_AddRepo("repo2", "this is a test repo2", $userid1);
+                                       gwvp_AddRepo("repo3", "this is a test repo3", $userid2);
                                        
                                        gwvp_setConfigVal("repodir", "/tmp/");
                                        
@@ -140,7 +148,7 @@ function gwvp_DebugBody()
        <a href="<?php echo $BASE_URL?>/debug/infomessage">Generate info message</a><br>
        <a href="<?php echo $BASE_URL?>/debug/createusersandgroups">Create a bunch of users and groups</a><br>
        <a href="<?php echo $BASE_URL?>/debug/dropallusersandgroups">Drop users/groups/groupmemberships</a><br>
-       <a href="<?php echo $BASE_URL?>/debug/recreatedb">Recreate db</a><br>
+       <a href="<?php echo $BASE_URL?>/debug/recreatedb">Recreate test db</a><br>
        <?php
 }
 
index d1b0699..7093812 100644 (file)
@@ -4,6 +4,7 @@ $CALL_ME_FUNCTIONS["gitcontrol"] = "gwvp_gitControlCallMe";
 
 //$MENU_ITEMS["20repos"]["text"] = "Repo Admin";
 //$MENU_ITEMS["20repos"]["link"] = "$BASE_URL/admin/repos";
+$HOME_PAGE_PROVIDERS["gitlog"] = "gwvp_GitLogProvider";
 
 function gwvp_gitControlCallMe()
 {
@@ -22,6 +23,11 @@ function gwvp_gitControlCallMe()
        
 }
 
+function gwvp_GitLogProvider()
+{
+       echo "<br>gitload provider loaded on homepage<br>";
+}
+
 function gwvp_repoPermissionCheck($repo, $user)
 {
        return true;
@@ -159,6 +165,15 @@ function gwvp_gitBackendInterface()
        }
 }
 
+function gwvp_canManageRepo($userid, $repoid)
+{
+       // only the owner or an admin can do these tasks
+       error_log("Checking repoid, $repoid against userid $userid");
+       
+       if(gwvp_IsUserAdmin(null, null, $userid)) return true;
+       if(gwvp_IsRepoOwner($userid, $repoid)) return true;
+       return false;
+}
 
 function gwvp_callGitBackend($repo)
 {
index bcf9d25..cc78ba4 100644 (file)
@@ -28,6 +28,9 @@ function gwvp_RepoAdminCallMe()
                                                case "updateperms":
                                                        return "gwvp_UpdateRepoPerms";
                                                        break;
+                                               case "details":
+                                                       return "gwvp_RepoDetailsPage";
+                                                       break;
                                                default:
                                                        return "gwvp_RepoAdminPage";
                                        }                                       
@@ -57,6 +60,16 @@ function gwvp_CreateRepoPage()
        gwvp_goMainPage("gwvp_CreateRepoPageBody");
 }
 
+function gwvp_RepoDetailsPage()
+{
+       gwvp_goMainPage("gwvp_RepoDetailsPageBody");
+}
+
+function gwvp_RepoDetailsPageBody()
+{
+       echo "I am a repo details page";
+}
+
 function gwvp_UpdateRepoPerms()
 {
        global $LOGIN_TYPE, $BASE_URL;
@@ -241,6 +254,7 @@ function gwvp_RepoAdminPageBody()
        // next we need a repo list - with perms checking - ug
        // i must also remember that the home page will also contain a list of repos and that this page is solely for maintance
        // and creation of repos - so i dont need to get over-worked about the info stored on this page outside of those activities
+       echo "<h3>All Repositories</h3>";
        $rlist = gwvp_GetRepoList();
        echo "<table border=\"1\"><tr><th>Repo Name</th><th>Repo Description</th><th>Repo Owner</th></tr>";
        foreach($rlist as $u_res) {
@@ -248,7 +262,15 @@ function gwvp_RepoAdminPageBody()
                $rname = $u_res["name"];
                $rdesc = $u_res["description"];
                $rown = gwvp_getUserName($u_res["owner"]);
-               echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td><td><a href=\"$BASE_URL/admin/repos/manage/$rid\">Details</a></td></tr>";
+               $manordetslink = "details";
+               $manordets = "Details";
+               if(isset($_SESSION["id"])) {
+                       if(gwvp_canManageRepo($_SESSION["id"], $rid)) {
+                               $manordetslink = "manage";
+                               $manordets = "Manage";
+                       }
+               }
+               echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td><td><a href=\"$BASE_URL/admin/repos/$manordetslink/$rid\">$manordets</a></td></tr>";
        }
        echo "</table>";
        
@@ -304,6 +326,8 @@ function gwvp_ManageRepoPageBody()
        echo "<input type=\"submit\" name=\"update\" value=\"Update\"><br>";
        echo "</form>";
        
+       
+       echo "<h3>Repository Permissions</h3>";
        echo "<form method=\"post\" action=\"$BASE_URL/admin/repos/updateperms/$rid\">";
        echo "<table>";
        echo "<tr bgcolor=\"#eeeee0\"><th>Visibility</th><th>Read/Clone</th><th>Write/Push</th></tr>";
index 6f8c36c..92ed814 100644 (file)
@@ -3,6 +3,9 @@
 // this function is the initial insertion point for the web calls, here we need to determine where we go
 global $CALL_ME_FUNCTIONS;
 
+// the home_page_provders bit is an array 
+global $HOME_PAGE_PROVIDERS;
+
 $MENU_ITEMS["00home"]["text"] = "Home";
 $MENU_ITEMS["00home"]["link"] = "$BASE_URL";
 
@@ -151,6 +154,7 @@ function gwvp_MenuBuilder()
        
        ksort($MENU_ITEMS);
        
+       echo "\n\n\n";
        echo "<table border=\"1\"><tr><td><b><i>Menu</i></b></td>";
        foreach($MENU_ITEMS as $key => $val) {
                $link = $val["link"];
@@ -183,6 +187,7 @@ function gwvp_MenuBuilder()
                }
        }
        echo "</tr></table>";
+       echo "\n\n\n";
        
 }
 
@@ -190,18 +195,29 @@ function gwvp_LoginBuilder()
 {
        global $WEB_ROOT_FS, $BASE_URL;
        
+       echo "\n\n\n";
        $login = gwvp_IsLoggedIn();
        if($login === false) {
                gwvp_SingleLineLoginForm();
        } else {
                echo "Hello, ".gwvp_GetFullName($login)." <a href=\"$BASE_URL/logout\">logout</a>";
        }
+       echo "\n\n\n";
 }
 
 // builds the body structure
 function gwvp_BodyBuilder()
 {
-       echo "I AM THE MAIN BODY, FEAR ME!!!!";
+       global $HOME_PAGE_PROVIDERS;
+       
+       echo "I AM THE MAIN BODY, FEAR ME!!!! - have no idea whats going to go here";
+       if(isset($HOME_PAGE_PROVIDERS)) {
+               ksort($HOME_PAGE_PROVIDERS);
+               foreach($HOME_PAGE_PROVIDERS as $provider) {
+                       error_log("Loading home_page_provider, $provider");
+                       $provider();
+               }
+       }
 }
 
 // builds the tail structure
index 7a72dd3..586f541 100644 (file)
@@ -142,6 +142,10 @@ input.login {
        border: 1px solid;
 }
 
+form {
+       margin: 0em;
+}
+
 .buttons {
        border: 1px solid;
 }