Skip to content

Commit dd1ff9c

Browse files
committed
Save authenticated flag to the database.
Do not display Create Ticket and Dashboard/Grid if the extension is not setup properly.
1 parent 234e13d commit dd1ff9c

File tree

8 files changed

+41
-9
lines changed

8 files changed

+41
-9
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public function getAuthHeader() {
3232
}
3333

3434
public function isConnected() {
35-
$connection = Mage::helper('zendesk')->getConnectionStatus();
36-
return $connection['success'];
35+
return Mage::getStoreConfig('zendesk/general/authenticated');
3736
}
3837

3938
public function getTotals() {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ 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') )
33-
{
32+
if (!Mage::getStoreConfig('zendesk/general/authenticated')
33+
|| (!$this->getIsZendeskDashboard() && !Mage::getStoreConfig('zendesk/backend_features/show_on_dashboard'))
34+
) {
3435
return parent::_prepareLayout();
3536
}
3637

src/app/code/community/Zendesk/Zendesk/Model/Api/SupportAddresses.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public function all()
77
$page = 1;
88
$addresses = array();
99

10-
while ($page) {
11-
$response = $this->_call('recipient_addresses.json?page=' . $page);
10+
while ($page && !empty($response = $this->_call('recipient_addresses.json?page=' . $page))) {
1211
$addresses = array_merge($addresses, $response['recipient_addresses']);
1312
$page = is_null($response['next_page']) ? 0 : $page + 1;
1413
}

src/app/code/community/Zendesk/Zendesk/Model/Observer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ public function saveConfig(Varien_Event_Observer $observer)
114114
} elseif (empty($zDomain)) {
115115
Mage::getModel('core/config')->saveConfig('zendesk/frontend_features/web_widget_code_snippet', '');
116116
}
117+
118+
// Save the connection status, used to check if it's okay to load pages that calls the API
119+
$connectionStatus = Mage::helper('zendesk')->getConnectionStatus();
120+
Mage::getModel('core/config')->saveConfig('zendesk/general/authenticated', (int) $connectionStatus['success'], $scope, $scopeId);
117121
}
118122

119123
public function addTicketButton(Varien_Event_Observer $event)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,9 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
691691

692692
private function _domainConfigured()
693693
{
694-
$domain = Mage::getStoreConfig('zendesk/general/domain');
695-
if(!$domain) {
694+
$authenticated = Mage::getStoreConfig('zendesk/general/authenticated');
695+
696+
if(!$authenticated) {
696697
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('zendesk')->__('Please set up Zendesk connection.'));
697698
$this->_redirect('adminhtml/dashboard');
698699
return false;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
/**
3+
* Copyright 2015 Zendesk
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
$connectionStatus = Mage::helper('zendesk')->getConnectionStatus();
19+
$config = new Mage_Core_Model_Config();
20+
$config->saveConfig('zendesk/general/authenticated', (int) $connectionStatus['success'], 'default', 0);

src/app/code/community/Zendesk/Zendesk/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<config>
2020
<modules>
2121
<Zendesk_Zendesk>
22-
<version>2.0.6</version>
22+
<version>2.0.7</version>
2323
</Zendesk_Zendesk>
2424
</modules>
2525
<zendesk>

src/app/code/community/Zendesk/Zendesk/etc/system.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@
110110
<show_in_store>1</show_in_store>
111111
<comment><![CDATA[Only if customers synchronization is enabled ]]></comment>
112112
</sync_now>
113+
<authenticated>
114+
<frontend_type>hidden</frontend_type>
115+
<source_model>adminhtml/system_config_source_yesno</source_model>
116+
<sort_order>1</sort_order>
117+
<show_in_default>0</show_in_default>
118+
<show_in_website>0</show_in_website>
119+
<show_in_store>0</show_in_store>
120+
</authenticated>
113121
</fields>
114122
</general>
115123
<sso translate="label comment">

0 commit comments

Comments
 (0)