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

Ticket #2252 - Usage in Conversations module.

AntonLV 7 лет назад
Родитель
Сommit
62feb302fe

+ 25 - 0
modules/boonex/convos/classes/BxCnvFormEntry.php

@@ -105,6 +105,9 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
             if(!$oProfile)
                 continue;
 
+            if($this->_oModule->checkAllowedContact($iProfile) !== CHECK_ACTION_RESULT_ALLOWED)
+                continue;
+
             $iRecipient = $oProfile->id();
             if($bDraft && $iRecipient == $iSender)
                 $this->_oModule->_oDb->moveConvo($iContentId, $iRecipient, $iFolder);
@@ -205,4 +208,26 @@ class BxCnvFormEntry extends BxBaseModTextFormEntry
     }
 }
 
+class BxCnvFormEntryCheckerHelper extends BxDolFormCheckerHelper
+{
+    static public function checkRecipients($aIds)
+    {
+        $bResult = self::checkAvail($aIds);
+        if(!$bResult)
+            return $bResult;
+
+        $oModule = BxDolModule::getInstance('bx_convos');
+
+        $aIdsAllowed = array();
+        foreach($aIds as $iId)
+            if($oModule->checkAllowedContact($iId) === CHECK_ACTION_RESULT_ALLOWED)
+                $aIdsAllowed[] = $iId;
+
+        if(empty($aIdsAllowed)) 
+            return false;
+
+        return true;
+    }
+}
+
 /** @} */

+ 45 - 0
modules/boonex/convos/classes/BxCnvModule.php

@@ -187,6 +187,11 @@ class BxCnvModule extends BxBaseModTextModule
         echo(json_encode($a));
     }
 
+    public function serviceIsAllowedContact($iProfileId)
+    {
+        return $this->checkAllowedContact($iProfileId) === CHECK_ACTION_RESULT_ALLOWED;
+    }
+
     public function serviceConversationsInFolder ($iFolderId = BX_CNV_FOLDER_INBOX)
     {
         $oGrid = BxDolGrid::getObjectInstance($this->_oConfig->CNF['OBJECT_GRID']);
@@ -328,6 +333,31 @@ class BxCnvModule extends BxBaseModTextModule
         return true;
     }
 
+    /**
+     * Create entry form
+     * @return HTML string
+     */
+    public function serviceEntityCreate ($sParams = false)
+    {
+        $sProfilesIds = bx_get('profiles');
+        if($sProfilesIds !== false) {
+            $sDiv = ',';
+            $aIds = explode($sDiv, $sProfilesIds);
+
+            $aIdsAllowed = array();
+            foreach($aIds as $iId)
+                if($this->checkAllowedContact($iId) === CHECK_ACTION_RESULT_ALLOWED)
+                    $aIdsAllowed[] = $iId;
+
+            if(empty($aIdsAllowed))
+                return MsgBox(_t('_sys_txt_access_denied'));
+            
+            bx_set('profiles', implode($sDiv, $aIdsAllowed));
+        }
+
+        return parent::serviceEntityCreate();
+    }
+
     /**
      * Entry collaborators block
      */
@@ -445,6 +475,21 @@ class BxCnvModule extends BxBaseModTextModule
         return $this->serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction);
     }
 
