ソースを参照

#3421 Comments: allow authors and groups admins to delete comments

RomanL 5 年 前
親
コミット
108dc5066b

+ 15 - 2
inc/classes/BxDolCmts.php

@@ -1061,9 +1061,22 @@ class BxDolCmts extends BxDolFactory implements iBxDolReplaceable, iBxDolContent
         if(abs($aCmt['cmt_author_id']) == $this->_getAuthorId() && $this->checkAction ('comments remove own', $isPerformAction))
             return true;
         
-        $mixedResult = BxDolService::call($this->_aSystem['module'], 'check_allowed_delete_comments', array($this->getId(), $this->_getAuthorId()));
-        if($mixedResult === CHECK_ACTION_RESULT_ALLOWED)
+        $aContentInfo = BxDolRequest::serviceExists($this->_aSystem['module'], 'get_all') ? BxDolService::call($this->_aSystem['module'], 'get_all', array(array('type' => 'id', 'id' => $this->getId()))) : array();
+        $oModule = BxDolModule::getInstance($this->_aSystem['module']);
+        $CNF = $oModule->_oConfig->CNF;
+        
+        if ($aContentInfo[$CNF['FIELD_AUTHOR']] == $this->_getAuthorId() && $this->checkAction('comments remove in own content', $isPerformAction)){
             return true;
+        }
+        
+        if (isset($CNF['FIELD_ALLOW_VIEW_TO']) &&  $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0){
+            $iGroupProfileId = -(int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
+            $oProfileContext = BxDolProfile::getInstance($iGroupProfileId);
+            $oModule = BxDolModule::getInstance($oProfileContext->getModule()); 
+            if ($oModule->getRole($iGroupProfileId, $this->_getAuthorId()) === BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR && $this->checkAction('comments remove in group context', $isPerformAction)){
+                return true;
+            }
+        }
         
         return false;
     }

+ 16 - 0
install/sql/system.sql

