started work on the repo page
authorpaulr <me@pjr.cc>
Thu, 3 Nov 2011 16:37:07 +0000 (03:37 +1100)
committerpaulr <me@pjr.cc>
Thu, 3 Nov 2011 16:37:07 +0000 (03:37 +1100)
added a table for repo permissions
added to debug for createing some repo entries on a recreation

gwvplib/gwvpdatabase.php
gwvplib/gwvpdebug.php
gwvplib/gwvprepoadmin.php

index 56b5247..0c9a121 100644 (file)
@@ -6,7 +6,7 @@ $DB_CONNECTION = false;
 // i need to figure out how i do data encapsulation here. We'll support mysql and sqlite3 off the bat if we can - sqlite3 comes first tho
 function gwvp_dbCreateMysqlStructure()
 {
-       
+
 }
 
 function gwvp_dbCreateSQLiteStructure($dbloc)
@@ -21,7 +21,7 @@ function gwvp_dbCreateSQLiteStructure($dbloc)
            "user_desc" TEXT,
            "user_status" INTEGER
                )';
-       
+
        $groupsql = '
                CREATE TABLE groups (
            "groups_id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -29,7 +29,7 @@ function gwvp_dbCreateSQLiteStructure($dbloc)
            "groups_is_admin" INTEGER,
                "groups_owner_id" INTEGER
                )';
-       
+
        $reposql = '
                CREATE TABLE "repos" (
            "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
@@ -37,28 +37,40 @@ function gwvp_dbCreateSQLiteStructure($dbloc)
            "repos_description" TEXT,
            "repos_owner" INTEGER
                )';
-       
+
+       // this looks like null, <repoid>, <read|visible|write>, user:<uid>|group:<gid>|authed|anon
+       // where authed = any authenticated user, anon = any unauthed user
+       // read|visible|write = can clone from repo|can see repo exists but not clone from it|can push to repo
+       // TODO: is this sufficient? i have to think about it
+       $repoperms = '
+               CREATE TABLE "repoperms" (
+               "repoperms_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+               "repo_id" INTEGER,
+               "repoperms_type" TEXT,
+               "repoperms_ref" TEXT
+       )';
+
        $configsql = '
                CREATE TABLE "config" (
            "config_name" TEXT,
            "config_value" TEXT
                )';
-       
+
        $groupmemsql = '
                CREATE TABLE "group_membership" (
            "groupmember_id" INTEGER PRIMARY KEY AUTOINCREMENT,
            "groupmember_groupid" INTEGER,
            "groupmember_userid" INTEGER
                )';
-       
+
        try {
                $DB_CONNECTION = new PDO("sqlite:$dbloc");
        } catch(PDOException $exep) {
                error_log("execpt on db open");
                return false;
        }
-       
-       
+
+
        $DB_CONNECTION->query($usersql);
        $DB_CONNECTION->query($groupsql);
        $DB_CONNECTION->query($reposql);
@@ -70,12 +82,12 @@ function gwvp_isDBSetup()
 {
        // for sqlite, we just check if the db exists, for everyone else, we check for a conneciton and go yay or nay
        global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_url;
-       
+
        if($db_type == "sqlite") {
                if(file_exists($db_url)) return true;
                else return false;
        }
-       
+
        // TODO now for the connectables
        // gwvp_ConnectDB();
 }
@@ -83,17 +95,17 @@ function gwvp_isDBSetup()
 function gwvp_ConnectDB()
 {
        global $WEB_ROOT_FS, $BASE_URL, $repo_base, $data_directory, $db_type, $db_name, $DB_CONNECTION;
-       
+
        // first check if $DB_CONNECTION IS live
        if($DB_CONNECTION != false) return $DB_CONNECTION;
-       
+
        if($db_type == "sqlite") {
                $db_url = $db_name;
                if(!file_exists($db_name)) {
                        error_log("$db_name does not exist - problem");
-               } 
+               }
        }
-       
+
        // and here we go with pdo.
        error_log("attmpting to open db, $db_type:$db_url");
        try {
@@ -102,26 +114,26 @@ function gwvp_ConnectDB()
                error_log("execpt on db open");
                return false;
        }
