Просмотр исходного кода

#3421 Comments: allow authors and groups admins to delete comments - Core & Posts & Groups

RomanL 5 лет назад
Родитель
Сommit
c5413c2b1e

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

@@ -2048,6 +2048,29 @@ 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)
     {

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

@@ -1112,6 +1112,17 @@ 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)
     {

+ 3 - 1
modules/boonex/groups/classes/BxGroupsConfig.php

@@ -87,7 +87,9 @@ 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',
             'OBJECT_STORAGE_COVER' => 'bx_groups_pics',

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

@@ -11,6 +11,8 @@
     <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>

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

@@ -19,7 +19,9 @@ 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_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);
 
 -- PAGES
 

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

@@ -85,6 +85,7 @@ 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',

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

@@ -14,7 +14,8 @@
     <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>
     <string name="_bx_posts_form_entry_display_edit"><![CDATA[Edit Post]]></string>

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

@@ -20,7 +20,8 @@ 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_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);
 
 -- PAGE: create entry