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 comments to allow list, read, approve, edit, or delete, reported by @Mitchell45

givanz70ec3c69f56d
diff --git a/admin/controller/content/comment.php b/admin/controller/content/comment.php
old mode 100755
new mode 100644
index 80c4eb2..10ee72d
--- a/admin/controller/content/comment.php
+++ b/admin/controller/content/comment.php
@@ -25,6 +25,7 @@ namespace Vvveb\Controller\Content;
use function Vvveb\__;
use Vvveb\Controller\Base;
use function Vvveb\model;
+use Vvveb\System\User\Admin;
class Comment extends Base {
protected $type = 'comment';
@@ -35,10 +36,24 @@ class Comment extends Base {
$comment = $this->request->post[$type] ?? false;
if ($comment) {
+ $data = [$type => $comment, $type . '_id' => $comment_id];
+
+ $editCapability = 'edit_other_posts';
+
+ if ($this->type != 'comment') {
+ $editCapability = 'edit_other_products';
+ }
+
+ if (Admin::hasCapability($editCapability)) {
+ //unset($data['admin_id']);
+ } else {
+ $data['admin_id'] = $this->global['admin_id'];
+ }
+
$comments = model($type);
if ($comment_id) {
- $result = $comments->edit([$type => $comment, $type . '_id' => $comment_id]);
+ $result = $comments->edit($data);
} else {
$result = $comments->add([$type => $comment]);
}
@@ -64,6 +79,21 @@ class Comment extends Base {
] + $this->global;
unset($options['user_id']);
+ $viewCapability = 'view_other_posts';
+ if ($this->type != 'comment') {
+ $viewCapability = 'view_other_products';
+ }
+
+ if (Admin::hasCapability($viewCapability)) {
+ unset($options['admin_id']);
+ } else {
+ $options['admin_id'] = $this->global['admin_id'];
+ }
+
$this->view->$type = $comments->get($options);
+
+ if (! $this->view->$type) {
+ $this->notFound();
+ }
}
}
diff --git a/admin/controller/content/comments.php b/admin/controller/content/comments.php
index 64d49fb..6d5fc5a 100644
--- a/admin/controller/content/comments.php
+++ b/admin/controller/content/comments.php
@@ -30,6 +30,7 @@ use Vvveb\Sql\commentSQL;
use Vvveb\System\CacheManager;
use Vvveb\System\Core\View;
use Vvveb\System\Images;
+use Vvveb\System\User\Admin;
class Comments extends Listing {
protected $type = 'comment';
@@ -40,15 +41,44 @@ class Comments extends Listing {
protected $listController = 'comments';
+ function delete() {
+ $editCapability = 'edit_other_posts';
+
+ if ($this->module == 'product') {
+ $editCapability = 'edit_other_products';
+ }
+
+ if (Admin::hasCapability($editCapability)) {
+ $this->userFilter = false;
+ } else {
+ }
+
+ parent::delete();
+ }
+
function save() {
$type = $this->type;
$comment_id = $this->request->get[$type . '_id'] ?? $this->request->post[$type . '_id'] ?? false;
$status = $this->request->get['newstatus'] ?? $this->request->post['newstatus'] ?? false;
if ($comment_id) {
+ $data = [$type => ['status' => (int) $status], $type . '_id' => $comment_id];
+
+ $editCapability = 'edit_other_posts';
+
+ if ($this->module == 'product') {
+ $editCapability = 'edit_other_products';
+ }
+
+ if (Admin::hasCapability($editCapability)) {
+ unset($data['admin_id']);
+ } else {
+ $data['admin_id'] = $this->global['admin_id'];
+ }
+
$comments = model($type);
- if ($comments->edit([$type => ['status' => (int) $status], $type . '_id' => $comment_id])) {
+ if ($comments->edit($data)) {
//CacheManager::delete($type);
CacheManager::delete();
$this->view->success[] = sprintf(__('%s status changed!'), humanReadable(__($type)));
@@ -88,6 +118,17 @@ class Comments extends Listing {
$options['status'] = $status;
}
+ $viewCapability = 'view_other_posts';
+ if ($this->module == 'product') {
+ $viewCapability = 'view_other_products';
+ }
+
+ if (Admin::hasCapability($viewCapability)) {
+ unset($options['admin_id']);
+ } else {
+ $options['admin_id'] = $this->global['admin_id'];
+ }
+
$results = $comments->getAll($options);
$results[$type] = $results[$type] ?? [];
@@ -102,12 +143,12 @@ class Comments extends Listing {
$url = ['module' => "$module/$listController", 'action' => 'save', 'status' => $status, $type . '_id' => $comment[$type . '_id']];
$postUrl = ['module' => "$module/$controller", $type . '_id' => $comment[$type . '_id']];
-
+
$comment['author-url'] = '';
if ($comment['user_id']) {
$comment['author-url'] = \Vvveb\url(['module' => 'user/user', 'user_id' => $comment['user_id']]);
}
-
+
$comment['edit-url'] = \Vvveb\url($postUrl);
$comment['delete-url'] = \Vvveb\url(['module' => "$module/$listController", 'action' => 'delete'] + $url);
$comment['approve-url'] = \Vvveb\url(['newstatus' => 1] + $url);
diff --git a/admin/sql/mysqli/comment.sql b/admin/sql/mysqli/comment.sql
index 823a88a..a0e7082 100644
--- a/admin/sql/mysqli/comment.sql
+++ b/admin/sql/mysqli/comment.sql
@@ -7,6 +7,7 @@
IN language_id INT,
IN post_id INT,
IN user_id INT,
+ IN admin_id INT,
IN status INT,
IN post_title INT,
@@ -30,6 +31,11 @@
FROM comment
LEFT JOIN user ON (user.user_id = comment.user_id)
+ @IF isset(:admin_id) AND :admin_id
+ THEN
+ LEFT JOIN post ON (post.post_id = comment.post_id)
+ END @IF
+
@IF isset(:post_title) AND :post_title
THEN
LEFT JOIN post_content ON (post_content.post_id = comment.post_id)
@@ -38,33 +44,39 @@
-- post
@IF isset(:post_id)
- THEN
- AND comment.post_id = :post_id
- END @IF
+ THEN
+ AND comment.post_id = :post_id
+ END @IF
-- post slug
@IF isset(:slug)
- THEN
- AND comment.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
- END @IF
+ THEN
+ AND comment.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
+ END @IF
-- user
@IF isset(:user_id)
- THEN
- AND comment.user_id = :user_id
- END @IF
+ THEN
+ AND comment.user_id = :user_id
+ END @IF
+
+ -- admin
+ @IF isset(:admin_id)
+ THEN
+ AND post.admin_id = :admin_id
+ END @IF
- -- user
+ -- user
@IF isset(:language_id) AND isset(:post_title)
- THEN
- AND post_content.language_id = :language_id
- END @IF
+ THEN
+ AND post_content.language_id = :language_id
+ END @IF
- -- user
+ -- status
@IF isset(:status)
- THEN
- AND comment.status = :status
- END @IF
+ THEN
+ AND comment.status = :status
+ END @IF
ORDER BY parent_id, comment_id
@@ -87,6 +99,7 @@
CREATE PROCEDURE get(
IN comment_id INT,
+ IN admin_id INT,
OUT fetch_row,
)
BEGIN
@@ -94,6 +107,12 @@
SELECT *
FROM comment AS _
LEFT JOIN user ON user.user_id = _.user_id
+
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON post.post_id = _.post_id AND post.admin_id = :admin_id
+ END @IF
+
WHERE 1 = 1
@IF isset(:comment_id)
@@ -133,7 +152,8 @@
CREATE PROCEDURE edit(
IN comment ARRAY,
- IN id_comment INT,
+ IN comment_id INT,
+ IN admin_id INT,
OUT affected_rows
)
BEGIN
@@ -141,21 +161,33 @@
@FILTER(:comment, comment)
UPDATE comment
-
- SET @LIST(:comment)
+
+ SET @LIST(:comment)
WHERE comment_id = :comment_id
-
+
+ @IF isset(:admin_id)
+ THEN
+ AND comment.post_id IN (SELECT post_id FROM post WHERE post.admin_id = :admin_id)
+ END @IF;
END
-- Delete comment
CREATE PROCEDURE delete(
- IN comment_id ARRAY,
+ IN comment_id ARRAY,
+ IN admin_id INT,
OUT affected_rows
)
BEGIN
- DELETE FROM comment WHERE comment_id IN (:comment_id)
+ DELETE comment FROM comment
+
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = comment.post_id AND post.admin_id = :admin_id)
+ END @IF
+
+ WHERE comment_id IN (:comment_id)
END
diff --git a/admin/sql/pgsql/comment.sql b/admin/sql/pgsql/comment.sql
old mode 100755
new mode 100644
index 8bacb08..bb9142c
--- a/admin/sql/pgsql/comment.sql
+++ b/admin/sql/pgsql/comment.sql
@@ -5,9 +5,9 @@
CREATE PROCEDURE getAll(
-- variables
IN language_id INT,
- IN site_id INT,
IN post_id INT,
IN user_id INT,
+ IN admin_id INT,
IN status INT,
IN post_title INT,
@@ -30,7 +30,12 @@
FROM comment
LEFT JOIN "user" ON ("user".user_id = comment.user_id)
-
+
+ @IF isset(:admin_id) AND :admin_id
+ THEN
+ LEFT JOIN post ON (post.post_id = comment.post_id)
+ END @IF
+
@IF isset(:post_title) AND :post_title
THEN
LEFT JOIN post_content ON (post_content.post_id = comment.post_id)
@@ -39,36 +44,42 @@
-- post
@IF isset(:post_id)
- THEN
- AND comment.post_id = :post_id
- END @IF
+ THEN
+ AND comment.post_id = :post_id
+ END @IF
-- post slug
@IF isset(:slug)
- THEN
- AND comment.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
- END @IF
+ THEN
+ AND comment.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
+ END @IF
-- user
@IF isset(:user_id)
- THEN
- AND comment.user_id = :user_id
- END @IF
-
- -- user
+ THEN
+ AND comment.user_id = :user_id
+ END @IF
+
+ -- admin
+ @IF isset(:admin_id)
+ THEN
+ AND post.admin_id = :admin_id
+ END @IF
+
+ -- user
@IF isset(:language_id) AND isset(:post_title)
- THEN
- AND post_content.language_id = :language_id
- END @IF
+ THEN
+ AND post_content.language_id = :language_id
+ END @IF
- -- user
+ -- status
@IF isset(:status)
- THEN
- AND comment.status = :status
- END @IF
-
- ORDER BY parent_id, comment_id
+ THEN
+ AND comment.status = :status
+ END @IF
+ ORDER BY parent_id, comment_id
+
@IF isset(:order) AND :order == "desc"
THEN
DESC
@@ -88,6 +99,7 @@
CREATE PROCEDURE get(
IN comment_id INT,
+ IN admin_id INT,
OUT fetch_row,
)
BEGIN
@@ -95,6 +107,12 @@
SELECT *
FROM comment AS _
LEFT JOIN "user" ON "user".user_id = _.user_id
+
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON post.post_id = _.post_id AND post.admin_id = :admin_id
+ END @IF
+
WHERE 1 = 1
@IF isset(:comment_id)
@@ -134,7 +152,8 @@
CREATE PROCEDURE edit(
IN comment ARRAY,
- IN id_comment INT,
+ IN comment_id INT,
+ IN admin_id INT,
OUT affected_rows
)
BEGIN
@@ -142,21 +161,32 @@
@FILTER(:comment, comment)
UPDATE comment
-
- SET @LIST(:comment)
+
+ SET @LIST(:comment)
WHERE comment_id = :comment_id
-
+
+ @IF isset(:admin_id)
+ THEN
+ AND comment.post_id IN (SELECT post_id FROM post WHERE post.admin_id = :admin_id)
+ END @IF;
END
-- Delete comment
CREATE PROCEDURE delete(
- IN comment_id ARRAY,
+ IN comment_id ARRAY,
OUT affected_rows
)
BEGIN
- DELETE FROM comment WHERE comment_id IN (:comment_id)
+ DELETE comment FROM comment
+
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = comment.post_id AND post.admin_id = :admin_id)
+ END @IF
+
+ WHERE comment_id IN (:comment_id)
END
diff --git a/admin/sql/sqlite/comment.sql b/admin/sql/sqlite/comment.sql
old mode 100755
new mode 100644
index f217c27..12bafb0
--- a/admin/sql/sqlite/comment.sql
+++ b/admin/sql/sqlite/comment.sql
@@ -5,9 +5,9 @@
CREATE PROCEDURE getAll(
-- variables
IN language_id INT,
- IN site_id INT,
IN post_id INT,
IN user_id INT,
+ IN admin_id INT,
IN status INT,
IN post_title INT,
@@ -30,7 +30,12 @@
FROM comment
LEFT JOIN user ON (user.user_id = comment.user_id)
-
+
+ @IF isset(:admin_id) AND :admin_id
+ THEN
+ LEFT JOIN post ON (post.post_id = comment.post_id)
+ END @IF
+
@IF isset(:post_title) AND :post_title
THEN
LEFT JOIN post_content ON (post_content.post_id = comment.post_id)
@@ -39,35 +44,41 @@
-- post
@IF isset(:post_id)
- THEN
- AND comment.post_id = :post_id
- END @IF
+ THEN
+ AND comment.post_id = :post_id
+ END @IF
-- post slug
@IF isset(:slug)
- THEN
- AND comment.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
- END @IF
+ THEN
+ AND comment.post_id = (SELECT post_id FROM post_content WHERE slug = :slug LIMIT 1)
+ END @IF
-- user
@IF isset(:user_id)
- THEN
- AND comment.user_id = :user_id
- END @IF
+ THEN
+ AND comment.user_id = :user_id
+ END @IF
- -- user
+ -- admin
+ @IF isset(:admin_id)
+ THEN
+ AND post.admin_id = :admin_id
+ END @IF
+
+ -- user
@IF isset(:language_id) AND isset(:post_title)
- THEN
- AND post_content.language_id = :language_id
- END @IF
+ THEN
+ AND post_content.language_id = :language_id
+ END @IF
- -- user
+ -- status
@IF isset(:status)
- THEN
- AND comment.status = :status
- END @IF
+ THEN
+ AND comment.status = :status
+ END @IF
- ORDER BY parent_id, comment_id
+ ORDER BY parent_id, comment_id
@IF isset(:order) AND :order == "desc"
THEN
@@ -88,6 +99,7 @@
CREATE PROCEDURE get(
IN comment_id INT,
+ IN admin_id INT,
OUT fetch_row,
)
BEGIN
@@ -95,6 +107,12 @@
SELECT *
FROM comment AS _
LEFT JOIN user ON user.user_id = _.user_id
+
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON post.post_id = _.post_id AND post.admin_id = :admin_id
+ END @IF
+
WHERE 1 = 1
@IF isset(:comment_id)
@@ -134,7 +152,8 @@
CREATE PROCEDURE edit(
IN comment ARRAY,
- IN id_comment INT,
+ IN comment_id INT,
+ IN admin_id INT,
OUT affected_rows
)
BEGIN
@@ -142,21 +161,32 @@
@FILTER(:comment, comment)
UPDATE comment
-
- SET @LIST(:comment)
+
+ SET @LIST(:comment)
WHERE comment_id = :comment_id
-
+
+ @IF isset(:admin_id)
+ THEN
+ AND comment.post_id IN (SELECT post_id FROM post WHERE post.admin_id = :admin_id)
+ END @IF;
END
-- Delete comment
CREATE PROCEDURE delete(
- IN comment_id ARRAY,
+ IN comment_id ARRAY,
OUT affected_rows
)
BEGIN
- DELETE FROM comment WHERE comment_id IN (:comment_id)
+ DELETE comment FROM comment
+
+ @IF isset(:admin_id)
+ THEN
+ INNER JOIN post ON (post.post_id = comment.post_id AND post.admin_id = :admin_id)
+ END @IF
+
+ WHERE comment_id IN (:comment_id)
END