Quellcode durchsuchen

Ticket #3732 - Pre-moderation for group based modules: Notifications. Approving in context.

AntonLV vor 4 Jahren
Ursprung
Commit
1fe33f84ba

+ 12 - 5
modules/base/general/classes/BxBaseModGeneralModule.php

@@ -50,9 +50,19 @@ class BxBaseModGeneralModule extends BxDolModule
     {
         $CNF = &$this->_oConfig->CNF;
 
-        if($aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id() || $this->_isModerator())
+        $iProfileId = bx_get_logged_profile_id();
+        if($aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId || $this->_isModerator())
             return true;
 
+        if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
+            $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
+            $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
+
+            $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
+            if(in_array($iProfileId, $aAdmins))
+                return true;
+        }
+
         if(isset($CNF['FIELD_STATUS']) && $aContentInfo[$CNF['FIELD_STATUS']] != 'active')
             return false;
 
@@ -3168,10 +3178,7 @@ class BxBaseModGeneralModule extends BxDolModule
             $iContextProfileId = abs((int)$aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
             $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
 
-            $aRecipients = bx_srv($oContextProfile->getModule(), 'get_admins_by_action', [$iContextProfileId, [
-                BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT, 
-                BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT
-            ]]);
+            $aRecipients = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
         }
 
         $sModule = $this->getName();

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

@@ -246,6 +246,14 @@ class BxBaseModGroupsModule extends BxBaseModProfileModule
         return $aResult;
     }
 