+    /**
+     * Checks whether contact is allowed.
+     * @param integer $iProfileId - recipient profile ID
+     * @param boolean $isPerformAction - perform or just check the action
+     * @return CHECK_ACTION_RESULT_ALLOWED if access is granted or error message if access is forbidden. So make sure to make strict(===) checking.
+     */
+    public function checkAllowedContact($iProfileId, $isPerformAction = false)
+    {
+        $mixedResult = BxDolProfile::getInstance($iProfileId)->checkAllowedProfileContact();
+        if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
+            return _t('_sys_txt_access_denied');
+
+        return $this->checkAllowedAdd($isPerformAction);
+    }
+
     public function serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction = false, $iProfileId = false)
     {
         if (CHECK_ACTION_RESULT_ALLOWED !== ($sMsg = parent::serviceCheckAllowedViewForProfile ($aDataEntry, $isPerformAction, $iProfileId)))

+ 1 - 1
modules/boonex/convos/install/langs/en.xml

@@ -24,7 +24,7 @@
 	<string name="_bx_cnv_form_entry_input_attachments"><![CDATA[Attachments]]></string>
     <string name="_bx_cnv_form_entry_input_recipients"><![CDATA[Recipients]]></string>
     <string name="_bx_cnv_form_entry_input_sys_recipients"><![CDATA[Recipients]]></string>
-    <string name="_bx_cnv_form_entry_input_recipients_err"><![CDATA[Recipients is mandatory]]></string>
+    <string name="_bx_cnv_form_entry_input_recipients_err"><![CDATA[Mandatory field. Please, fill it in with profile(s) you are allowed to contact.]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_text"><![CDATA[Draft status]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_block"><![CDATA[Submit block]]></string>
     <string name="_bx_cnv_form_entry_input_sys_draft_id"><![CDATA[Draft ID]]></string>

+ 3 - 3
modules/boonex/convos/install/sql/enable.sql

@@ -113,9 +113,9 @@ INSERT INTO `sys_menu_items` (`set_name`, `module`, `name`, `title_system`, `tit
 
 -- MENU: add menu item to profiles modules actions menu (trigger* menu sets are processed separately upon modules enable/disable)
 
-INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `active`, `copyable`, `order`) VALUES 
-('trigger_profile_view_actions', 'bx_convos', 'convos-compose', '_bx_cnv_menu_item_title_system_message', '_bx_cnv_menu_item_title_message', 'page.php?i=start-convo&profiles={profile_id}', '', '', 'envelope', '', 2147483646, 1, 0, 0),
-('trigger_group_view_actions', 'bx_convos', 'convos-compose', '_bx_cnv_menu_item_title_system_message_group', '_bx_cnv_menu_item_title_message_group', 'page.php?i=start-convo&profiles={recipients}', '', '', 'envelope', '', 2147483646, 1, 0, 0);
+INSERT INTO `sys_menu_items`(`set_name`, `module`, `name`, `title_system`, `title`, `link`, `onclick`, `target`, `icon`, `submenu_object`, `visible_for_levels`, `visibility_custom`, `active`, `copyable`, `order`) VALUES 
+('trigger_profile_view_actions', 'bx_convos', 'convos-compose', '_bx_cnv_menu_item_title_system_message', '_bx_cnv_menu_item_title_message', 'page.php?i=start-convo&profiles={profile_id}', '', '', 'envelope', '', 2147483646, 'a:3:{s:6:"module";s:9:"bx_convos";s:6:"method";s:18:"is_allowed_contact";s:6:"params";a:1:{i:0;s:12:"{profile_id}";}}', 1, 0, 0),
+('trigger_group_view_actions', 'bx_convos', 'convos-compose', '_bx_cnv_menu_item_title_system_message_group', '_bx_cnv_menu_item_title_message_group', 'page.php?i=start-convo&profiles={recipients}', '', '', 'envelope', '', 2147483646, '', 1, 0, 0);
 
 -- GRID
 

+ 2 - 2
modules/boonex/convos/install/sql/install.sql

@@ -123,7 +123,7 @@ INSERT INTO `sys_transcoder_filters` (`transcoder_object`, `filter`, `filter_par
 -- FORMS
 
 INSERT INTO `sys_objects_form`(`object`, `module`, `title`, `action`, `form_attrs`, `table`, `key`, `uri`, `uri_title`, `submit_name`, `params`, `deletable`, `active`, `override_class_name`, `override_class_file`) VALUES 
-('bx_convos', 'bx_convos', '_bx_cnv_form_entry', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_convos_conversations', 'id', '', '', 'do_submit', '', 0, 1, 'BxCnvFormEntry', 'modules/boonex/convos/classes/BxCnvFormEntry.php');
+('bx_convos', 'bx_convos', '_bx_cnv_form_entry', '', 'a:1:{s:7:\"enctype\";s:19:\"multipart/form-data\";}', 'bx_convos_conversations', 'id', '', '', 'do_submit', 'a:1:{s:14:"checker_helper";s:27:"BxCnvFormEntryCheckerHelper";}', 0, 1, 'BxCnvFormEntry', 'modules/boonex/convos/classes/BxCnvFormEntry.php');
 
 INSERT INTO `sys_form_displays`(`object`, `display_name`, `module`, `view_mode`, `title`) VALUES 
 ('bx_convos', 'bx_convos_entry_add', 'bx_convos', 0, '_bx_cnv_form_entry_display_add'),
@@ -139,7 +139,7 @@ INSERT INTO `sys_form_inputs`(`object`, `module`, `name`, `value`, `values`, `ch
 ('bx_convos', 'bx_convos', 'submit_block', '', 'do_submit,submit_text', 0, 'input_set', '_bx_cnv_form_entry_input_sys_submit_block', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 ('bx_convos', 'bx_convos', 'draft_id', '0', '', 0, 'hidden', '_bx_cnv_form_entry_input_sys_draft_id', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', 0, 0),
 ('bx_convos', 'bx_convos', 'text', '', '', 0, 'textarea', '_bx_cnv_form_entry_input_sys_text', '_bx_cnv_form_entry_input_text', '', 1, 0, 2, '', '', '', 'Avail', '', '_bx_cnv_form_entry_input_text_err', 'XssHtml', '', 1, 0),
-('bx_convos', 'bx_convos', 'recipients', '', '', 0, 'custom', '_bx_cnv_form_entry_input_sys_recipients', '_bx_cnv_form_entry_input_recipients', '', 1, 0, 0, '', '', '', 'Avail', '', '_bx_cnv_form_entry_input_recipients_err', '', '', 1, 0),
+('bx_convos', 'bx_convos', 'recipients', '', '', 0, 'custom', '_bx_cnv_form_entry_input_sys_recipients', '_bx_cnv_form_entry_input_recipients', '', 1, 0, 0, '', '', '', 'Recipients', '', '_bx_cnv_form_entry_input_recipients_err', '', '', 1, 0),
 ('bx_convos', 'bx_convos', 'attachments', 'a:1:{i:0;s:9:"sys_html5";}', 'a:2:{s:10:"sys_simple";s:26:"_sys_uploader_simple_title";s:9:"sys_html5";s:25:"_sys_uploader_html5_title";}', 0, 'files', '_bx_cnv_form_entry_input_sys_attachments', '_bx_cnv_form_entry_input_attachments', '', 0, 0, 0, '', '', '', '', '', '', '', '', 1, 0);
 
 INSERT INTO `sys_form_display_inputs` (`display_name`, `input_name`, `visible_for_levels`, `active`, `order`) VALUES

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

@@ -24,7 +24,7 @@
 	<string name="_bx_cnv_form_entry_input_attachments"><![CDATA[Прикрепления]]></string>
     <string name="_bx_cnv_form_entry_input_recipients"><![CDATA[Получатели]]></string>
     <string name="_bx_cnv_form_entry_input_sys_recipients"><![CDATA[Получатели]]></string>
-    <string name="_bx_cnv_form_entry_input_recipients_err"><![CDATA[Необходимо указать хотя бы одного получателя]]></string>
+    <string name="_bx_cnv_form_entry_input_recipients_err"><![CDATA[Обязательное поле. Пожалуйста, укажите хотя бы одного получателя, которому Вы можете писать.]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_text"><![CDATA[Статус черновика]]></string>
     <string name="_bx_cnv_form_entry_input_sys_submit_block"><![CDATA[Блок отправки сообщения]]></string>
     <string name="_bx_cnv_form_entry_input_sys_draft_id"><![CDATA[ID черновика]]></string>