From 15664dc5a6771cfcc0ff0975f747e865594b4063 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 22 Oct 2014 12:28:07 +0200 Subject: [PATCH] Admin or space admin can delete arbitrary content (#276 #282) --- protected/models/Content.php | 11 +++- .../modules_core/comment/models/Comment.php | 20 +++++++ .../comment/widgets/views/showComment.php | 57 +++++++++++-------- 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/protected/models/Content.php b/protected/models/Content.php index b563f6a005..1066e4ccab 100644 --- a/protected/models/Content.php +++ b/protected/models/Content.php @@ -285,14 +285,19 @@ class Content extends CActiveRecord public function canDelete($userId = "") { - if (HSetting::Get('canAdminAlwaysDeleteContent', 'security') == 1 && Yii::app()->user->isAdmin()) - return true; - if ($userId == "") $userId = Yii::app()->user->id; if ($this->created_by == $userId) return true; + + if (Yii::app()->user->isAdmin()) { + return true; + } + + if ($this->container instanceof Space && $this->container->isAdmin($userId)) { + return true; + } return false; } diff --git a/protected/modules_core/comment/models/Comment.php b/protected/modules_core/comment/models/Comment.php index 83e7ab70a6..9f05cd8ae2 100644 --- a/protected/modules_core/comment/models/Comment.php +++ b/protected/modules_core/comment/models/Comment.php @@ -172,4 +172,24 @@ class Comment extends HActiveRecordContentAddon return Yii::t('CommentModule.models_comment', 'Comment') . " \"" . Helpers::truncateText($this->message, 40) . "\""; } + public function canDelete($userId = "") + { + + if ($userId == "") + $userId = Yii::app()->user->id; + + if ($this->created_by == $userId) + return true; + + if (Yii::app()->user->isAdmin()) { + return true; + } + + if ($this->content->container instanceof Space && $this->content->container->isAdmin($userId)) { + return true; + } + + return false; + } + } diff --git a/protected/modules_core/comment/widgets/views/showComment.php b/protected/modules_core/comment/widgets/views/showComment.php index e1763dbd21..88aaaea751 100644 --- a/protected/modules_core/comment/widgets/views/showComment.php +++ b/protected/modules_core/comment/widgets/views/showComment.php @@ -9,40 +9,49 @@ * @since 0.5 */ ?> +canWrite(); +$canDelete = $comment->canDelete(); +?>
- canDelete()) : ?> +