@@ -773,6 +773,14 @@ INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`,
 ('system', 'comments remove all', NULL, '_sys_acl_action_comments_remove_all', '', 1, 3);
 SET @iIdActionCmtRemoveAll = LAST_INSERT_ID();
 
+INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
+('system', 'comments remove in own content', NULL, '_sys_acl_action_comments_remove_in_own_content', '', 1, 3);
+SET @iIdActionCmtRemoveInOwnContent = LAST_INSERT_ID();
+
+INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
+('system', 'comments remove in group context', NULL, '_sys_acl_action_comments_remove_in_group_context', '', 1, 3);
+SET @iIdActionCmtRemoveInGroupContext = LAST_INSERT_ID();
+
 INSERT INTO `sys_acl_actions` (`Module`, `Name`, `AdditionalParamName`, `Title`, `Desc`, `Countable`, `DisabledForLevels`) VALUES
 ('system', 'comments pin', NULL, '_sys_acl_action_comments_pin', '', 1, 3);
 SET @iIdActionCmtPin = LAST_INSERT_ID();
@@ -983,6 +991,14 @@ INSERT INTO `sys_acl_matrix` (`IDLevel`, `IDAction`) VALUES
 (@iModerator, @iIdActionCmtRemoveAll),
 (@iAdministrator, @iIdActionCmtRemoveAll),
 
+-- comments remove in own content
+(@iModerator, @iIdActionCmtRemoveInOwnContent),
+(@iAdministrator, @iIdActionCmtRemoveInOwnContent),
+
+-- comments remove in group context
+(@iModerator, @iIdActionCmtRemoveInGroupContext),
+(@iAdministrator, @iIdActionCmtRemoveInGroupContext),
+
 -- comments pin
 (@iModerator, @iIdActionCmtPin),
 (@iAdministrator, @iIdActionCmtPin),

+ 0 - 23
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -2048,29 +2048,6 @@ class BxBaseModGeneralModule extends BxDolModule
         
         return $this->serviceCheckAllowedWithContent('comments_post', $iContentId);
     }
-    
-    public function serviceCheckAllowedDeleteComments($iContentId, $iProfileId) 
-    {
-        $CNF = &$this->_oConfig->CNF;
-        if (!isset($CNF['PARAM_ALLOW_CONTENT_AUTHOR_DELETE_ANY_COMMENTS']))
-            return CHECK_ACTION_RESULT_NOT_ALLOWED;
-        
-        if (getParam($CNF['PARAM_ALLOW_CONTENT_AUTHOR_DELETE_ANY_COMMENTS']) == 'on'){
-            $aContentInfo = $this->_oDb->getContentInfoById($iContentId);
-            
-            if ($aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId)
-                return CHECK_ACTION_RESULT_ALLOWED;    
-            
-            if (isset($CNF['FIELD_ALLOW_VIEW_TO']) &&  $aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0){
-                $iGroupProfileId = -(int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']];
-                $oProfileContext = BxDolProfile::getInstance($iGroupProfileId);
-                $mixedResult = BxDolService::call($oProfileContext->getModule(), 'check_allowed_delete_comments_in_context', array($iGroupProfileId, $iProfileId));
-                if ($mixedResult === CHECK_ACTION_RESULT_ALLOWED)
-                    return CHECK_ACTION_RESULT_ALLOWED;
-            }
-        }
-        return CHECK_ACTION_RESULT_NOT_ALLOWED;
-    }
 
     public function serviceGetContentOwnerProfileId ($iContentId)
     {

+ 0 - 11
modules/base/groups/classes/BxBaseModGroupsModule.php

@@ -1112,17 +1112,6 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
     {
         return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
     }
-    
-    public function serviceCheckAllowedDeleteCommentsInContext($iGroupProfileId, $iProfileId) 
-    {
-        $CNF = &$this->_oConfig->CNF;
-        
-        if (getParam($CNF['PARAM_ALLOW_GROUP_ADMIN_DELETE_ANY_COMMENTS']) == 'on' &&  BX_BASE_MOD_GROUPS_ROLE_ADMINISTRATOR === $this->_oDb->getRole($iGroupProfileId, $iProfileId)){
-            return CHECK_ACTION_RESULT_ALLOWED;    
-        }
-        
-        return CHECK_ACTION_RESULT_NOT_ALLOWED;
-    }
 
     public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
     {

+ 2 - 0
modules/boonex/english/data/langs/system/en.xml

@@ -1876,6 +1876,8 @@
         <string name="_sys_acl_action_comments_pin"><![CDATA[Comments Pin]]></string>
 	<string name="_sys_acl_action_comments_post"><![CDATA[Comments Post]]></string>
 	<string name="_sys_acl_action_comments_remove_all"><![CDATA[Comments Remove All]]></string>
+  <string name="_sys_acl_action_comments_remove_in_own_content"><![CDATA[Comments Remove All In Own Content]]></string>
+  <string name="_sys_acl_action_comments_remove_in_group_context"><![CDATA[Comments Remove All In Context for Context's admins]]></string>
 	<string name="_sys_acl_action_comments_remove_own"><![CDATA[Comments Remove Own]]></string>
 	<string name="_sys_acl_action_connect"><![CDATA[Connect (befriend, follow, etc)]]></string>
 	<string name="_sys_acl_action_create_account"><![CDATA[Create Account]]></string>

+ 0 - 2
modules/boonex/groups/classes/BxGroupsConfig.php

@@ -87,8 +87,6 @@ class BxGroupsConfig extends BxBaseModGroupsConfig
             'PARAM_RECURRING_RESERVE' => 3, // 3 days for recurring payment to be registered
             'PARAM_PER_PAGE_FOR_FAVORITES_LISTS' => 'bx_groups_per_page_for_favorites_lists',
             'PARAM_USE_IN' => 'bx_groups_internal_notifications',
-            'PARAM_ALLOW_CONTENT_AUTHOR_DELETE_ANY_COMMENTS' => 'bx_groups_allow_content_author_delete_any_comments',
-            'PARAM_ALLOW_GROUP_ADMIN_DELETE_ANY_COMMENTS' => 'bx_groups_allow_group_admin_delete_any_comments',
             
             // objects
             'OBJECT_STORAGE' => 'bx_groups_pics',

+ 0 - 2
modules/boonex/groups/install/langs/en.xml

@@ -11,8 +11,6 @@
     <string name="_bx_groups_option_members_mode_multi_roles"><![CDATA[Multi Roles]]></string>
     <string name="_bx_groups_option_per_page_for_favorites_lists"><![CDATA[Number of favorite lists per page]]></string>
     <string name="_bx_groups_option_internal_notifications"><![CDATA[Use internal notifications]]></string>
-    <string name="_bx_groups_option_allow_content_author_delete_any_comments"><![CDATA[Allow content author to delete any comments posted on their content page]]></string>
-    <string name="_bx_groups_option_allow_group_admin_delete_any_comments"><![CDATA[Allow group admin to delete any comments posted into group context]]></string>
 
     <string name="_bx_groups_form_profile"><![CDATA[Groups]]></string>
     <string name="_bx_groups_form_profile_display_add"><![CDATA[Add Group]]></string>

+ 1 - 3
modules/boonex/groups/install/sql/enable.sql

@@ -19,9 +19,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `e
 ('bx_groups_per_page_for_favorites_lists', '5', @iCategId, '_bx_groups_option_per_page_for_favorites_lists', 'digit', '', '', '', 17),
 ('bx_groups_searchable_fields', 'group_name,group_desc', @iCategId, '_bx_groups_option_searchable_fields', 'list', 'a:2:{s:6:"module";s:9:"bx_groups";s:6:"method";s:21:"get_searchable_fields";}', '', '', 30),
 ('bx_groups_members_mode', '', @iCategId, '_bx_groups_option_members_mode', 'select', 'a:2:{s:6:"module";s:9:"bx_groups";s:6:"method";s:24:"get_options_members_mode";}', '', '', 40),