-       
+
        return $DB_CONNECTION;
 }
 
 function gwvp_createUser($email, $fullname, $password, $username, $desc, $status)
 {
        $conn = gwvp_ConnectDB();
-       
+
        // TODO: change from sha1
        $shapass = sha1($password);
        //error_log("Create user called with $email");
        $conn->query("insert into users values (null, '$fullname', '$shapass', '$username', '$email', '$desc', '$status')");
        /*
         *          "users_id" INTEGER PRIMARY KEY AUTOINCREMENT,
-           "user_full_name" TEXT,
-           "user_password" TEXT,
-           "user_username" TEXT,
-           "user_email" TEXT,
-           "user_desc" TEXT,
-           "user_status" INTEGER
+        "user_full_name" TEXT,
+        "user_password" TEXT,
+        "user_username" TEXT,
+        "user_email" TEXT,
+        "user_desc" TEXT,
+        "user_status" INTEGER
 
         */
 }
@@ -129,7 +141,7 @@ function gwvp_createUser($email, $fullname, $password, $username, $desc, $status
 function gwvp_getUser($username=null, $email=null, $id=null)
 {
        $conn = gwvp_ConnectDB();
-       
+
        if($username != null) {
                $res = $conn->query("select * from users where user_username='$username'");
        } else if($email != null) {
@@ -148,17 +160,17 @@ function gwvp_getUser($username=null, $email=null, $id=null)
                $returns["desc"] = $u_res["user_desc"];
                $returns["status"] = $u_res["user_status"];
        }
-       
+
        return $returns;
-       
+
 }
 
 function gwvp_getUsers()
 {
        $conn = gwvp_ConnectDB();
-       
+
        $res = $conn->query("select * from users");
-       
+
        $returns = false;
        $rn = 0;
        foreach($res as $u_res) {
@@ -171,28 +183,28 @@ function gwvp_getUsers()
                $returns[$rn]["status"] = $u_res["user_status"];
                $rn++;
        }
-       
+
        return $returns;
 }
 
 function gwvp_deleteUser($email)
 {
        $conn = gwvp_ConnectDB();
-       
+
        $sql = "delete from users where user_email='$email'";
-       
+
        $conn->query($sql);
 }
 
 function gwvp_createGroup($group_name, $is_admin, $owner_id)
 {
        $conn = gwvp_ConnectDB();
-       
+
        /*
         *              CREATE TABLE groups (
-           "groups_id" INTEGER,
-           "groups_name" TEXT,
-           "groups_is_admin" INTEGER,
+        "groups_id" INTEGER,
+        "groups_name" TEXT,
+        "groups_is_admin" INTEGER,
                "groups_owner_id" INTEGER
                )';
 
@@ -203,17 +215,17 @@ function gwvp_createGroup($group_name, $is_admin, $owner_id)
                $is_admin_t = 0;
        }
        $sql = "insert into groups values( null, '$group_name', '$is_admin_t', '$owner_id')";
-       
+
        $conn->query($sql);
-       
+
 }
 
 function gwvp_deleteGroup($groupname)
 {
        $conn = gwvp_ConnectDB();
-       
+
        $sql = "delete from groups where groups_name='$groupname'";
-       
+
        $conn->query($sql);
 }
 
@@ -222,15 +234,15 @@ function gwvp_getGroupsForUser($email)
        $conn = gwvp_ConnectDB();
 
        /*
-                               select g.groups_name from 
-                               group_membership gm, groups g, users u 
-                       where 
-                               gm.groupmember_userid=u.users_id and
-                               u.user_email='$email' and
-                               gm.groupmember_groupid=g.groups_id and
-                               g.groups_name='$groupname'
-       */
-       
+        select g.groups_name from
+        group_membership gm, groups g, users u
+        where
+        gm.groupmember_userid=u.users_id and
+        u.user_email='$email' and
+        gm.groupmember_groupid=g.groups_id and
+        g.groups_name='$groupname'
+        */
+
        $sql = "
                        select g.groups_name from 
                                group_membership gm, groups g, users u 
@@ -239,16 +251,16 @@ function gwvp_getGroupsForUser($email)
                                u.user_email='$email' and
                                gm.groupmember_groupid=g.groups_id
        ";
-       
+
        $res = $conn->query($sql);
-       
+
        $return = false;
        $rn = 0;
        foreach($res as $u_res) {
                $return[$rn] = $u_res[0];
                $rn++;
        }
-       
+
        return $return;
 }
 
@@ -257,15 +269,15 @@ function gwvp_getGroupsOwnedByUser($email)
        $conn = gwvp_ConnectDB();
 
        /*
-                               select g.groups_name from 
-                               group_membership gm, groups g, users u 
-                       where 
-                               gm.groupmember_userid=u.users_id and
-                               u.user_email='$email' and
-                               gm.groupmember_groupid=g.groups_id and
-                               g.groups_name='$groupname'
-       */
-       
+        select g.groups_name from
+        group_membership gm, groups g, users u
+        where
+        gm.groupmember_userid=u.users_id and
+        u.user_email='$email' and
+        gm.groupmember_groupid=g.groups_id and
+        g.groups_name='$groupname'
+        */
+
        $sql = "
                        select g.groups_name from 
                                groups g, users u 
@@ -273,41 +285,41 @@ function gwvp_getGroupsOwnedByUser($email)
                                u.user_email='$email' and
                                u.users_id=g.groups_owner_id
        ";
-       
+
        $res = $conn->query($sql);
-       
+
        $return = false;
        $rn = 0;
        foreach($res as $u_res) {
                $return[$rn] = $u_res[0];
                $rn++;
        }
-       
+
        return $return;
-       
+
 }
 
 function gwvp_groupOwner($groupname)
 {
        $conn = gwvp_ConnectDB();
-       
+
        $sql = "select u.user_email from users u, groups g where g.groups_name='$groupname' and g.groups_owner_id=u.users_id";
 
        $res = $conn->query($sql);
        $return = false;
        foreach($res as $u_res) {
-               $return = $u_res[0];    
+               $return = $u_res[0];
        }
-       
+
        return $return;
 }
 
 function gwvp_getGroups()
 {
        $conn = gwvp_ConnectDB();
-       
+
        $res = $conn->query("select * from groups");
-       
+
        $returns = false;
        $rn = 0;
        foreach($res as $u_res) {
@@ -319,85 +331,85 @@ function gwvp_getGroups()
                $returns[$rn]["ownerid"] = $u_res["groups_owner_id"];
                $rn++;
        }
-       
+
        return $returns;
 }
 
 function gwvp_getGroupId($groupname)
 {
        $conn = gwvp_ConnectDB();
-       
+
        $sql = "select groups_id from groups where groups_name='$groupname'";
-       
+
        $res = $conn->query($sql);
        $return = false;
        foreach($res as $u_res) {
                $return = $u_res["groups_id"];
        }
-       
+
        return $return;
 }
 
 function gwvp_getUserId($useremail=null, $username = null)
 {
        $conn = gwvp_ConnectDB();
-       
+
        if($useremail != null) {
                $sql = "select users_id from users where user_email='$useremail'";
        } else if($username != null) {
                $sql = "select users_id from users where user_username='$username'";
        } else return false;
-       
+
        $res = $conn->query($sql);
        $return = false;
        foreach($res as $u_res) {
                $return = $u_res["users_id"];
        }
-       
+
        return $return;
 }
 
 function gwvp_getUserEmail($id)
 {
        $conn = gwvp_ConnectDB();
-       
+
        $sql = "select user_email from users where users_id='$id'";
-       
+
        $res = $conn->query($sql);
        $return = false;
        foreach($res as $u_res) {
                $return = $u_res["user_email"];
        }
-       
+
        return $return;
 }
 
 function gwvp_addGroupMember($email, $groupname)
 {
        $conn = gwvp_ConnectDB();
-       
+
        $uid = gwvp_getUserId($email);
        $gid = gwvp_getGroupId($groupname);
-       
+
        /*
         *              CREATE TABLE "group_membership" (
-           "groupmember_id" INTEGER PRIMARY KEY AUTOINCREMENT,
-           "groupmember_groupid" INTEGER,
-           "groupmember_userid" INTEGER
+        "groupmember_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+        "groupmember_groupid" INTEGER,
+        "groupmember_userid" INTEGER
 
         */
        if($uid!=false&&$gid!=false) $sql = "insert into group_membership values (null, '$gid', '$uid')";
        else return false;
-       
+
        $conn->query($sql);
-       
+
        return true;
 }
 
 function gwvp_IsGroupMember($email, $groupname)
 {
        $conn = gwvp_ConnectDB();
-       
+
        // i think this is right
        $sql = "
                        select count(*) from 
@@ -408,13 +420,13 @@ function gwvp_IsGroupMember($email, $groupname)
                                gm.groupmember_groupid=g.groups_id and
                                g.groups_name='$groupname'
                        ";
-       
+
        $res = $conn->query($sql);
        $result = 0;
        foreach($res as $u_res) {
                $result = $u_res[0];
        }
-       
+
        if($result == 0) return false;
        if($result == 1) return true;
 }
