gforge-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gforge-commits] gforge/common/tracker ArtifactType.class, 1.21, 1.22 Ar


From: tperdue
Subject: [Gforge-commits] gforge/common/tracker ArtifactType.class, 1.21, 1.22 ArtifactTypeFactory.class, 1.6, 1.7
Date: Wed, 04 Aug 2004 11:18:45 -0500

Update of /cvsroot/gforge/gforge/common/tracker
In directory db.perdue.net:/home/tperdue/share/dev.gforge.org/common/tracker

Modified Files:
        ArtifactType.class ArtifactTypeFactory.class 
Log Message:
RBAC, DELETION, AND FORUM EMAIL GATEWAY

Index: ArtifactType.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/tracker/ArtifactType.class,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- ArtifactType.class  28 Feb 2004 14:11:52 -0000      1.21
+++ ArtifactType.class  4 Aug 2004 16:18:34 -0000       1.22
@@ -150,13 +150,13 @@
                                        return false;
                                }
                        }
-                       if (!$this->isPublic()) {
-                               $perm =& $this->Group->getPermission( 
session_get_user() );
-                               if (!$perm || !is_object($perm) || 
!$perm->isMember()) {
-                                       $this->setPermissionDeniedError();
-                                       $this->data_array = null;
-                                       return false;
-                               }
+                       //
+                       //  Make sure they can even access this object
+                       //
+                       if (!$this->userCanView()) {
+                               $this->setPermissionDeniedError();
+                               $this->data_array = null;
+                               return false;
                        }
                }
        }
@@ -166,8 +166,8 @@
         *
         *      @param  string  The type name.
         *      @param  string  The type description.
-        *      @param  bool    (1) true (0) false - viewable by general public.
-        *      @param  bool    (1) true (0) false - whether non-logged-in 
users can submit.
+        *  @param  bool        (1) true (0) false - viewable by general public.
+        *  @param  bool        (1) true (0) false - whether non-logged-in 
users can submit.
         *      @param  bool    (1) true (0) false - whether to email on all 
updates.
         *      @param  string  The address to send new entries and updates to.
         *      @param  int             Days before this item is considered 
overdue.
@@ -200,10 +200,10 @@
                        $email_all=0;
                }
 
-                $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
-                $is_public = ((!$is_public) ? 0 : $is_public);
-                $allow_anon = ((!$allow_anon) ? 0 : $allow_anon);
-                $email_all = ((!$email_all) ? 0 : $email_all);
+               $use_resolution = ((!$use_resolution) ? 0 : $use_resolution);
+               $is_public = ((!$is_public) ? 0 : $is_public);
+               $allow_anon = ((!$allow_anon) ? 0 : $allow_anon);
+               $email_all = ((!$email_all) ? 0 : $email_all);
 
 
                $sql="INSERT INTO 
@@ -250,8 +250,13 @@
                                db_rollback();
                                return false;
                        } else {
-                               db_commit();
-                               return $id;
+                               if (!$this->addAllUsers()) {
+                                       db_rollback();
+                                       return false;
+                               } else {
+                                       db_commit();
+                                       return $id;
+                               }
                        }
                }
        }
