Merge pull request #3096 from mepps/remove-autocomplete-email
[civicrm-core.git] / CRM / Mailing / Page / View.php
index ea0198dad3c016a84850710701984039f98ac6d0..9877b6c7d673a1b11f01a802749d60c626ae3653 100644 (file)
@@ -75,13 +75,13 @@ class CRM_Mailing_Page_View extends CRM_Core_Page {
    *
    * @return void
    */
-  function run($id = NULL, $contactID = NULL, $print = TRUE) {
+  function run($id = NULL, $contactID = NULL, $print = TRUE, $allowID = FALSE) {
     if (is_numeric($id)) {
       $this->_mailingID = $id;
     }
     else {
       $print = TRUE;
-      $this->_mailingID = CRM_Utils_Request::retrieve('id', 'Integer', CRM_Core_DAO::$_nullObject, TRUE);
+      $this->_mailingID = CRM_Utils_Request::retrieve('id', 'String', CRM_Core_DAO::$_nullObject, TRUE);
     }
 
     // # CRM-7651
@@ -96,8 +96,30 @@ class CRM_Mailing_Page_View extends CRM_Core_Page {
       $this->_contactID = $session->get('userID');
     }
 
-    $this->_mailing = new CRM_Mailing_BAO_Mailing();
-    $this->_mailing->id = $this->_mailingID;
+    // mailing key check
+    if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'hash_mailing_url')) {
+      $this->_mailing = new CRM_Mailing_BAO_Mailing();
+
+      if (!is_numeric($this->_mailingID)) {
+        $this->_mailing->hash = $this->_mailingID;
+      }
+      elseif (is_numeric($this->_mailingID)) {
+        $this->_mailing->id = $this->_mailingID;
+        // if mailing is present and associated hash is present
+        // while 'hash' is not been used for mailing view : throw 'permissionDenied'
+        if ($this->_mailing->find() &&
+          CRM_Core_DAO::getFieldValue('CRM_Mailing_BAO_Mailing', $this->_mailingID, 'hash', 'id') &&
+          !$allowID
+        ) {
+          CRM_Utils_System::permissionDenied();
+          return;
+        }
+      }
+    }
+    else {
+      $this->_mailing = new CRM_Mailing_BAO_Mailing();
+      $this->_mailing->id = $this->_mailingID;
+    }
 
     if (!$this->_mailing->find(TRUE) ||
       !$this->checkPermission()