@@ -422,8 +434,8 @@ function gwvp_IsGroupMember($email, $groupname)
 function gwvp_IsUserAdmin($email=null, $username = null)
 {
        $conn = gwvp_ConnectDB();
-       
-       
+
+
        // TODO: clean this up, this should be a single query - idiot
        if($email != null) {
                $id = gwvp_getUserId($email);
@@ -432,32 +444,32 @@ function gwvp_IsUserAdmin($email=null, $username = null)
                $id = gwvp_getUserId(null, $username);
                $sql = "select groupmember_groupid from group_membership where groupmember_userid='$id'";
        } else return false;
-       
+
        $res = $conn->query($sql);
        $rn = 0;
        foreach($res as $u_res) {
-               $gid[$rn] = $u_res["groupmember_groupid"]; 
+               $gid[$rn] = $u_res["groupmember_groupid"];
                $rn++;
        }
-       
+
        foreach($gid as $gid_t) {
-       /*
-        *              CREATE TABLE groups (
-           "groups_id" INTEGER,
-           "groups_name" TEXT,
-           "groups_is_admin" INTEGER,
-               "groups_owner_id" INTEGER
-               )';
+               /*
+                *              CREATE TABLE groups (
+                "groups_id" INTEGER,
+                "groups_name" TEXT,
+                "groups_is_admin" INTEGER,
+                "groups_owner_id" INTEGER
+                )';
+
+                */
 
-        */
-               
                $sql = "select groups_is_admin from groups where groups_id='$gid_t'";
                $res = $conn->query($sql);
                foreach($res as $u_res) {
                        if($u_res["groups_is_admin"] == "1") return true;
-               }
+               }
        }
