Skip to content

Commit 78c82a2

Browse files
committed
Merge pull request #71 from zendesk/josemiomiguel/fix_sso_payload
On SSO payload, send user email instead of store email
2 parents d18210c + 3a50c00 commit 78c82a2

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function indexAction()
2828
}
2929

3030
$connection = Mage::helper('zendesk')->getConnectionStatus();
31-
31+
3232
if(!$connection['success']) {
3333
$this->setFlag('', 'no-dispatch', true);
3434
Mage::getSingleton('adminhtml/session')->addError( $connection['msg'] );
@@ -37,7 +37,7 @@ public function indexAction()
3737
}
3838

3939
Mage::helper('zendesk')->storeDependenciesInCachedRegistry();
40-
40+
4141
$this->_title($this->__('Zendesk Dashboard'));
4242
$this->loadLayout();
4343
$this->_setActiveMenu('zendesk/zendesk_dashboard');
@@ -98,7 +98,7 @@ public function authenticateAction()
9898

9999
$user = Mage::getSingleton('admin/session')->getUser();
100100
$name = $user->getName();
101-
$email = Mage::getStoreConfig('zendesk/general/email');
101+
$email = $user->getEmail();
102102
$externalId = $user->getId();
103103

104104
$payload = array(
@@ -107,7 +107,7 @@ public function authenticateAction()
107107
"name" => $name,
108108
"email" => $email
109109
);
110-
110+
111111
// Validate if we need to include external_id param
112112
$externalIdEnabled = Mage::helper('zendesk')->isExternalIdEnabled();
113113
if($externalIdEnabled) {
@@ -118,14 +118,14 @@ public function authenticateAction()
118118

119119
$jwt = JWT::encode($payload, $token);
120120
$return = $return_url ? "&return_to=".$return_url : "";
121-
121+
122122
$url = "https://".$domain."/access/jwt?jwt=" . $jwt . $return;
123123

124124
Mage::log('Admin URL: ' . $url, null, 'zendesk.log');
125125

126126
$this->_redirectUrl($url);
127127
}
128-
128+
129129
/**
130130
* Wrapper for the existing authenticate action. Mirrors the login/logout actions available for customers.
131131
*/
@@ -160,7 +160,7 @@ public function createAction()
160160
if (!$this->_domainConfigured()) {
161161
return;
162162
}
163-
163+
164164
// Check if we have been passed an order ID, in which case we can preload some of the form details
165165
if($orderId = $this->getRequest()->getParam('order_id')) {
166166
$order = Mage::getModel('sales/order')->load($orderId);
@@ -198,9 +198,9 @@ public function launchAction()
198198
if (!$domain) {
199199
return;
200200
}
201-
201+
202202
$sso = Mage::getStoreConfig('zendesk/sso/enabled');
203-
203+
204204
if (!$sso) {
205205
$url = "https://".$domain;
206206
} elseif(Mage::helper('zendesk')->isSSOAdminUsersEnabled()) {
@@ -396,13 +396,13 @@ public function clearLogAction()
396396
}
397397

398398
public function checkOutboundAction()
399-
{
399+
{
400400
$connection = Mage::helper('zendesk')->getConnectionStatus();
401-
401+
402402
$this->getResponse()->clearHeaders()->setHeader('Content-type','application/json', true);
403403
$this->getResponse()->setBody(json_encode($connection));
404-
}
405-
404+
}
405+
406406
/**
407407
* Loading page block
408408
*/
@@ -425,16 +425,16 @@ public function loadBlockAction()
425425
$this->getResponse()->setBody($result);
426426
}
427427
}
428-
428+
429429
public function getUserAction()
430430
{
431431
$request = $this->getRequest();
432432
$id = $request->getParam('id');
433-
433+
434434
$user = Mage::getModel('customer/customer')->load($id);
435-
435+
436436
$this->getResponse()->clearHeaders()->setHeader('Content-type','application/json',true);
437-
437+
438438
if($user->getId()) {
439439
$this->getResponse()->setBody(json_encode(array('success'=>true, 'usr'=> array(
440440
'firstname' => $user->getFirstname(),
@@ -445,14 +445,14 @@ public function getUserAction()
445445
$this->getResponse()->setBody(json_encode(array('success'=>false, 'msg'=>Mage::helper('zendesk')->__('User does not exist'))));
446446
}
447447
}
448-
448+
449449
public function getOrderAction()
450450
{
451451
$request = $this->getRequest();
452452
$id= $request->getParam('id');
453-
453+
454454
$order = Mage::getModel('sales/order')->load($id);
455-
455+
456456
$this->getResponse()->clearHeaders()->setHeader('Content-type','application/json',true);
457457
if($order->getId()) {
458458
$this->getResponse()->setBody(json_encode(array('success'=>true, 'order'=> array(
@@ -462,16 +462,16 @@ public function getOrderAction()
462462
$this->getResponse()->setBody(json_encode(array('success'=>false, 'msg'=>Mage::helper('zendesk')->__('Order does not exist'))));
463463
}
464464
}
465-
465+
466466
public function syncAction()
467467
{
468468
$this->getResponse()->clearHeaders()->setHeader('Content-type','application/json',true);
469469
Mage::log('Synchronization started', null, 'zendesk.log');
470-
try {
470+
try {
471471
$user = Mage::getModel('zendesk/api_users')->all();
472472
if (is_null($user))
473473
throw new Exception("Connection Failed");
474-
474+
475475
$data = array();
476476
$data[] = array(
477477
'user_field' => array(
@@ -539,14 +539,14 @@ public function syncAction()
539539
if (!isset($response['active']) || $response['active'] === false)
540540
Mage::log('Unable to create User Field with key '.$field['user_field']['key'], null, 'zendesk.log');
541541
}
542-
542+
543543
$customers = Mage::getModel('customer/customer')->getCollection();
544544
$customers->addAttributeToSelect(array('firstname', 'lastname', 'email'));
545545
foreach($customers as $customer) {
546546
Mage::log('Synchronizing customer with id '.$customer->getId(), null, 'zendesk.log');
547547
Mage::dispatchEvent('customer_save_commit_after', array('customer' => $customer));
548548
}
549-
549+
550550
} catch (Exception $ex) {
551551
Mage::log('Synchronization failed: '.$ex->getMessage(), null, 'zendesk.log');
552552
$this->getResponse()->setBody(json_encode(array('success'=>false, 'msg'=>Mage::helper('zendesk')->__('Synchronization failed: ').$ex->getMessage())));
@@ -568,12 +568,12 @@ public function bulkDeleteAction()
568568
}
569569
$this->_redirectReferer();
570570
}
571-
571+
572572
public function bulkChangeStatusAction()
573573
{
574574
$ids = $this->getRequest()->getParam('id');
575575
$status = $this->getRequest()->getParam('status');
576-
576+
577577
try {
578578
$response = Mage::getModel('zendesk/api_tickets')->updateMany($ids, compact('status'));
579579
$this->getMassActionResponse($response, $ids);
@@ -582,12 +582,12 @@ public function bulkChangeStatusAction()
582582
}
583583
$this->_redirect('adminhtml/zendesk/');
584584
}
585-
585+
586586
public function bulkChangePriorityAction()
587587
{
588588
$ids = $this->getRequest()->getParam('id');
589589
$priority = $this->getRequest()->getParam('priority');
590-
590+
591591
try {
592592
$response = Mage::getModel('zendesk/api_tickets')->updateMany($ids, compact('priority'));
593593
$this->getMassActionResponse($response, $ids);
@@ -596,12 +596,12 @@ public function bulkChangePriorityAction()
596596
}
597597
$this->_redirect('adminhtml/zendesk/');
598598
}
599-
599+
600600
public function bulkChangeTypeAction()
601601
{
602602
$ids = $this->getRequest()->getParam('id');
603603
$type = $this->getRequest()->getParam('type');
604-
604+
605605
try {
606606
$response = Mage::getModel('zendesk/api_tickets')->updateMany($ids, compact('type'));
607607
$this->getMassActionResponse($response, $ids);
@@ -610,11 +610,11 @@ public function bulkChangeTypeAction()
610610
}
611611
$this->_redirect('adminhtml/zendesk/');
612612
}
613-
613+
614614
public function bulkMarkSpamAction()
615615
{
616616
$ids = $this->getRequest()->getParam('id');
617-
617+
618618
try {
619619
$response = Mage::getModel('zendesk/api_tickets')->bulkMarkAsSpam($ids);
620620
$message = '%d out of %d ticket(s) were marked as spam.';
@@ -627,34 +627,34 @@ public function bulkMarkSpamAction()
627627

628628
public function ticketsAllAction() {
629629
$isAjax = Mage::app()->getRequest()->isAjax();
630-
630+
631631
if ($isAjax) {
632632
Mage::helper('zendesk')->storeDependenciesInCachedRegistry();
633633
$this->getResponse()->setBody($this->getLayout()->createBlock('zendesk/adminhtml_dashboard_tab_tickets_grid_all')->toHtml());
634634
}
635635
}
636-
636+
637637
public function ticketsViewAction() {
638638
$isAjax = Mage::app()->getRequest()->isAjax();
639639

640640
if ($isAjax) {
641641
Mage::helper('zendesk')->storeDependenciesInCachedRegistry();
642642
$viewId = (int) $this->getRequest()->getParam('viewid');
643643
Mage::register('zendesk_tickets_view', $viewId);
644-
644+
645645
$this->getResponse()->setBody($this->getLayout()->createBlock('zendesk/adminhtml_dashboard_tab_tickets_grid_view')->toHtml());
646646
}
647647
}
648-
648+
649649
protected function getMassActionResponse($response, $ids, $message = '%d out of %d ticket(s) were updated.')
650650
{
651651
if (isset($response['job_status']) && isset($response['job_status']['url'])) {
652652
$job_status = Mage::getModel('zendesk/api_tickets')->getJobStatus($response['job_status']['url']);
653-
653+
654654
$parsed = array();
655655
$parsed['errors'] = array();
656656
$parsed['success'] = 0;
657-
657+
658658
if (isset($job_status['job_status']['results'])) {
659659
foreach ($job_status['job_status']['results'] as $result) {
660660
if ($result['success']) {
@@ -669,8 +669,8 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
669669

670670
Mage::getSingleton('adminhtml/session')->addSuccess(
671671
Mage::helper('zendesk')->__(
672-
$message,
673-
$parsed['success'],
672+
$message,
673+
$parsed['success'],
674674
count($ids)
675675
)
676676
);
@@ -688,7 +688,7 @@ protected function getMassActionResponse($response, $ids, $message = '%d out of
688688
);
689689
}
690690
}
691-
691+
692692
private function _domainConfigured()
693693
{
694694
$domain = Mage::getStoreConfig('zendesk/general/domain');

0 commit comments

Comments
 (0)