CRM-13823 Move dashboard notices to system check
authorAndrew Hunt <andrew@aghstrategies.com>
Sun, 26 Apr 2015 17:08:09 +0000 (13:08 -0400)
committerJon goldberg <jon@palantetech.coop>
Tue, 21 Jul 2015 20:37:37 +0000 (16:37 -0400)
----------------------------------------
* CRM-13823: Admin Status Page
  https://issues.civicrm.org/jira/browse/CRM-13823

CRM/Contact/Page/DashBoard.php
CRM/Utils/Check.php
CRM/Utils/Check/Env.php
CRM/Utils/Check/Message.php
CRM/Utils/Check/Security.php
css/civicrm.css
templates/CRM/Contact/Page/DashBoardDashlet.tpl

index 657fa89e1b32963743a6ad47899a501d26a051b1..87cdc6ed1d9e25de8a00d7b59ba1fdef211bd965 100644 (file)
@@ -50,8 +50,6 @@ class CRM_Contact_Page_DashBoard extends CRM_Core_Page {
     $resources->addScriptFile('civicrm', 'js/jquery/jquery.dashboard.js', 0, 'html-header', FALSE);
     $resources->addStyleFile('civicrm', 'css/dashboard.css');
 
-    $config = CRM_Core_Config::singleton();
-
     $resetCache = CRM_Utils_Request::retrieve('resetCache', 'Positive', CRM_Core_DAO::$_nullObject);
 
     CRM_Utils_System::setTitle(ts('CiviCRM Home'));
@@ -71,50 +69,6 @@ class CRM_Contact_Page_DashBoard extends CRM_Core_Page {
       $this->assign('hookContentPlacement', $contentPlacement);
     }
 
-    //check that default FROM email address, owner (domain) organization name and default mailbox are configured.
-    $fromEmailOK = TRUE;
-    $ownerOrgOK = TRUE;
-    $defaultMailboxOK = TRUE;
-
-    // Don't put up notices if user doesn't have administer CiviCRM permission
-    if (CRM_Core_Permission::check('administer CiviCRM')) {
-      $destination = CRM_Utils_System::url(
-        'civicrm/dashboard',
-        'reset=1',
-        FALSE, NULL, FALSE
-      );
-
-      $destination = urlencode($destination);
-
-      list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
-
-      if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
-        $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
-        $this->assign('fixEmailUrl', $fixEmailUrl);
-        $fromEmailOK = FALSE;
-      }
-
-      $domain = CRM_Core_BAO_Domain::getDomain();
-      $domainName = $domain->name;
-      if (!$domainName || $domainName == 'Default Domain Name') {
-        $fixOrgUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1&civicrmDestination={$destination}");
-        $this->assign('fixOrgUrl', $fixOrgUrl);
-        $ownerOrgOK = FALSE;
-      }
-
-      if (in_array('CiviMail', $config->enableComponents) &&
-        CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG"
-      ) {
-        $fixDefaultMailbox = CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1&civicrmDestination={$destination}");
-        $this->assign('fixDefaultMailbox', $fixDefaultMailbox);
-        $defaultMailboxOK = FALSE;
-      }
-    }
-
-    $this->assign('fromEmailOK', $fromEmailOK);
-    $this->assign('ownerOrgOK', $ownerOrgOK);
-    $this->assign('defaultMailboxOK', $defaultMailboxOK);
-
     $communityMessages = CRM_Core_CommunityMessages::create();
     if ($communityMessages->isEnabled()) {
       $message = $communityMessages->pick();
index b61f165ed598846d5da02bcf97f8d3aa97f621f2..a0bdcfc048bc48301d22cd093832a82d01cb786d 100644 (file)
@@ -84,11 +84,12 @@ class CRM_Utils_Check {
         $statusMessages = array();
         $statusType = 'alert';
 
+        uasort($messages, array(__CLASS__, 'severitySort'));
         foreach ($messages as $message) {
           if ($filter === TRUE || call_user_func($filter, $message->getSeverity()) >= 3) {
             $statusType = (call_user_func($filter, $message->getSeverity()) >= 4) ? 'error' : $statusType;
-            $statusMessages[] = $message->getMessage();
-            $statusTitle = $message->getTitle();
+             $statusMessage = $message->getMessage();
+             $statusMessages[] = $statusTitle = $message->getTitle();
           }
         }
 
@@ -97,9 +98,7 @@ class CRM_Utils_Check {
             $statusTitle = ts('Multiple Alerts');
             $statusMessage = '<ul><li>' . implode('</li><li>',$statusMessages) . '</li></ul>';
           }
-          else {
-            $statusMessage = array_shift($statusMessages);
-          }
+
           // TODO: add link to status page
           CRM_Core_Session::setStatus($statusMessage, $statusTitle, $statusType);
         }
@@ -107,6 +106,22 @@ class CRM_Utils_Check {
     }
   }
 