+    public function serviceGetAdminsToManageContent($iGroupProfileId)
+    {
+        return $this->serviceGetAdminsByAction($iGroupProfileId, [
+            BX_BASE_MOD_GROUPS_ACTION_EDIT_CONTENT, 
+            BX_BASE_MOD_GROUPS_ACTION_DELETE_CONTENT
+        ]);
+    }
+
     /**
      * Delete profile from fans and admins tables
      * @param $iProfileId profile id 

+ 11 - 0
modules/base/text/classes/BxBaseModTextModule.php

@@ -597,7 +597,9 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
     public function checkAllowedApprove($mixedContent, $isPerformAction = false)
     {
         $CNF = &$this->_oConfig->CNF;
+
         $sTxtError = '_sys_txt_access_denied';
+        $iProfileId = bx_get_logged_profile_id();
 
         if(!is_array($mixedContent))
             $mixedContent = $this->_oDb->getContentInfoById((int)$mixedContent);
@@ -611,6 +613,15 @@ class BxBaseModTextModule extends BxBaseModGeneralModule implements iBxDolConten
         if($this->_isModerator())
             return CHECK_ACTION_RESULT_ALLOWED;
 
+        if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
+            $iContextProfileId = abs((int)$mixedContent[$CNF['FIELD_ALLOW_VIEW_TO']]);
+            $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
+
+            $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
+            if(in_array($iProfileId, $aAdmins))
+                return CHECK_ACTION_RESULT_ALLOWED;
+        }
+        
         return _t($sTxtError);
     }    
 

+ 13 - 2
modules/base/text/classes/BxBaseModTextPageEntry.php

@@ -24,8 +24,19 @@ class BxBaseModTextPageEntry extends BxBaseModGeneralPageEntry
         if ($iContentId)
             $this->_aContentInfo = $this->_oModule->_oDb->getContentInfoById($iContentId);
 
-        $bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == bx_get_logged_profile_id();
+        $iProfileId = bx_get_logged_profile_id();
+
+        $bLoggedOwner = isset($this->_aContentInfo[$CNF['FIELD_AUTHOR']]) && $this->_aContentInfo[$CNF['FIELD_AUTHOR']] == $iProfileId;
         $bLoggedModerator = $this->_oModule->checkAllowedEditAnyEntry() === CHECK_ACTION_RESULT_ALLOWED;
+        $bLoggedContextModerator = false;
+        if(!empty($CNF['FIELD_ALLOW_VIEW_TO']) && (int)$this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']] < 0) {
+            $iContextProfileId = abs((int)$this->_aContentInfo[$CNF['FIELD_ALLOW_VIEW_TO']]);
+            $oContextProfile = BxDolProfile::getInstance($iContextProfileId);
+
+            $aAdmins = bx_srv($oContextProfile->getModule(), 'get_admins_to_manage_content', [$iContextProfileId]);
+            if(in_array($iProfileId, $aAdmins))
+                $bLoggedContextModerator = true;
+        }
 
         $sTitle = $sUrl = $sIcon = "";
         if ($this->_aContentInfo && CHECK_ACTION_RESULT_ALLOWED === $this->_oModule->checkAllowedView($this->_aContentInfo)) {
@@ -50,7 +61,7 @@ class BxBaseModTextPageEntry extends BxBaseModGeneralPageEntry
         
         $aInformers = array ();
         $oInformer = BxDolInformer::getInstance($this->_oTemplate);
-        if($oInformer && ($bLoggedOwner || $bLoggedModerator)) {
+        if($oInformer && ($bLoggedOwner || $bLoggedModerator || $bLoggedContextModerator)) {
             $iNow = time();
             $bFieldPublished = isset($CNF['FIELD_PUBLISHED']);
             $sStatus = isset($CNF['FIELD_STATUS']) && isset($this->_aContentInfo[$CNF['FIELD_STATUS']]) ? $this->_aContentInfo[$CNF['FIELD_STATUS']] : '';

+ 5 - 13
modules/boonex/notifications/classes/BxNtfsTemplate.php

@@ -199,10 +199,7 @@ class BxNtfsTemplate extends BxBaseModNotificationsTemplate
             $aEvent['content'][$sKey] = call_user_func_array('_t', $aCallParams);
         }
 
-        if($this->_isInContext($aEvent) && empty($aEvent['subobject_id']) && $oObjectOwner)
-            $sOwnerUnit = $oObjectOwner->getUnit(0, ['template' => 'unit_wo_info_links']);
-        else
-            $sOwnerUnit = $oOwner->getUnit(0, ['template' => 'unit_wo_info_links']);
+        $sOwnerUnit = $oOwner->getUnit(0, ['template' => 'unit_wo_info_links']);
 
         $bEventParsed = false;
         bx_alert($this->_oConfig->getName(), 'get_notification', 0, 0, [
@@ -363,11 +360,10 @@ class BxNtfsTemplate extends BxBaseModNotificationsTemplate
 
     protected function _getContentLangKey(&$aEvent)
     {
-        if(!empty($aEvent['subobject_id']))
-            return '_bx_ntfs_txt_subobject_added' . ($this->_isInContext($aEvent) ? '_in_context' : '');
+        $bInContext = $this->_isInContext($aEvent);
 
-        if($this->_isInContext($aEvent))
-            return '_bx_ntfs_txt_object_added_in_context';
+        if(!empty($aEvent['subobject_id']))
+            return '_bx_ntfs_txt_subobject_added' . ($bInContext ? '_in_context' : '');
 
         $sKey = '';
         switch($aEvent['action']) {
@@ -375,10 +371,6 @@ class BxNtfsTemplate extends BxBaseModNotificationsTemplate
                 $sKey = '_bx_ntfs_txt_object_pending_approval';
                 break;
 
-            case 'approved':
-                $sKey = '_bx_ntfs_txt_object_approved';
-                break;
-
             case 'publish_failed':
                 $sKey = '_bx_ntfs_txt_object_publish_failed';
                 break;
@@ -388,7 +380,7 @@ class BxNtfsTemplate extends BxBaseModNotificationsTemplate
                 break;
 
             default:
-                $sKey = '_bx_ntfs_txt_object_added';
+                $sKey = '_bx_ntfs_txt_object_' . $aEvent['action'] . ($bInContext ? '_in_context' : '');
         }
 
     	return $sKey;

+ 3 - 2
modules/boonex/notifications/install/langs/en.xml

@@ -107,11 +107,12 @@
     <string name="_bx_ntfs_txt_err_nothing_changed"><![CDATA[Nothing was changed.]]></string>
     <string name="_bx_ntfs_txt_err_cannot_perform"><![CDATA[Cannot perform the action.]]></string>
     <string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
-    <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{object_owner_name}</b> added a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> in <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
+    <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> has got a {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> added by <b class="bx-ntfs-content-profile">{object_owner_name}</b>]]></string>
+    <string name="_bx_ntfs_txt_object_approved"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> approved {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
+    <string name="_bx_ntfs_txt_object_approved_in_context"><![CDATA[<b class="bx-ntfs-content-entry">{entry_caption}</b> {entry_sample} was approved in <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_failed"><![CDATA[Failed to publish your {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_succeeded"><![CDATA[Your {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> was published successfully]]></string>
     <string name="_bx_ntfs_txt_object_pending_approval"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a pending approval {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
-    <string name="_bx_ntfs_txt_object_approved"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> approved your {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_subobject_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> added a {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_subobject_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> has got a {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
 

+ 3 - 2
modules/boonex/russian/data/langs/bx_notifications/ru.xml

@@ -107,11 +107,12 @@
     <string name="_bx_ntfs_txt_err_nothing_changed"><![CDATA[Ничего не изменилось.]]></string>
     <string name="_bx_ntfs_txt_err_cannot_perform"><![CDATA[Невозможно выполнить действие.]]></string>
     <string name="_bx_ntfs_txt_object_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
-    <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{object_owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> в <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
+    <string name="_bx_ntfs_txt_object_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> от <b class="bx-ntfs-content-profile">{object_owner_name}</b>]]></string>
+    <string name="_bx_ntfs_txt_object_approved"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - одобрение <b class="bx-ntfs-content-entry">{entry_caption}</b> ({entry_sample})]]></string>
+    <string name="_bx_ntfs_txt_object_approved_in_context"><![CDATA[<b class="bx-ntfs-content-entry">{entry_caption}</b> {entry_sample} - одобрение в <b class="bx-ntfs-content-profile">{owner_name}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_failed"><![CDATA[Ошибка при публикации: {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_publish_succeeded"><![CDATA[Успешная публикация: {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_object_pending_approval"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b> ожидает одобрения]]></string>
-    <string name="_bx_ntfs_txt_object_approved"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> активировал {entry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_subobject_added"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>
     <string name="_bx_ntfs_txt_subobject_added_in_context"><![CDATA[<b class="bx-ntfs-content-profile">{owner_name}</b> - {subentry_sample} <b class="bx-ntfs-content-entry">{entry_caption}</b>]]></string>