Skip to content

Commit 8681f17

Browse files
committed
Merge pull request #82 from zendesk/jose/MI-174-acl-patch
[MI-174] ACL Patch
2 parents 59428b0 + 933ae85 commit 8681f17

File tree

9 files changed

+114
-23
lines changed

9 files changed

+114
-23
lines changed

src/app/code/community/Zendesk/Zendesk/Block/Adminhtml/Dashboard/Tab/Tickets/Grid/Abstract.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ protected function _prepareCollection() {
9090
protected function _prepareMassaction() {
9191
parent::_prepareMassaction();
9292

93+
// Disable mass actions if not allowed for the current user's role
94+
if ( ! Mage::getSingleton('admin/session')->isAllowed('zendesk/zendesk_dashboard/bulk_actions')) {
95+
return;
96+
}
97+
9398
$this->setMassactionIdField('id');
9499
$this->getMassactionBlock()->setFormFieldName('id');
95100

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ public function __construct()
2727
public function isAllowed($target)
2828
{
2929
try {
30-
return Mage::getSingleton('admin/session')->isAllowed('admin/zendesk/zendesk_' . $target);
30+
if ($target == 'settings') {
31+
return Mage::getSingleton('admin/session')->isAllowed('admin/system/config/zendesk');
32+
} else {
33+
return Mage::getSingleton('admin/session')->isAllowed('admin/zendesk/zendesk_' . $target);
34+
}
3135
} catch (Exception $e) {
3236
return false;
3337
}

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 && $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/Api/Tickets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,4 @@ public function create($data)
191191
return $response['ticket'];
192192
}
193193

194-
}
194+
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public function all()
5656
$page = 1;
5757
$users = array();
5858

59-
while($page) {
60-
$response = $this->_call('users.json?page=' . $page);
59+
while($page && $response = $this->_call('users.json?page=' . $page)) {
6160
$users = array_merge($users, $response['users']);
6261
$page = is_null($response['next_page']) ? 0 : $page + 1;
6362
}
@@ -109,6 +108,11 @@ public function create($user)
109108
public function createUserField($field)
110109
{
111110
$response = $this->_call('user_fields.json', null, 'POST', $field, true);
111+
112+
if(!isset($response['user_field'])) {
113+
throw new Exception('No User Field specified.');
114+
}
115+
112116
return $response['user_field'];
113117
}
114-
}
118+
}