+  /**
+   * Sort messages based upon severity
+   *
+   * @param CRM_Utils_Check_Message $a
+   * @param CRM_Utils_Check_Message $b
+   * @return integer
+   */
+  public function severitySort($a, $b) {
+    $aSeverity = $a->getSeverity();
+    $bSeverity = $b->getSeverity();
+    if ($aSeverity == $bSeverity) {
+      return 0;
+    }
+    return (self::severityMap($aSeverity) > self::severityMap($bSeverity));
+  }
+
   /**
    * Get the integer value (useful for thresholds) of the severity.
    *
index 461be3439e40d68071f7889ca419fa6fd1cd9dcd..24e63310523afa0be51f3afbf3c44f546af9f8cb 100644 (file)
@@ -43,7 +43,9 @@ class CRM_Utils_Check_Env {
     $messages = array_merge(
       $this->checkMysqlTime(),
       $this->checkDebug(),
-      $this->checkOutboundMail()
+      $this->checkOutboundMail(),
+      $this->checkDomainNameEmail(),
+      $this->checkDefaultMailbox()
     );
     return $messages;
   }
@@ -66,7 +68,7 @@ class CRM_Utils_Check_Env {
           2 => $sqlNow,
           3 => $phpNow,
         )),
-        ts('Environment Settings'),
+        ts('Timestamp Mismatch'),
         \Psr\Log\LogLevel::ERROR
       );
     }
@@ -86,7 +88,7 @@ class CRM_Utils_Check_Env {
         'checkDebug',
         ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.',
           array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))),
-        ts('Debug Mode'),
+        ts('Debug Mode Enabled'),
         \Psr\Log\LogLevel::WARNING
       );
     }
@@ -110,7 +112,7 @@ class CRM_Utils_Check_Env {
         'checkOutboundMail',
         ts('Warning: Outbound email is disabled in <a href="%1">system settings</a>. Proper settings should be enabled on production servers.',
           array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))),
-        ts('Outbound Email Settings'),
+        ts('Outbound Email Disabled'),
         \Psr\Log\LogLevel::WARNING
       );
     }
@@ -118,4 +120,66 @@ class CRM_Utils_Check_Env {
     return $messages;
   }
 
+  /**
+   * Check that domain email and org name are set
+   * @return array
+   */
+
+  public function checkDomainNameEmail() {
+    $messages = array();
+
+    list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
+    $domain = CRM_Core_BAO_Domain::getDomain();
+    $domainName = $domain->name;
+    $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1");
+
+    if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
+      if (!$domainName || $domainName == 'Default Domain Name') {
+        $msg = ts("Please enter your organization's <a href=\"%1\">name, primary address, and default FROM Email Address</a> (for system-generated emails).",
+          array(1 => $fixEmailUrl));
+      }
+      else {
+        $msg = ts('Please enter a <a href="%1">default FROM Email Address</a> (for system-generated emails).',
+          array(1 => $fixEmailUrl));
+      }
+    }
+    elseif (!$domainName || $domainName == 'Default Domain Name') {
+      $msg = ts("Please enter your organization's <a href=\"%1\">name and primary address</a>.",
+        array(1 => $fixEmailUrl));
+    }
+    $messages[] = new CRM_Utils_Check_Message(
+      'checkDomainNameEmail',
+      $msg,
+      ts('Complete Setup'),
+      \Psr\Log\LogLevel::WARNING
+    );
+
+    return $messages;
+  }
+
+  /**
+   * Checks if a default bounce handling mailbox is set up
+   * @return array
+   */
+
+  public function checkDefaultMailbox() {
+    $messages = array();
+    $config = CRM_Core_Config::singleton();
+
+    if (in_array('CiviMail', $config->enableComponents) &&
+      CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG"
+    ) {
+      $message = new CRM_Utils_Check_Message(
+        'checkDefaultMailbox',
+        ts('Please configure a default mailbox for CiviMail.',
+          array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1"))),
+        ts('Configure Default Mailbox'),
+        \Psr\Log\LogLevel::WARNING
+      );
+      $message->addHelp(ts('Learn more in the <a href="%1">user guide</a>', array(1 => 'http://book.civicrm.org/user/advanced-configuration/email-system-configuration/')));
+      $messages[] = $message;
+    }
+
+    return $messages;
+  }
 }
