Skip to content
Snippets Groups Projects
Commit 6db97d40 authored by Daniel Speicher's avatar Daniel Speicher
Browse files

Issue #3444639: Synchronize Users

parent 3a9ccb83
No related branches found
No related tags found
No related merge requests found
Pipeline #165583 failed
...@@ -26,7 +26,7 @@ class GitLab extends PluginBase { ...@@ -26,7 +26,7 @@ class GitLab extends PluginBase {
use StringTranslationTrait; use StringTranslationTrait;
const PER_PAGE = 100; const int PER_PAGE = 100;
/** /**
* The GitLab client. * The GitLab client.
...@@ -35,20 +35,6 @@ class GitLab extends PluginBase { ...@@ -35,20 +35,6 @@ class GitLab extends PluginBase {
*/ */
private ?Client $adminClient = NULL; private ?Client $adminClient = NULL;
/**
* The client for a specific user.
*
* @var \Gitlab\Client|null
*/
private ?Client $userClient = NULL;
/**
* The current impersonation token.
*
* @var string
*/
private string $currentImpersonationToken;
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -133,9 +119,10 @@ class GitLab extends PluginBase { ...@@ -133,9 +119,10 @@ class GitLab extends PluginBase {
if ($comment['internal']) { if ($comment['internal']) {
continue; continue;
} }
$comment_id = $issue->addComment( $body = $this->filterMarkdownLinks( $comment['body']);
$issue->addComment(
$comment['id'], $comment['id'],
$comment['body'], htmlspecialchars_decode($body),
$user, $user,
strtotime($comment['created_at']), strtotime($comment['created_at']),
strtotime($comment['updated_at']) strtotime($comment['updated_at'])
...@@ -148,6 +135,12 @@ class GitLab extends PluginBase { ...@@ -148,6 +135,12 @@ class GitLab extends PluginBase {
return $issues; return $issues;
} }
private function filterMarkdownLinks(string $text): string {
return preg_replace_callback('/\[(.*?)]\((.*?)\)/', function ($matches) {
return 'Here is an attachment which could not be downloaded.';
}, htmlspecialchars($text));
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -331,11 +324,7 @@ class GitLab extends PluginBase { ...@@ -331,11 +324,7 @@ class GitLab extends PluginBase {
*/ */
private function getUserClient(HelpdeskInterface $helpdesk, int $remoteUserId): Client { private function getUserClient(HelpdeskInterface $helpdesk, int $remoteUserId): Client {
$token = $this->getUserImpersonationToken($helpdesk, $remoteUserId); $token = $this->getUserImpersonationToken($helpdesk, $remoteUserId);
if (!$this->userClient || $this->currentImpersonationToken !== $token) { return $this->doCreateClient($helpdesk, $token);
$this->userClient = $this->doCreateClient($helpdesk, $token);
$this->currentImpersonationToken = $token;
}
return $this->userClient;
} }
/** /**
...@@ -371,7 +360,7 @@ class GitLab extends PluginBase { ...@@ -371,7 +360,7 @@ class GitLab extends PluginBase {
$tokens = $this->getAdminClient($helpdesk)->users() $tokens = $this->getAdminClient($helpdesk)->users()
->userImpersonationTokens($remoteUserId, [ ->userImpersonationTokens($remoteUserId, [
'state' => 'active', 'state' => 'active',
'per_page' => 100, 'per_page' => self::PER_PAGE,
]); ]);
foreach ($tokens as $token) { foreach ($tokens as $token) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment