Skip to content

Commit 9978fea

Browse files
committed
Merge pull request #98 from zendesk/jose/MI-100-connection-status
[MI-100] Check connection status before loading the grid
2 parents 2b4c6f9 + 6be69d6 commit 9978fea

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public function getAuthHeader() {
3131
return 'Token token="' . Mage::helper('zendesk')->getApiToken(false) . '"';
3232
}
3333

34-
public function isConnected() {
35-
$connection = Mage::helper('zendesk')->getConnectionStatus();
36-
return $connection['success'];
37-
}
38-
3934
public function getTotals() {
4035
return Mage::helper("zendesk")->getTicketTotals();
4136
}

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Grids.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct() {
2929
protected function _prepareLayout() {
3030
// Check if we are on the main admin dashboard and, if so, whether we should be showing the grid
3131
// Note: an additional check in the template is needed, but this will prevent unnecessary API calls to Zendesk
32-
if ( !$this->getIsZendeskDashboard() && !Mage::getStoreConfig('zendesk/backend_features/show_on_dashboard') )
32+
if ( !Mage::helper('zendesk')->isConnected() || (!$this->getIsZendeskDashboard() && !Mage::getStoreConfig('zendesk/backend_features/show_on_dashboard')) )
3333
{
3434
return parent::_prepareLayout();
3535
}

src/app/code/community/Zendesk/Zendesk/Helper/Data.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,17 @@ public function getConnectionStatus() {
391391
);
392392
}
393393
}
394-
394+
395+
/**
396+
* Checks if the current connection details are valid.
397+
*
398+
* @return boolean
399+
*/
400+
public function isConnected() {
401+
$connection = $this->getConnectionStatus();
402+
return $connection['success'];
403+
}
404+
395405
public function storeDependenciesInCachedRegistry() {
396406
$cache = Mage::app()->getCache();
397407

src/app/code/community/Zendesk/Zendesk/controllers/Adminhtml/ZendeskController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ public function createAction()
252252

253253
public function launchAction()
254254
{
255-
$domain = $this->_domainConfigured();
256-
if (!$domain) {
255+
if (!$this->_domainConfigured()) {
257256
return;
258257
}
259258

259+
$domain = Mage::getStoreConfig('zendesk/general/domain');
260+
260261
$sso = Mage::getStoreConfig('zendesk/sso/enabled');
261262

262263
if (!$sso) {
@@ -749,13 +750,12 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
749750

750751
private function _domainConfigured()
751752
{
752-
$domain = Mage::getStoreConfig('zendesk/general/domain');
753-
if(!$domain) {
754-
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
753+
if (!Mage::helper('zendesk')->isConnected()) {
754+
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up a Zendesk connection.'));
755755
$this->_redirect('adminhtml/dashboard');
756756
return false;
757757
} else {
758-
return $domain;
758+
return true;
759759
}
760760
}
761761

src/app/design/adminhtml/default/default/template/zendesk/dashboard/index.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* limitations under the License.
1616
*/
1717
?>
18-
<?php if( $this->isConnected() ): ?>
18+
<?php if( Mage::helper('zendesk')->isConnected() ): ?>
1919
<?php if ($this->getIsZendeskDashboard() || Mage::getStoreConfig('zendesk/backend_features/show_on_dashboard')): ?>
2020
<?php if ($this->getIsZendeskDashboard()): ?>
2121
<div class="content-header">

0 commit comments

Comments
 (0)