index e52c7ccf519170a59a842403a24d9ecc2f2e0dd3..59064da39f7b8862cfaa9f0110e626ca7c9ad4a4 100644 (file)
@@ -54,6 +54,12 @@ class CRM_Utils_Check_Message {
    */
   private $level;
 
+  /**
+   * @var string
+   *   help text (to be presented separately from the message)
+   */
+  private $help;
+
   /**
    * @param string $name
    *   Symbolic name for the check.
@@ -105,21 +111,33 @@ class CRM_Utils_Check_Message {
   /**
    * Alias for Level
    * @return string
-   **/
+   */
   public function getSeverity() {
     return $this->getLevel();
   }
 
+  /**
+   * Set optional additional help text
+   * @param string help
+   */
+  public function addHelp($help) {
+    $this->help = $help;
+  }
+
   /**
    * @return array
    */
   public function toArray() {
-    return array(
+    $array = array(
       'name' => $this->name,
       'message' => $this->message,
       'title' => $this->title,
-      'level' => $this->level,
+      'severity' => $this->level,
     );
+    if (!empty($this->help)) {
+      $array['help'] = $this->help;
+    }
+    return $array;
   }
 
 }
index 43b01fa6062cee5442bfc51c81ca33c8d075bf6d..9ab1c59166c4bc8a1b8261a41f18b76429104374 100644 (file)
@@ -112,7 +112,7 @@ class CRM_Utils_Check_Security {
           $messages[] = new CRM_Utils_Check_Message(
             'checkLogFileIsNotAccessible',
             ts($msg, array(1 => $log_url, 2 => $docs_url)),
-            ts('Security Warning'),
+            ts('Debug Log Downloadable'),
             \Psr\Log\LogLevel::CRITICAL
           );
         }
@@ -160,7 +160,7 @@ class CRM_Utils_Check_Security {
               2 => $privateDir,
               3 => $heuristicUrl,
             )),
-          ts('Security Warning'),
+          ts('Private Files Readable'),
           \Psr\Log\LogLevel::WARNING
         );
       }
@@ -207,7 +207,7 @@ class CRM_Utils_Check_Security {
         $messages[] = new CRM_Utils_Check_Message(
           'checkDirectoriesAreNotBrowseable',
           ts($msg, array(1 => $publicDir, 2 => $publicDir, 3 => $docs_url)),
-          ts('Security Warning'),
+          ts('Browseable Directories'),
           \Psr\Log\LogLevel::ERROR
         );
       }
@@ -256,7 +256,7 @@ class CRM_Utils_Check_Security {
         $messages[] = new CRM_Utils_Check_Message(
           'checkFilesAreNotPresent',
           ts('File \'%1\' presents a security risk and should be deleted.', array(1 => $file)),
-          ts('Security Warning'),
+          ts('Unsafe Files'),
           $file[1]
         );
       }