src/app/code/community/Zendesk/Zendesk/Model/Resource/Tickets/Collection.php

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,24 @@ public function addFieldToFilter($fieldName, $condition = null) {
3535
switch($fieldName) {
3636
case 'subject':
3737
$searchFields[] = array(
38-
'field' => 'subject',
39-
'value' => '"'.$condition.'"'
38+
'field' => 'subject',
39+
'value' => '"'.$condition.'"'
4040
);
4141
break;
4242
case 'requester':
4343
case 'requester_id':
44-
$value = is_numeric($condition) ? $condition : '*' . $condition . '*';
44+
if (is_array($condition)) {
45+
break;
46+
}
47+
48+
$searchFields[] = array(
49+
'field' => 'requester',
50+
'value' => '*' . $condition,
51+
);
52+
4553
$searchFields[] = array(
46-
'field' => 'requester',
47-
'value' => $value
54+
'field' => 'requester',
55+
'value' => $condition . '*',
4856
);
4957
break;
5058
case 'tags':
@@ -54,14 +62,14 @@ public function addFieldToFilter($fieldName, $condition = null) {
5462
case 'group':
5563
case 'assignee':
5664
$searchFields[] = array(
57-
'field' => $fieldName,
58-
'value' => $condition
65+
'field' => $fieldName,
66+
'value' => $condition
5967
);
6068
break;
6169
case 'type':
6270
$searchFields[] = array(
63-
'field' => 'ticket_type',
64-
'value' => $condition
71+
'field' => 'ticket_type',
72+
'value' => $condition
6573
);
6674
break;
6775
case 'id':

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

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,64 @@
1919

2020
class Zendesk_Zendesk_Adminhtml_ZendeskController extends Mage_Adminhtml_Controller_Action
2121
{
22-
protected $_publicActions = array('redirect', 'logout');
22+
protected $_publicActions = array('redirect', 'logout', 'authenticate', 'login');
23+
24+
protected function _isAllowed()
25+
{
26+
$action = strtolower($this->getRequest()->getActionName());
27+
28+
// Disable ACL check for public actions
29+
if (in_array($action, $this->_publicActions)) {
30+
return true;
31+
}
32+
33+
switch ($action) {
34+
case 'launch':
35+
$aclAction = 'launch';
36+
break;
37+
// When users have access to the zendesk_dashboard they must also be able to access the viewing actions on this controller
38+
case 'index':
39+
case 'ticketsall':
40+
case 'ticketsview':
41+
$aclAction = 'dashboard';
42+
break;
43+
// User must have bulk_actions permission
44+
case 'bulkchangepriority':
45+
case 'bulkchangestatus':
46+
case 'bulkchangetype':
47+
case 'bulkdelete':
48+
case 'bulkmarkspam':
49+
$aclAction = 'dashboard/bulk_actions';
50+
break;
51+
// Actions accessible to roles with the zendesk_create permission
52+
case 'autocomplete':
53+
case 'create':
54+
case 'getorder':
55+
case 'getuser':
56+
case 'loadblock':
57+
case 'save':
58+
$aclAction = 'create';
59+
break;
60+
// Configuration actions, role must have Configuration > Zendesk permissions
61+
case 'checkoutbound':
62+
case 'clearlog';
63+
case 'configuration':
64+
case 'generate':
65+
case 'sync':
66+
$aclAction = 'settings';
67+
break;
68+
default:
69+
return false;
70+
}
71+
72+
$acl = "zendesk/zendesk_$aclAction";
73+
74+
if ($acl == 'zendesk/zendesk_settings') {
75+
$acl = 'admin/system/config/zendesk';
76+
}
77+
78+
return Mage::getSingleton('admin/session')->isAllowed($acl);
79+
}
2380

2481
public function indexAction()
2582
{
@@ -402,7 +459,7 @@ public function checkOutboundAction()
402459

403460
$this->getResponse()->clearHeaders()->setHeader('Content-type','application/json', true);
404461
$this->getResponse()->setBody(json_encode($connection));
405-
}
462+
}
406463

407464
/**
408465
* Loading page block

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,12 @@
202202
<action>adminhtml/zendesk/launch</action>
203203
<sort_order>3</sort_order>
204204
</zendesk_launch>
205-
<zendesk_configurations module="zendesk">
205+
<zendesk_configuration module="zendesk">
206+
<resource>system/config/zendesk</resource>
206207
<title>Configuration</title>
207208
<action>adminhtml/system_config/edit/section/zendesk</action>
208209
<sort_order>4</sort_order>
209-
</zendesk_configurations>
210+
</zendesk_configuration>
210211
<zendesk_log module="zendesk">
211212
<title>Log Viewer</title>
212213
<action>adminhtml/zendesk/log</action>
@@ -225,6 +226,12 @@
225226
<zendesk_dashboard translate="title" module="zendesk">
226227
<title>Dashboard</title>
227228
<sort_order>1</sort_order>
229+
<children>
230+
<bulk_actions>
231+
<title>Bulk Actions</title>
232+
<sort_order>1</sort_order>
233+
</bulk_actions>
234+
</children>
228235
</zendesk_dashboard>
229236
<zendesk_create translate="title" module="zendesk">
230237
<title>Create Ticket</title>
@@ -234,10 +241,10 @@
234241
<title>Launch Zendesk</title>
235242
<sort_order>3</sort_order>
236243
</zendesk_launch>
237-
<zendesk_settings translate="title" module="zendesk">
238-
<title>Settings</title>
244+
<zendesk_log>
245+
<title>View Logs</title>
239246
<sort_order>4</sort_order>
240-
</zendesk_settings>
247+
</zendesk_log>
241248
</children>
242249
</zendesk>
243250
<system>

src/app/design/adminhtml/default/default/template/zendesk/left-menu.phtml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
<span><?php echo $this->__('Configuration'); ?></span>
4545
</a>
4646
</li>
47+
<?php } ?>
48+
<?php if ($this->isAllowed('log')) { ?>
49+
<li>
50+
<a href="<?php echo $this->getUrl('adminhtml/zendesk/log'); ?>" class="tab-item-link">
51+
<span><?php echo $this->__('Log Viewer'); ?></span>
52+
</a>
53+
</li>
4754
<?php } ?>
4855
</ul>
4956

0 commit comments

Comments
 (0)