-       
+
        return false;
 }
 
@@ -465,27 +477,27 @@ function gwvp_ModifyUser($userid, $email=null, $fullname=null, $password=null, $
 {
        /*
         *          "users_id" INTEGER PRIMARY KEY AUTOINCREMENT,
-           "user_full_name" TEXT,
-           "user_password" TEXT,
-           "user_username" TEXT,
-           "user_email" TEXT,
-           "user_desc" TEXT,
-           "user_status" INTEGER
+        "user_full_name" TEXT,
+        "user_password" TEXT,
+        "user_username" TEXT,
+        "user_email" TEXT,
+        "user_desc" TEXT,
+        "user_status" INTEGER
 
         */
-       
+
        $conn = gwvp_ConnectDB();
-       
+
        if($email != null) {
                $sql = "update users set user_email='$email' where users_id='$userid'";
                $conn->query($sql);
        }
-       
+
        if($fullname != null) {
                $sql = "update users set user_full_name='$fullname' where users_id='$userid'";
                $conn->query($sql);
        }
-       
+
        if($password != null) {
                $shapass = sha1($password);
                $sql = "update users set user_password='$shapass' where users_id='$userid'";
@@ -506,7 +518,7 @@ function gwvp_ModifyUser($userid, $email=null, $fullname=null, $password=null, $
                $sql = "update users set user_status='$status' where users_id='$userid'";
                $conn->query($sql);
        }
-       
+
        return true;
 }
 
@@ -515,15 +527,15 @@ function gwvp_ModifyGroup($groupid, $groupname = null, $group_is_admin = null, $
 {
        /*
         *              CREATE TABLE groups (
-           "groups_id" INTEGER,
-           "groups_name" TEXT,
-           "groups_is_admin" INTEGER,
+        "groups_id" INTEGER,
+        "groups_name" TEXT,
+        "groups_is_admin" INTEGER,
                "groups_owner_id" INTEGER
                )';
 
         */
        $conn = gwvp_ConnectDB();
-       
+
        if($groupname != null) {
                $sql = "update groups set groups_name='$groupname' where groups_id='$groupid'";
                $conn->query($sql);
@@ -533,16 +545,57 @@ function gwvp_ModifyGroup($groupid, $groupname = null, $group_is_admin = null, $
                $sql = "update groups set groups_is_admin='$group_is_admin' where groups_id='$groupid'";
                $conn->query($sql);
        }
-       
+
        if($groups_owner_id != null) {
                $sql = "update groups set groups_owner_id='$groups_owner_id' where groups_id='$groupid'";
                $conn->query($sql);
        }
-       
+
        return true;
 }
+
+function gwvp_AddRepo($reponame, $repodesc, $repoowner)
+{
+       $conn = gwvp_ConnectDB();
+       
+       $sql = "insert into repos values (null, '$reponame', '$repodesc', '$repoowner')";
+       
+       $conn->query($sql);
+}
+
+function gwvp_GetRepoList()
+{
+       $conn = gwvp_ConnectDB();
+
+       /*
+        *      $reposql = '
+               CREATE TABLE "repos" (
+               "repos_id" INTEGER PRIMARY KEY AUTOINCREMENT,
+               "repos_name" TEXT,
+               "repos_description" TEXT,
+               "repos_owner" INTEGER
+               )';
+
+        */
+
+       $sql = "select * from repos";
+       
+       $res = $conn->query($sql);
+       
+       $return = false;
+       $rn = 0;
+       foreach($res as $u_res) {
+               $return[$rn]["id"] = $u_res["repos_id"];
+               $return[$rn]["name"] = $u_res["repos_name"];
+               $return[$rn]["description"] = $u_res["repos_description"];
+               $return[$rn]["owner"] = $u_res["repos_owner"];
+               $rn++;
+       }
+       
+       return $return;
+}
 /* functions we'll need to access data:
- * 
+ *
  * getUsers(pattern)
  * getUserData(username)
  * getGroups(pattern)
@@ -550,7 +603,7 @@ function gwvp_ModifyGroup($groupid, $groupname = null, $group_is_admin = null, $
  * modifyGroup(...)
  * addGroupMember(...)
  * deleteGroupMember(...)
- * 
+ *
  * createUser(...)
  * deleteUser(...)
  * modifyUser(...)
index 3793e31..b1df458 100644 (file)
@@ -97,6 +97,11 @@ function gwvp_DebugCall()
                                        gwvp_createGroup("usergroup", 0, gwvp_getUserId("user@localhost"));
                                        gwvp_addGroupMember("user@localhost", "usergroup");
                                        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);
+                                       
                                        header("Location: $BASE_URL/debug");
                                        break;
                                case "dropallusersandgroups":
index 49073c0..e0943ba 100644 (file)
@@ -8,7 +8,22 @@ function gwvp_RepoAdminCallMe()
 {
        if(isset($_REQUEST["q"])) {
                $query = $_REQUEST["q"];
-               if($query == "admin/repos") return "gwvp_RepoAdminPage";
+               $qspl = explode("/", $query);
+               if(isset($qspl[0]) && isset($qspl[1])) {
+                       if($qspl[0] == "admin" && $qspl[1] == "repos") {
+                               if(isset($qspl[2])) {
+                                       switch($qspl[2]) {
+                                               case "create":
+                                                       return "gwvp_CreateRepoPage";
+                                                       break;
+                                               default:
+                                                       return "gwvp_RepoAdminPage";
+                                       }                                       
+                               } else {
+                                       return "gwvp_RepoAdminPage";
+                               }
+                       }
+               } 
                else return false;
        }
        
@@ -23,7 +38,25 @@ function gwvp_RepoAdminPage()
 
 function gwvp_RepoAdminPageBody()
 {
-       echo "I am a repo admin page body";
+       // first we need a menu
+       global $BASE_URL;
+       
+       echo "<h2>Repo Management</h2>";
+       echo "<a href=\"$BASE_URL/admin/repos/create\">Create a Repo</a><br>";
+       
+       
+       // next we need a repo list - with perms checking - ug
+       $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) {
+               $rname = $u_res["name"];
+               $rdesc = $u_res["description"];
+               $rown = $u_res["owner"];
+               echo "<tr><td>$rname</td><td>$rdesc</td><td>$rown</td></tr>";
+       }
+       echo "</table>";
+       
+       return;
 }
 
 ?>
\ No newline at end of file