-('bx_groups_internal_notifications', '', @iCategId, '_bx_groups_option_internal_notifications', 'checkbox', '', '', '', 50),
-('bx_groups_allow_content_author_delete_any_comments', 'on', @iCategId, '_bx_groups_option_allow_content_author_delete_any_comments', 'checkbox', '', '', '', 55),
-('bx_groups_allow_group_admin_delete_any_comments', 'on', @iCategId, '_bx_groups_option_allow_group_admin_delete_any_comments', 'checkbox', '', '', '', 60);
+('bx_groups_internal_notifications', '', @iCategId, '_bx_groups_option_internal_notifications', 'checkbox', '', '', '', 50);
 
 -- PAGES
 

+ 0 - 1
modules/boonex/posts/classes/BxPostsConfig.php

@@ -85,7 +85,6 @@ class BxPostsConfig extends BxBaseModTextConfig
             'PARAM_SEARCHABLE_FIELDS' => 'bx_posts_searchable_fields',
             'PARAM_PER_PAGE_BROWSE_SHOWCASE' => 'bx_posts_per_page_browse_showcase',
             'PARAM_PER_PAGE_FOR_FAVORITES_LISTS' => 'bx_posts_per_page_for_favorites_lists',
-            'PARAM_ALLOW_CONTENT_AUTHOR_DELETE_ANY_COMMENTS' => 'bx_posts_allow_content_author_delete_any_comments',
 
             'PARAM_MULTICAT_ENABLED' => true,
             'PARAM_MULTICAT_AUTO_ACTIVATION_FOR_CATEGORIES' => 'bx_posts_auto_activation_for_categories',

+ 0 - 1
modules/boonex/posts/install/langs/en.xml

@@ -14,7 +14,6 @@
     <string name="_bx_posts_option_searchable_fields"><![CDATA[Searchable fields for keyword search]]></string>
     <string name="_bx_posts_option_auto_activation_for_categories"><![CDATA[Auto-Activation For Categories]]></string>
     <string name="_bx_posts_option_per_page_for_favorites_lists"><![CDATA[Number of favorite lists per page]]></string>
-    <string name="_bx_posts_option_allow_content_author_delete_any_comments"><![CDATA[Allow content author to delete any comments posted on their content page]]></string>
 
     <string name="_bx_posts_form_entry"><![CDATA[Posts]]></string>
     <string name="_bx_posts_form_entry_display_add"><![CDATA[Add Post]]></string>

+ 1 - 2
modules/boonex/posts/install/sql/enable.sql

@@ -20,8 +20,7 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `c
 ('bx_posts_per_page_for_favorites_lists', '5', @iCategId, '_bx_posts_option_per_page_for_favorites_lists', 'digit', '', '', '', 17),
 ('bx_posts_rss_num', '10', @iCategId, '_bx_posts_option_rss_num', 'digit', '', '', '', 20),
 ('bx_posts_searchable_fields', 'title,text', @iCategId, '_bx_posts_option_searchable_fields', 'list', '', '', 'a:2:{s:6:"module";s:8:"bx_posts";s:6:"method";s:21:"get_searchable_fields";}', 30),
-('bx_posts_auto_activation_for_categories', 'on', @iCategId, '_bx_posts_option_auto_activation_for_categories', 'checkbox', '', '', '', 35),
-('bx_posts_allow_content_author_delete_any_comments', 'on', @iCategId, '_bx_posts_option_allow_content_author_delete_any_comments', 'checkbox', '', '', '', 40);
+('bx_posts_auto_activation_for_categories', 'on', @iCategId, '_bx_posts_option_auto_activation_for_categories', 'checkbox', '', '', '', 35);
 
 -- PAGE: create entry
 

+ 3 - 1
modules/boonex/russian/data/langs/system/ru.xml

@@ -1861,7 +1861,9 @@
 	<string name="_sys_acl_action_comments_edit_own"><![CDATA[Комментарии - Редактировать Свои]]></string>
         <string name="_sys_acl_action_comments_pin"><![CDATA[Комментарии - Закреплять]]></string>
 	<string name="_sys_acl_action_comments_post"><![CDATA[Комментарии - Размещать]]></string>
-	<string name="_sys_acl_action_comments_remove_all"><![CDATA[Комментарии - Удалить Все]]></string>
+	<string name="_sys_acl_action_comments_remove_all"><![CDATA[Комментарии - Удалять Все]]></string>
+  <string name="_sys_acl_action_comments_remove_in_own_content"><![CDATA[Комментарии - Удалять в собственном контенте]]></string>
+  <string name="_sys_acl_action_comments_remove_in_group_context"><![CDATA[Комментарии - Удалять в контексте для администраторов контекста]]></string>
 	<string name="_sys_acl_action_comments_remove_own"><![CDATA[Комментарии - Удалить Собственные]]></string>
 	<string name="_sys_acl_action_connect"><![CDATA[Установить связь (подружиться, следить и т.п.)]]></string>
 	<string name="_sys_acl_action_create_account"><![CDATA[Создать Аккаунт]]></string>