From d997b52c36f6aaee989b3d603d517db912fdd3da Mon Sep 17 00:00:00 2001 From: Mzhelskiy Maxim Date: Tue, 18 Dec 2012 21:29:15 +0400 Subject: [PATCH] fix Issue #188 --- classes/modules/acl/ACL.class.php | 31 +++++++++++++---- .../topic/entity/Topic.entity.class.php | 33 +++++++++++++++++++ .../skin/developer/topic_part_header.tpl | 22 +++++++------ templates/skin/synio/topic_part_header.tpl | 6 ++-- 4 files changed, 73 insertions(+), 19 deletions(-) diff --git a/classes/modules/acl/ACL.class.php b/classes/modules/acl/ACL.class.php index f660e521..32f15e02 100644 --- a/classes/modules/acl/ACL.class.php +++ b/classes/modules/acl/ACL.class.php @@ -311,10 +311,20 @@ class ModuleACL extends Module { /** * Если модер или админ блога */ - $oBlogUser=$this->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$oUser->getId()); - if ($oBlogUser and ($oBlogUser->getIsModerator() or $oBlogUser->getIsAdministrator())) { - return true; + if ($this->User_GetUserCurrent() and $this->User_GetUserCurrent()->getId()==$oUser->getId()) { + /** + * Для авторизованного пользователя данный код будет работать быстрее + */ + if ($oTopic->getBlog()->getUserIsAdministrator() or $oTopic->getBlog()->getUserIsModerator()) { + return true; + } + } else { + $oBlogUser=$this->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$oUser->getId()); + if ($oBlogUser and ($oBlogUser->getIsModerator() or $oBlogUser->getIsAdministrator())) { + return true; + } } + return false; } /** @@ -340,9 +350,18 @@ class ModuleACL extends Module { /** * Если модер или админ блога */ - $oBlogUser=$this->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$oUser->getId()); - if ($oBlogUser and ($oBlogUser->getIsModerator() or $oBlogUser->getIsAdministrator())) { - return true; + if ($this->User_GetUserCurrent() and $this->User_GetUserCurrent()->getId()==$oUser->getId()) { + /** + * Для авторизованного пользователя данный код будет работать быстрее + */ + if ($oTopic->getBlog()->getUserIsAdministrator() or $oTopic->getBlog()->getUserIsModerator()) { + return true; + } + } else { + $oBlogUser=$this->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(),$oUser->getId()); + if ($oBlogUser and ($oBlogUser->getIsModerator() or $oBlogUser->getIsAdministrator())) { + return true; + } } return false; } diff --git a/classes/modules/topic/entity/Topic.entity.class.php b/classes/modules/topic/entity/Topic.entity.class.php index 78b2afbb..73f1eeec 100644 --- a/classes/modules/topic/entity/Topic.entity.class.php +++ b/classes/modules/topic/entity/Topic.entity.class.php @@ -394,6 +394,39 @@ class ModuleTopic_EntityTopic extends Entity { } return false; } + /** + * Проверяет разрешение на удаление топика у текущего пользователя + * + * @return bool + */ + public function getIsAllowDelete() { + if ($oUser=$this->User_GetUserCurrent()) { + return $this->ACL_IsAllowDeleteTopic($this,$oUser); + } + return false; + } + /** + * Проверяет разрешение на редактирование топика у текущего пользователя + * + * @return bool + */ + public function getIsAllowEdit() { + if ($oUser=$this->User_GetUserCurrent()) { + return $this->ACL_IsAllowEditTopic($this,$oUser); + } + return false; + } + /** + * Проверяет разрешение на какое-либо действие для топика у текущего пользователя + * + * @return bool + */ + public function getIsAllowAction() { + if ($this->User_GetUserCurrent()) { + return $this->getIsAllowEdit() || $this->getIsAllowDelete(); + } + return false; + } /** * Возвращает количество добавивших топик в избранное * diff --git a/templates/skin/developer/topic_part_header.tpl b/templates/skin/developer/topic_part_header.tpl index 33bae8f1..8dce7bb6 100644 --- a/templates/skin/developer/topic_part_header.tpl +++ b/templates/skin/developer/topic_part_header.tpl @@ -35,15 +35,17 @@ - - + + {if $oTopic->getIsAllowAction()} + + {/if} \ No newline at end of file diff --git a/templates/skin/synio/topic_part_header.tpl b/templates/skin/synio/topic_part_header.tpl index d0a0de8b..fcea3f48 100644 --- a/templates/skin/synio/topic_part_header.tpl +++ b/templates/skin/synio/topic_part_header.tpl @@ -29,13 +29,13 @@ {/if} - {if $oUserCurrent and ($oUserCurrent->getId()==$oTopic->getUserId() or $oUserCurrent->isAdministrator() or $oBlog->getUserIsAdministrator() or $oBlog->getUserIsModerator() or $oBlog->getOwnerId()==$oUserCurrent->getId())} + {if $oTopic->getIsAllowAction()}