@@ -420,6 +425,69 @@
        }
 
        /**
+        *        delete - delete this tracker and all its related data.
+        *
+        *      @param  bool    I'm Sure.
+        *      @param  bool    I'm REALLY sure.
+        *        @return       bool true/false;
+        */
+       function delete($sure, $really_sure) {
+               if (!$sure || !$really_sure) {
+                       $this->setMissingParamsError();
+                       return false;
+               }
+               if (!$this->userIsAdmin()) {
+                       $this->setPermissionDeniedError();
+                       return false;
+               }
+               db_begin();
+               db_query("DELETE FROM artifact_canned_responses 
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '1'.db_error();
+               db_query("DELETE FROM artifact_category
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '2'.db_error();
+               db_query("DELETE FROM artifact_perm
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '3'.db_error();
+               db_query("DELETE FROM artifact_group
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '4'.db_error();
+               db_query("DELETE FROM artifact_counts_agg
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '5'.db_error();
+               db_query("DELETE FROM artifact_file
+                       WHERE EXISTS (SELECT artifact_id FROM artifact 
+                       WHERE group_artifact_id='".$this->getID()."'
+                       AND artifact.artifact_id=artifact_file.artifact_id)");
+//echo '6'.db_error();
+               db_query("DELETE FROM artifact_message
+                       WHERE EXISTS (SELECT artifact_id FROM artifact 
+                       WHERE group_artifact_id='".$this->getID()."'
+                       AND 
artifact.artifact_id=artifact_message.artifact_id)");
+//echo '7'.db_error();
+               db_query("DELETE FROM artifact_history
+                       WHERE EXISTS (SELECT artifact_id FROM artifact 
+                       WHERE group_artifact_id='".$this->getID()."'
+                       AND 
artifact.artifact_id=artifact_history.artifact_id)");
+//echo '8'.db_error();
+               db_query("DELETE FROM artifact_monitor
+                       WHERE EXISTS (SELECT artifact_id FROM artifact 
+                       WHERE group_artifact_id='".$this->getID()."'
+                       AND 
artifact.artifact_id=artifact_history.artifact_id)");
+//echo '9'.db_error();
+               db_query("DELETE FROM artifact
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '10'.db_error();
+               db_query("DELETE FROM artifact_group_list
+                       WHERE group_artifact_id='".$this->getID()."'");
+//echo '11'.db_error();
+               
+               db_commit();
+               return true;
+       }
+
+       /**
         *      getCategories - List of possible categories set up for this 
artifact type.
         *
         *      @return database result set.
@@ -575,7 +643,34 @@
        }
 
        /**
-        *      addUser - add a user to this ArtifactType - depends on UNIQUE 
INDEX preventing duplicates.
+        *  addAllUsers - add all users to this artifact.
+        *
+        *  @return boolean success.
+        */
+       function addAllUsers() {
+               if (!$this->userIsAdmin()) {
+                       $this->setPermissionDeniedError();
+                       return false;
+               }
+               $sql="INSERT INTO artifact_perm 
(group_artifact_id,user_id,perm_level)
+                       SELECT '".$this->getID()."',user_id,artifact_flags
+                       FROM user_group
+                       WHERE
+                       group_id='".$this->Group->getID()."'
+                       AND NOT EXISTS (SELECT user_id FROM artifact_perm
+                       WHERE group_artifact_id='".$this->getID()."'
+                       AND user_id=user_group.user_id);";
+               $res= db_query($sql);
+               if (!$res) {
+                       $this->setError(db_error());
+                       return false;
+               } else {
+                       return true;
+               }
+       }
+
+       /**
+        *      addUser - add a user to this ArtifactType.
         *
         *      @param  int             user_id of the new user.
         *      @return boolean success.
@@ -589,14 +684,22 @@
                        $this->setMissingParamsError();
                        return false;
                }
-               $sql="INSERT INTO artifact_perm 
(group_artifact_id,user_id,perm_level) 
-                       VALUES ('".$this->getID()."','$id',0)";
+               $sql="SELECT * FROM artifact_perm 
+                       WHERE group_artifact_id='".$this->getID()."' 
+                       AND user_id='$id'";
                $result=db_query($sql);
-               if ($result && db_affected_rows($result) > 0) {
+               if (db_numrows($result) > 0) {
                        return true;
                } else {
-                       $this->setError(db_error());
-                       return false;
+                       $sql="INSERT INTO artifact_perm 
(group_artifact_id,user_id,perm_level) 
+                               VALUES ('".$this->getID()."','$id',0)";
+                       $result=db_query($sql);
+                       if ($result && db_affected_rows($result) > 0) {
+                               return true;
+                       } else {
+                               $this->setError(db_error());
+                               return false;
+                       }
                }
        }
 
@@ -604,7 +707,7 @@
         *      updateUser - update a user's permissions.
         *
         *      @param  int             user_id of the user to update.
-        *      @param  int             (1) tech only, (2) admin & tech (3) 
admin only.
+        *      @param  int             (0) read only, (1) tech only, (2) admin 
& tech (3) admin only.
         *      @return boolean success.
         */
        function updateUser($id,$perm_level) {
@@ -619,11 +722,21 @@
                $sql="UPDATE artifact_perm SET perm_level='$perm_level'
                        WHERE user_id='$id' AND 
group_artifact_id='".$this->getID()."'";
                $result=db_query($sql);
-               if ($result) {
-                       return true;
+               if (db_affected_rows($result) < 1) {
+                       //
+                       //  If not, insert it.
+                       //
+                       $sql="INSERT INTO artifact_perm 
(group_artifact_id,user_id,perm_level) VALUES
+                               ('".$this->getID()."','$id','$perm_level')";
+                       $result=db_query($sql);
+                       if (!$result) {
+                               $this->setError(db_error());
+                               return false;
+                       } else {
+                               return true;
+                       }
                } else {
-                       $this->setError(db_error());
-                       return false;
+                       return true;
                }
        }
 
@@ -672,12 +785,13 @@
                                return false;
                        } else {
                                //
-                               //      For now, we let any member of a project 
view this ArtifactType
-                               //      A future change might be to restrict to 
only those people with 
-                               //      a corresponding entry in artifact_perm 
table
+                               //      You must have an entry in artifact_perm 
if this tracker is not public
                                //
-                               $perm =& $this->Group->getPermission( 
session_get_user() );
-                               return $perm->isMember();
+                               if ($this->getCurrentUserPerm() >= 1) {
+                                       return true;
+                               } else {
+                                       return false;
+                               }
                        }
                }
        }
@@ -688,12 +802,16 @@
         *      @return boolean user_is_admin.
         */
        function userIsAdmin() { 
-               $perm =& $this->Group->getPermission( session_get_user() );
-
-               if (($this->getCurrentUserPerm() >= 2) || 
($perm->isArtifactAdmin())) {
-                       return true;
-               } else {
+               if (!session_loggedin()) {
                        return false;
+               } else {
+                       $perm =& $this->Group->getPermission( 
session_get_user() );
+
+                       if (($this->getCurrentUserPerm() >= 2) || 
($perm->isArtifactAdmin())) {
+                               return true;
+                       } else {
+                               return false;
+                       }
                }
        }
 
@@ -703,12 +821,16 @@
         *      @return boolean user_is_technician.
         */
        function userIsTechnician() { 
-               $perm =& $this->Group->getPermission( session_get_user() );
-
-               if (($this->getCurrentUserPerm() >= 1) || 
($perm->isArtifactAdmin())) {
-                       return true;
-               } else {
+               if (!session_loggedin()) {
                        return false;
+               } else {
+                       $perm =& $this->Group->getPermission( 
session_get_user() );
+
+                       if (($this->getCurrentUserPerm() >= 1) || 
($perm->isArtifactAdmin())) {
+                               return true;
+                       } else {
+                               return false;
+                       }
                }
        }
 
@@ -737,8 +859,6 @@
         *
         *  @param      string  The item name.
         *  @param      string  The item description.
-        *  @param      bool    (1) true (0) false - viewable by general public.
-        *  @param      bool    (1) true (0) false - whether non-logged-in 
users can submit.
         *  @param      bool    (1) true (0) false - whether to email on all 
updates.
         *  @param      string  The address to send new entries and updates to.
         *  @param      int             Days before this item is considered 
overdue.
@@ -748,13 +868,12 @@
         *  @param      string  Free-form string that project admins can place 
on the browse page.
         *  @return true on success, false on failure.
         */
-       function 
update($name,$description,$is_public,$allow_anon,$email_all,$email_address,
+       function update($name,$description,$email_all,$email_address,
                $due_period, 
$status_timeout,$use_resolution,$submit_instructions,$browse_instructions) {
 
                global $Language;
-               $perm =& $this->Group->getPermission(session_get_user());
 
-               if (!$perm || !is_object($perm) || !$perm->isArtifactAdmin()) {
+               if (!$this->userIsAdmin()) {
                        $this->setPermissionDeniedError();
                        return false;
                }
@@ -778,14 +897,10 @@
 
                $email_all = ((!$email_all) ? 0 : $email_all); 
                $use_resolution = ((!$use_resolution) ? 0 : $use_resolution); 
-               $allow_anon = ((!$allow_anon) ? 0 : $allow_anon); 
-               $is_public = ((!$is_public) ? 0 : $is_public); 
 
                $sql="UPDATE artifact_group_list SET 
                        name='". htmlspecialchars($name). "',
                        description='". htmlspecialchars($description) ."',
-                       is_public='$is_public',
-                       allow_anon='$allow_anon',
                        email_all_updates='$email_all',
                        email_address='$email_address',
                        due_period='". ($due_period * (60*60*24)) ."',

Index: ArtifactTypeFactory.class
===================================================================
RCS file: /cvsroot/gforge/gforge/common/tracker/ArtifactTypeFactory.class,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- ArtifactTypeFactory.class   28 Feb 2004 14:11:52 -0000      1.6
+++ ArtifactTypeFactory.class   4 Aug 2004 16:18:34 -0000       1.7
@@ -81,15 +81,6 @@
        }
 
        /**
-        *      setDataType - set the data type (DAO)
-        *
-        *      @param  string  the data type
-        */     
-       function &setDataType($newDataType) {
-               $this->dataType = $newDataType;
-       }
-
-       /**
         *      getArtifactTypes - return an array of ArtifactType objects.
         *
         *      @return array   The array of ArtifactType objects.
@@ -98,11 +89,24 @@
                if ($this->ArtifactTypes) {
                        return $this->ArtifactTypes;
                }
+               if (session_loggedin()) {
+                       $perm =& $this->Group->getPermission( 
session_get_user() );
+                       if (!$perm || !is_object($perm) || !$perm->isMember()) {
+                               $public_flag='=1';
+                       } else {
+                               $public_flag='<3';
+                               $exists=' AND EXISTS (SELECT group_artifact_ID
+                                       FROM artifact_perm
+                                       WHERE perm_level >= 0 AND 
group_artifact_id=artifact_group_list.group_artifact_id) ';
+                       }
+               } else {
+                       $public_flag='=1';
+               }
 
                $sql="SELECT * FROM artifact_group_list_vw
                        WHERE group_id='". $this->Group->getID() ."'
-                       AND is_public IN (".$this->getPublicFlag().")
-                       AND datatype ".$this->getDataTypeWhereClause()."
+                       AND is_public $public_flag
+                       $exists
                        ORDER BY group_artifact_id ASC";
 
                $result = db_query ($sql);
@@ -121,33 +125,11 @@
        }
 
        /**
-        * getDataTypeWhereClause - utility method to formulate the WHERE 
clause to include data types
-        *
-        * @return      string  A segment of a WHERE clause 
-        */
-       function &getDataTypeWhereClause() {
-               if ($this->dataType) {
-                       return "='".$this->dataType."' ";
-               }
-               return " LIKE '%' ";
-       }
-
-       /**
         * getPublicFlag - a utility method to load up the current user's 
permissions
         *
         * @return      string  The public_flag field to plug into a SQL string
         */     
        function &getPublicFlag() {
-               if (session_loggedin()) {
-                       $perm =& $this->Group->getPermission( 
session_get_user() );
-                       if (!$perm || !is_object($perm) || !$perm->isMember()) {
-                               $public_flag='1';
-                       } else {
-                               $public_flag='0,1';
-                       }
-               } else {
-                       $public_flag='1';
-               }
                return $public_flag;
        }
 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]