index 4a097a73ab4d1bf323f5df4f95df783a94dba9a8..6d059b52518354dd1686878925091064a4b62d30 100644 (file)
@@ -3343,33 +3343,6 @@ div.m ul#civicrm-menu,
 #crm-container .crm-fb-tweet-buttons {
   width: 93%;
 }
-#crm-container div.finalconf-button {
-  float: right;
-  padding: 5px 0 0 0;
-}
-#crm-container div.finalconf-button input {
-  margin: 0;
-}
-#crm-container div.finalconf-intro {
-  padding-bottom: 12px;
-  font-style: italic;
-}
-#crm-container h4.finalconf-item {
-  border-top: 1px solid #ccc;
-  padding: 8px 0 8px 10px;
-  margin: 0;
-}
-#crm-container div.finalconf-itemdesc {
-  font-style: italic;
-  padding: 6px 12px 6px 12px;
-  color: #666;
-  float: right;
-  width: 60%;
-}
-#crm-container h4.finalconf-btm {
-  border-bottom: 1px solid #ccc;
-  margin-bottom: 20px;
-}
 
 /* classes related to batch entry operation */
 .crm-container span.batch-edit,
index c653fa44394df4b7163b3f74d0c5b9480eddd722..5469fd14c1c59b6df9c55be853946b8edef0e4ec 100644 (file)
 {include file="CRM/common/dashboard.tpl"}
 {include file="CRM/common/openFlashChart.tpl"}
 {* Alerts for critical configuration settings. *}
-{if ! $fromEmailOK || ! $ownerOrgOK || ! $defaultMailboxOK}
-    <div class="help">
-    <div class="finalconf-intro">
-      {ts}There are a few things to setup before using your site ...{/ts}
-    </div>
-    {if ! $ownerOrgOK}
-        <div class="finalconf-button">
-            <a href="{$fixOrgUrl}" id="fixOrgUrl" class="button"><span><div class="icon ui-icon-wrench"></div>{ts}Go{/ts}</span></a>
-        </div>
-      <div class="finalconf-itemdesc">{ts}Please enter your organization's name and primary address.{/ts}</div>
-      <h4 class="finalconf-item"><div class="icon ui-icon-alert"></div> &nbsp;{ts}Organization Name{/ts}</h4>
-      <div style="clear:both"></div>
-  {/if}
-    {if ! $fromEmailOK}
-        <div class="finalconf-button">
-            <a href="{$fixEmailUrl}" id="fixOrgUrl" class="button"><span><div class="icon ui-icon-wrench"></div>{ts}Go{/ts}</span></a>
-        </div>
-      <div class="finalconf-itemdesc">{ts}Please enter a default FROM Email Address (for system-generated emails).{/ts}</div>
-      <h4 class="finalconf-item"><div class="icon ui-icon-alert"></div> &nbsp;{ts}From Email Address{/ts}</h4>
-      <div style="clear:both"></div>
-    {/if}
-    {if ! $defaultMailboxOK}
-        <div class="finalconf-button">
-            <a href="{$fixDefaultMailbox}" id="fixDefaultMailbox" class="button"><span><div class="icon ui-icon-wrench"></div>{ts}Go{/ts}</span></a>
-        </div>
-        <div class="finalconf-itemdesc">{ts}Please configure a default mailbox for CiviMail.{/ts} (<a href="http://book.civicrm.org/user/advanced-configuration/email-system-configuration/" title="{ts}opens online user guide in a new window{/ts}" target="_blank">{ts}learn more{/ts}</a>)</div>
-        <h4 class="finalconf-item"><div class="icon ui-icon-alert"></div> &nbsp;{ts}Default CiviMail Mailbox{/ts}</h4>
-        <div style="clear:both"></div>
-    {/if}
-    </div>
-{/if}
 {$communityMessages}
 <div class="crm-submit-buttons">
 <a href="#" id="crm-dashboard-configure" class="crm-hover-button show-add">