Skip to content

armgit / Vvveb

Public Imported from GitHub
0

Powerful and easy to use cms to build websites, blogs or ecommerce stores.

Added edit_other_posts capability check for posts to allow list, read, approve, edit, or delete, reported by @Mitchell45

givanz0ce6ba6baf59
diff --git a/admin/controller/content/posts.php b/admin/controller/content/posts.php
index 9aaa18e..8514d2d 100755
--- a/admin/controller/content/posts.php
+++ b/admin/controller/content/posts.php
@@ -114,6 +114,13 @@ class Posts extends Listing {
'post_id' => $post_id, 'type' => $this->type,
] + $this->global;
+ $editCapability = 'edit_other_posts';
+
+ if (Admin::hasCapability($editCapability)) {
+ unset($options['admin_id']);
+ } else {
+ }
+
$result = $this->posts->delete($options);
if ($result && isset($result['post'])) {
diff --git a/admin/sql/mysqli/post.sql b/admin/sql/mysqli/post.sql
index 86e7bef..27c85a7 100644
--- a/admin/sql/mysqli/post.sql
+++ b/admin/sql/mysqli/post.sql
@@ -1,6 +1,6 @@
-- Posts
- -- get all post
+ -- get all posts
CREATE PROCEDURE getAll(
IN start INT, -- start offset
@@ -247,7 +247,8 @@
@ELSE
@IF isset(:order_by)
THEN
- ORDER BY post.$order_by $direction
+ -- ORDER BY $order_by $direction
+ ORDER BY post.@ESC(:order_by) @ESC(:direction)
@ELSE
ORDER BY post.post_id DESC
END @IF
@@ -439,6 +440,7 @@
IN post_field_value ARRAY,
IN post_id INT,
IN site_id ARRAY,
+ IN admin_id INT,
OUT insert_id,
OUT affected_rows,
OUT insert_id,
@@ -503,6 +505,12 @@
SET @LIST(:post)
WHERE post_id = :post_id
+
+ @IF !empty(:admin_id)
+ THEN
+ AND admin_id = :admin_id
+ END @IF
+
END @IF;
@@ -532,6 +540,7 @@
CREATE PROCEDURE delete(
IN post_id ARRAY,
+ IN admin_id INT,
OUT affected_rows,
OUT affected_rows,
OUT affected_rows,
@@ -539,10 +548,32 @@
)
BEGIN
- DELETE FROM post_to_taxonomy_item WHERE post_id IN (:post_id);
- DELETE FROM post_to_site WHERE post_id IN (:post_id);
- DELETE FROM post_content WHERE post_id IN (:post_id);
- DELETE FROM post WHERE post_id IN (:post_id);
+ DELETE post_to_taxonomy_item FROM post_to_taxonomy_item
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_to_taxonomy_item.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_to_taxonomy_item.post_id IN (:post_id);
+
+ DELETE post_to_site FROM post_to_site
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_to_site.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_to_site.post_id IN (:post_id);
+
+ DELETE post_content FROM post_content
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_content.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_content.post_id IN (:post_id);
+
+ DELETE post FROM post WHERE post_id IN (:post_id)
+ @IF isset(:admin_id)
+ THEN
+ AND admin_id = :admin_id
+ END @IF;
END
diff --git a/admin/sql/pgsql/post.sql b/admin/sql/pgsql/post.sql
index c1f346b..273eef4 100644
--- a/admin/sql/pgsql/post.sql
+++ b/admin/sql/pgsql/post.sql
@@ -60,7 +60,7 @@
--,MATCH(pd.name, pd.content) AGAINST(:search) as score
,ts_rank(
to_tsvector(name) || to_tsvector(content),
- plainto_tsquery(:search)
+ websearch_to_tsquery(:search)
) AS score
END @IF
@@ -112,7 +112,7 @@
THEN
-- AND pd.name LIKE CONCAT('%',:search,'%')
-- AND MATCH(pd.name, pd.content) AGAINST(:search)
- AND to_tsvector(name) || to_tsvector(content) @@ plainto_tsquery(:search)
+ AND to_tsvector(name) || to_tsvector(content) @@ websearch_to_tsquery(:search)
END @IF
-- like
@@ -166,12 +166,18 @@
END @IF
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
- @IF isset(:order_by)
+ @IF isset(:search)
THEN
- ORDER BY post.$order_by $direction
+ ORDER BY score DESC
@ELSE
- ORDER BY post.post_id DESC
- END @IF
+ @IF isset(:order_by)
+ THEN
+ -- ORDER BY $order_by $direction
+ ORDER BY post.@ESC(:order_by) @ESC(:direction)
+ @ELSE
+ ORDER BY post.post_id DESC
+ END @IF
+ END @IF
-- limit
@IF isset(:limit)
@@ -359,6 +365,7 @@
IN post_field_value ARRAY,
IN post_id INT,
IN site_id ARRAY,
+ IN admin_id INT,
OUT fetch_one,
OUT affected_rows,
OUT fetch_one,
@@ -424,6 +431,12 @@
SET @LIST(:post)
WHERE post_id = :post_id
+
+ @IF !empty(:admin_id)
+ THEN
+ AND admin_id = :admin_id
+ END @IF
+
END @IF;
@@ -453,6 +466,7 @@
CREATE PROCEDURE delete(
IN post_id ARRAY,
+ IN admin_id INT,
OUT affected_rows,
OUT affected_rows,
OUT affected_rows,
@@ -460,10 +474,32 @@
)
BEGIN
- DELETE FROM post_to_taxonomy_item WHERE post_id IN (:post_id);
- DELETE FROM post_to_site WHERE post_id IN (:post_id);
- DELETE FROM post_content WHERE post_id IN (:post_id);
- DELETE FROM post WHERE post_id IN (:post_id);
+ DELETE post_to_taxonomy_item FROM post_to_taxonomy_item
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_to_taxonomy_item.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_to_taxonomy_item.post_id IN (:post_id);
+
+ DELETE post_to_site FROM post_to_site
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_to_site.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_to_site.post_id IN (:post_id);
+
+ DELETE post_content FROM post_content
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_content.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_content.post_id IN (:post_id);
+
+ DELETE post FROM post WHERE post_id IN (:post_id)
+ @IF isset(:admin_id)
+ THEN
+ AND admin_id = :admin_id
+ END @IF;
END
diff --git a/admin/sql/sqlite/post.sql b/admin/sql/sqlite/post.sql
index 1fbd59a..dacfa05 100644
--- a/admin/sql/sqlite/post.sql
+++ b/admin/sql/sqlite/post.sql
@@ -105,7 +105,7 @@
-- search
@IF isset(:search) && !empty(:search)
THEN
- -- AND pd.name LIKE CONCAT('%',:search,'%')
+ -- AND pd.name LIKE '%' || :search || '%'
-- AND MATCH(pd.name, pd.content) AGAINST(:search)
-- AND (pcs.name MATCH :search OR pcs.content MATCH :search)
AND (post_content_search = :search)
@@ -161,12 +161,18 @@
END @IF
-- ORDER BY parameters can't be binded, because they are added to the query directly they must be properly sanitized by only allowing a predefined set of values
- @IF isset(:order_by)
+ @IF isset(:search)
THEN
- ORDER BY post.$order_by $direction
+ ORDER BY rank
@ELSE
- ORDER BY post.post_id DESC
- END @IF
+ @IF isset(:order_by)
+ THEN
+ -- ORDER BY $order_by $direction
+ ORDER BY post.@ESC(:order_by) @ESC(:direction)
+ @ELSE
+ ORDER BY post.post_id DESC
+ END @IF
+ END @IF
-- limit
@IF isset(:limit)
@@ -354,6 +360,7 @@
IN post_field_value ARRAY,
IN post_id INT,
IN site_id ARRAY,
+ IN admin_id INT,
OUT insert_id,
OUT affected_rows,
OUT insert_id,
@@ -419,6 +426,12 @@
SET @LIST(:post)
WHERE post_id = :post_id
+
+ @IF !empty(:admin_id)
+ THEN
+ AND admin_id = :admin_id
+ END @IF
+
END @IF;
@@ -448,6 +461,7 @@
CREATE PROCEDURE delete(
IN post_id ARRAY,
+ IN admin_id INT,
OUT affected_rows,
OUT affected_rows,
OUT affected_rows,
@@ -455,10 +469,32 @@
)
BEGIN
- DELETE FROM post_to_taxonomy_item WHERE post_id IN (:post_id);
- DELETE FROM post_to_site WHERE post_id IN (:post_id);
- DELETE FROM post_content WHERE post_id IN (:post_id);
- DELETE FROM post WHERE post_id IN (:post_id);
+ DELETE post_to_taxonomy_item FROM post_to_taxonomy_item
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_to_taxonomy_item.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_to_taxonomy_item.post_id IN (:post_id);
+
+ DELETE post_to_site FROM post_to_site
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_to_site.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_to_site.post_id IN (:post_id);
+
+ DELETE post_content FROM post_content
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = post_content.post_id AND post.admin_id = :admin_id)
+ END @IF
+ WHERE post_content.post_id IN (:post_id);
+
+ DELETE post FROM post WHERE post_id IN (:post_id)
+ @IF isset(:admin_id)
+ THEN
+ AND admin_id = :admin_id
+ END @IF;
END
diff --git a/system/traits/crud.php b/system/traits/crud.php
index 00ee8b7..c4f3f92 100644
--- a/system/traits/crud.php
+++ b/system/traits/crud.php
@@ -49,6 +49,10 @@ trait Crud {
//protected $fullPost;
+ protected $userFilter = false;
+
+ protected $adminFilter = true;
+
function delete() {
if (APP == 'admin') {
$this->checkCsrf();
@@ -186,7 +190,15 @@ trait Crud {
}
$this->options += $this->global + $this->request->get;
- unset($this->options['user_id']);
+ //unset($this->options['user_id']);
+
+ if (! $this->userFilter) {
+ unset($this->options['user_id']);
+ }
+
+ if (! $this->adminFilter) {
+ unset($this->options['admin_id']);
+ }
$result = $this->model->get($this->options);
diff --git a/system/traits/listing.php b/system/traits/listing.php
index d0edbe0..2b77b62 100644
--- a/system/traits/listing.php
+++ b/system/traits/listing.php
@@ -43,6 +43,8 @@ trait Listing {
protected $modelName;
protected $userFilter = false;
+
+ protected $adminFilter = true;
protected $options = [];
@@ -75,6 +77,11 @@ trait Listing {
$model = model($this->modelName);
$options = [$type_id => $data_id] + $this->global;
+
+ if (! $this->adminFilter) {
+ unset($options['admin_id']);
+ }
+
$result = $model->delete($options);
$name = ucfirst(__($type));
@@ -124,6 +131,10 @@ trait Listing {
unset($options['user_id']);
}
+ if (! $this->adminFilter) {
+ unset($options['admin_id']);
+ }
+
if ($this->data_id && ($id = $this->request->get[$this->data_id] ?? false)) {
$options[$this->data_id] = $id;
}