This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "FusionForge".

The branch, feature/filter-search-results has been created
        at  9108e16340bb577c915782c98e40e25abbeb7c3a (commit)

- Log -----------------------------------------------------------------
https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=9108e16340bb577c915782c98e40e25abbeb7c3a

commit 9108e16340bb577c915782c98e40e25abbeb7c3a
Author: Roland Mas <[email protected]>
Date:   Wed Mar 30 21:13:02 2016 +0200

    New way to calculate total number of rows

diff --git a/src/common/search/SearchQuery.class.php 
b/src/common/search/SearchQuery.class.php
index 342fc69..95f6929 100644
--- a/src/common/search/SearchQuery.class.php
+++ b/src/common/search/SearchQuery.class.php
@@ -45,12 +45,6 @@ class SearchQuery extends Error {
         */
        var $rowsCount = 0;
        /**
-        * Number of rows returned by the query
-        *
-        * @var int $rowsTotalCount
-        */
-       var $rowsTotalCount = 0;
-       /**
         * Offset
         *
         * @var int $offset
@@ -193,8 +187,7 @@ class SearchQuery extends Error {
                        $this->offset,
                        'SYS_DB_SEARCH'
                );
-               $this->rowsTotalCount = db_numrows($this->result);
-               $this->rowsCount = min($this->rowsPerPage, 
$this->rowsTotalCount);
+               $this->rowsCount = min($this->rowsPerPage, 
db_numrows($this->result));
        }
 
        /**
@@ -329,7 +322,8 @@ class SearchQuery extends Error {
         * @return int rows count
         */
        function getRowsTotalCount() {
-               return $this->rowsTotalCount;
+               $this->fetchAllData();
+               return count($this->cached_results);
        }
 
        /**

https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=3a0cb58b5a8ca06f8ed34dedc8455dd595fdfca1

commit 3a0cb58b5a8ca06f8ed34dedc8455dd595fdfca1
Author: Roland Mas <[email protected]>
Date:   Wed Mar 30 16:39:50 2016 +0200

    Split method to allow for partial fetches (if we don't want to paginate)

diff --git a/src/common/search/SearchQuery.class.php 
b/src/common/search/SearchQuery.class.php
index f7a2eb5..342fc69 100644
--- a/src/common/search/SearchQuery.class.php
+++ b/src/common/search/SearchQuery.class.php
@@ -207,7 +207,7 @@ class SearchQuery extends Error {
                return;
        }
 
-       function getData($limit = NULL, $offset = 0) {
+       function fetchDataUntil($limit = NULL) {
                if ($this->cached_results == NULL) {
                        $this->cached_results = array();
                }
@@ -220,7 +220,7 @@ class SearchQuery extends Error {
                }
 
                if ($limit) {
-                       while ((count($this->cached_results) < $limit + $offset)
+                       while ((count($this->cached_results) < $limit)
                                   && ($row = db_fetch_array($this->data_res))) 
{
                                if ($this->isRowVisible($row)) {
                                        $this->cached_results[] = $row;
@@ -233,7 +233,18 @@ class SearchQuery extends Error {
                                }
                        }
                }
+       }
 
+       function fetchAllData() {
+               $this->fetchDataUntil();
+       }          
+
+       function getData($limit = NULL, $offset = 0) {
+               if ($limit) {
+                       $this->fetchDataUntil($limit+$offset);
+               } else {
+                       $this->fetchAllData();
+               }
                return array_slice($this->cached_results, $offset, $limit);
        }
 

https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=82946bcd7128963972cae043fcb4451d0a0eda00

commit 82946bcd7128963972cae043fcb4451d0a0eda00
Author: Roland Mas <[email protected]>
Date:   Wed Mar 30 11:43:43 2016 +0200

    Handle paging

diff --git a/src/common/search/SearchQuery.class.php 
b/src/common/search/SearchQuery.class.php
index ecb8ddd..f7a2eb5 100644
--- a/src/common/search/SearchQuery.class.php
+++ b/src/common/search/SearchQuery.class.php
@@ -56,7 +56,7 @@ class SearchQuery extends Error {
         * @var int $offset
         */
        var $offset = 0;
-       /**
+       /**
         * Result handle
         *
         * @var resource $result
@@ -89,6 +89,18 @@ class SearchQuery extends Error {
        var $field_separator = ' ioM0Thu6_fieldseparator_kaeph9Ee ';
 
        /**
+        * Result handle
+        *
+        * @var resource $result
+        */
+       var $data_res;
+       /**
+        * Cached results (array of rows)
+        *
+        * @var array $cached_results
+        */
+       var $cached_results;
+       /**
         * Constructor
         *
         * @param       string  $words words we are searching for
@@ -115,6 +127,9 @@ class SearchQuery extends Error {
                $this->isExact = $isExact;
                $this->operator = $this->getOperator();
                $this->options = $options;
+
+               $this->data_res = NULL;
+               $this->cached_results = NULL;
        }
 
        /**
@@ -192,22 +207,34 @@ class SearchQuery extends Error {
                return;
        }
 
-       function getData() {
+       function getData($limit = NULL, $offset = 0) {
                if ($this->cached_results == NULL) {
                        $this->cached_results = array();
+               }
 
-                       $res = db_query_qpa (
+               if ($this->data_res == NULL) {
+                       $this->data_res = db_query_qpa (
                                $this->getQuery(),
                                'SYS_DB_SEARCH'
                                );
-                       while ($row = db_fetch_array($res)) {
+               }
+
+               if ($limit) {
+                       while ((count($this->cached_results) < $limit + $offset)
+                                  && ($row = db_fetch_array($this->data_res))) 
{
+                               if ($this->isRowVisible($row)) {
+                                       $this->cached_results[] = $row;
+                               }
+                       }
+               } else {
+                       while ($row = db_fetch_array($this->data_res)) {
                                if ($this->isRowVisible($row)) {
                                        $this->cached_results[] = $row;
                                }
                        }
                }
 
-               return $this->cached_results;
+               return array_slice($this->cached_results, $offset, $limit);
        }
 
        function isRowVisible($row) {

https://scm.fusionforge.org/anonscm/gitweb/?p=fusionforge/fusionforge.git;a=commitdiff;h=3d734c91a1e63b7359a4f0fbdb53af9a0b6b009b

commit 3d734c91a1e63b7359a4f0fbdb53af9a0b6b009b
Author: Roland Mas <[email protected]>
Date:   Tue Mar 29 22:08:14 2016 +0200

    Started machinery to filter search results according to permissions

diff --git a/src/common/search/ArtifactSearchQuery.class.php 
b/src/common/search/ArtifactSearchQuery.class.php
index 6a3d17d..74b7183 100644
--- a/src/common/search/ArtifactSearchQuery.class.php
+++ b/src/common/search/ArtifactSearchQuery.class.php
@@ -78,6 +78,12 @@ class ArtifactSearchQuery extends SearchQuery {
 
                return $qpa;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm('tracker',
+                                                               
$row['group_artifact_id'],
+                                                               'read');
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/DocsSearchQuery.class.php 
b/src/common/search/DocsSearchQuery.class.php
index 9a91f78..3fabe5e 100644
--- a/src/common/search/DocsSearchQuery.class.php
+++ b/src/common/search/DocsSearchQuery.class.php
@@ -149,6 +149,10 @@ class DocsSearchQuery extends SearchQuery {
                }
                return $sections;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm ('docman', $row['group_id'], 'read');
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/ExportProjectSearchQuery.class.php 
b/src/common/search/ExportProjectSearchQuery.class.php
index 6c14ab3..092bc5f 100644
--- a/src/common/search/ExportProjectSearchQuery.class.php
+++ b/src/common/search/ExportProjectSearchQuery.class.php
@@ -62,6 +62,10 @@ class ExportProjectSearchQuery extends SearchQuery {
                $qpa = db_construct_qpa($qpa, ') ORDER BY ts_rank(vectors, q) 
DESC, group_name ASC');
                return $qpa;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm ('project_read', $row['group_id']);
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/ForumSearchQuery.class.php 
b/src/common/search/ForumSearchQuery.class.php
index 365f558..9043d9b 100644
--- a/src/common/search/ForumSearchQuery.class.php
+++ b/src/common/search/ForumSearchQuery.class.php
@@ -75,6 +75,12 @@ class ForumSearchQuery extends SearchQuery {
                $qpa = db_construct_qpa($qpa, 'ORDER BY ts_rank(vectors, $1) 
DESC', array($words));
                return $qpa;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm('forum',
+                                                               
$row['group_forum_id'],
+                                                               'read');
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/ForumsSearchQuery.class.php 
b/src/common/search/ForumsSearchQuery.class.php
index 89db4ee..d732ebd 100644
--- a/src/common/search/ForumsSearchQuery.class.php
+++ b/src/common/search/ForumsSearchQuery.class.php
@@ -117,6 +117,12 @@ class ForumsSearchQuery extends SearchQuery {
                }
                return $sections;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm('forum',
+                                                               
$row['group_forum_id'],
+                                                               'read');
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/FrsSearchQuery.class.php 
b/src/common/search/FrsSearchQuery.class.php
index 8fc2f34..359f4d3 100644
--- a/src/common/search/FrsSearchQuery.class.php
+++ b/src/common/search/FrsSearchQuery.class.php
@@ -115,6 +115,10 @@ class FrsSearchQuery extends SearchQuery {
                }
                return $sections;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm ('project_read', $row['group_id']);
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/NewsSearchQuery.class.php 
b/src/common/search/NewsSearchQuery.class.php
index 692a853..c20689b 100644
--- a/src/common/search/NewsSearchQuery.class.php
+++ b/src/common/search/NewsSearchQuery.class.php
@@ -91,6 +91,12 @@ class NewsSearchQuery extends SearchQuery {
                }
                return $sections;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm('forum',
+                                                               
$row['forum_id'],
+                                                               'read');
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/ProjectSearchQuery.class.php 
b/src/common/search/ProjectSearchQuery.class.php
index e5b89d9..a0957ad 100644
--- a/src/common/search/ProjectSearchQuery.class.php
+++ b/src/common/search/ProjectSearchQuery.class.php
@@ -51,6 +51,9 @@ class ProjectSearchQuery extends SearchQuery {
                return $qpa;
        }
 
+       function isRowVisible($row) {
+               return forge_check_perm ('project_read', $row['group_id']);
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/SearchQuery.class.php 
b/src/common/search/SearchQuery.class.php
index 644d3ca..ecb8ddd 100644
--- a/src/common/search/SearchQuery.class.php
+++ b/src/common/search/SearchQuery.class.php
@@ -192,6 +192,28 @@ class SearchQuery extends Error {
                return;
        }
 
+       function getData() {
+               if ($this->cached_results == NULL) {
+                       $this->cached_results = array();
+
+                       $res = db_query_qpa (
+                               $this->getQuery(),
+                               'SYS_DB_SEARCH'
+                               );
+                       while ($row = db_fetch_array($res)) {
+                               if ($this->isRowVisible($row)) {
+                                       $this->cached_results[] = $row;
+                               }
+                       }
+               }
+
+               return $this->cached_results;
+       }
+
+       function isRowVisible($row) {
+               return true;
+       }
+
        function addMatchCondition($qpa, $fieldName) {
 
                if(!count($this->phrases)) {
diff --git a/src/common/search/TasksSearchQuery.class.php 
b/src/common/search/TasksSearchQuery.class.php
index 6019883..8530b81 100644
--- a/src/common/search/TasksSearchQuery.class.php
+++ b/src/common/search/TasksSearchQuery.class.php
@@ -118,6 +118,12 @@ class TasksSearchQuery extends SearchQuery {
                }
                return $sections;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm('pm',
+                                                               
$row['group_project_id'],
+                                                               'read');
+       }
 }
 
 // Local Variables:
diff --git a/src/common/search/TrackersSearchQuery.class.php 
b/src/common/search/TrackersSearchQuery.class.php
index 3608e17..6ad54e8 100644
--- a/src/common/search/TrackersSearchQuery.class.php
+++ b/src/common/search/TrackersSearchQuery.class.php
@@ -117,6 +117,12 @@ class TrackersSearchQuery extends SearchQuery {
                }
                return $sections;
        }
+
+       function isRowVisible($row) {
+               return forge_check_perm('tracker',
+                                                               
$row['group_artifact_id'],
+                                                               'read');
+       }
 }
 
 // Local Variables:

-----------------------------------------------------------------------


hooks/post-receive
-- 
FusionForge

_______________________________________________
Fusionforge-commits mailing list
[email protected]
http://lists.fusionforge.org/cgi-bin/mailman/listinfo/fusionforge-commits

Reply via email to