Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Z
Zendesk - Drupal 9
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Packages
Packages
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sumesh S
Zendesk - Drupal 9
Commits
7f25700d
Commit
7f25700d
authored
Nov 03, 2021
by
Sumesh S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
D9 Upgrade: Minor fixes
parent
c611c0ea
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
9 deletions
+25
-9
src/Utils/ZendeskHelper.php
src/Utils/ZendeskHelper.php
+5
-5
zendesk_users/src/ZendeskUsers.php
zendesk_users/src/ZendeskUsers.php
+19
-3
zendesk_users/zendesk_users.services.yml
zendesk_users/zendesk_users.services.yml
+1
-1
No files found.
src/Utils/ZendeskHelper.php
View file @
7f25700d
...
...
@@ -20,18 +20,18 @@ class ZendeskHelper {
* @return string
* A signed JWT.
*/
public
function
jwtEncode
(
$payload
,
$key
)
{
public
static
function
jwtEncode
(
$payload
,
$key
)
{
$header
=
[
'typ'
=>
'JWT'
,
'alg'
=>
'HS256'
,
];
$segments
=
[];
$segments
[]
=
$this
->
urlSafeB64Encode
(
json_encode
(
$header
));
$segments
[]
=
$this
->
urlSafeB64Encode
(
json_encode
(
$payload
));
$segments
[]
=
self
::
urlSafeB64Encode
(
json_encode
(
$header
));
$segments
[]
=
self
::
urlSafeB64Encode
(
json_encode
(
$payload
));
$signing_input
=
implode
(
'.'
,
$segments
);
$signature
=
hash_hmac
(
'sha256'
,
$signing_input
,
$key
,
TRUE
);
$segments
[]
=
$this
->
urlSafeB64Encode
(
$signature
);
$segments
[]
=
self
::
urlSafeB64Encode
(
$signature
);
return
implode
(
'.'
,
$segments
);
...
...
@@ -51,7 +51,7 @@ class ZendeskHelper {
* @return string
* The encoded string.
*/
public
function
urlSafeB64Encode
(
$data
)
{
public
static
function
urlSafeB64Encode
(
$data
)
{
$b64
=
base64_encode
(
$data
);
return
str_replace
([
'+'
,
'/'
,
'\r'
,
'\n'
,
'='
],
[
'-'
,
'_'
],
$b64
);
...
...
zendesk_users/src/ZendeskUsers.php
View file @
7f25700d
...
...
@@ -138,7 +138,12 @@ class ZendeskUsers {
*/
public
function
syncUserBack
(
AccountInterface
$account
)
{
// Look for the user.
$result
=
$this
->
zendeskClient
->
users
()
->
search
(
$account
->
getEmail
());
$result
=
$this
->
zendeskClient
->
users
()
->
search
([
'query'
=>
$account
->
getEmail
()]);
if
(
empty
(
$result
->
users
))
{
$result
=
$this
->
zendeskClient
->
users
()
->
search
([
'query'
=>
$account
->
getDisplayName
()]);
}
if
(
isset
(
$result
->
users
[
0
]
->
id
))
{
$this
->
database
->
insert
(
'zendesk_users'
)
->
fields
([
...
...
@@ -158,14 +163,25 @@ class ZendeskUsers {
* Updates the user data on zendesk.
*/
public
function
updateUser
(
AccountInterface
$account
)
{
if
(
$this
->
config
->
get
(
'zendesk_api_sync_users'
)
&&
$this
->
hasAccess
(
$account
))
{
if
(
$user_id
=
$this
->
getZendeskUserId
(
$account
->
id
()))
{
$data
=
[
'id'
=>
$user_id
,
'name'
=>
$account
->
getDisplayName
(),
'email'
=>
$account
->
getEmail
(),
'role'
=>
'end-user'
,
];
// Invoke a alter call to allow other modules to pass data to ZenDesk.
$this
->
moduleHandler
->
alter
([
'zendesk_user'
,
'zendesk_user_update'
],
$data
,
$account
);
// Make the call.
$this
->
zendeskClient
->
users
()
->
update
(
$user_id
,
$data
);
}
elseif
(
$user_id
=
$this
->
syncUserBack
(
$account
))
{
$data
=
[
'id'
=>
$user_id
,
'name'
=>
$account
->
getDisplayName
(),
'email'
=>
$account
->
getEmail
(),
];
// Invoke a alter call to allow other modules to pass data to ZenDesk.
...
...
zendesk_users/zendesk_users.services.yml
View file @
7f25700d
services
:
zendesk_user.manager
:
class
:
\Drupal\zendesk_users\ZendeskUser
class
:
\Drupal\zendesk_users\ZendeskUser
s
arguments
:
[
'
@database'
,
'
@module_handler'
,
'
@config.factory'
,
'
@logger.channel.zendesk'
]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment