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 {
use StringTranslationTrait;
const PER_PAGE = 100;
const int PER_PAGE = 100;
/**
* The GitLab client.
......@@ -35,20 +35,6 @@ class GitLab extends PluginBase {
*/
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}
*/
......@@ -133,9 +119,10 @@ class GitLab extends PluginBase {
if ($comment['internal']) {
continue;
}
$comment_id = $issue->addComment(
$body = $this->filterMarkdownLinks( $comment['body']);
$issue->addComment(
$comment['id'],
$comment['body'],
htmlspecialchars_decode($body),
$user,
strtotime($comment['created_at']),
strtotime($comment['updated_at'])
......@@ -148,6 +135,12 @@ class GitLab extends PluginBase {
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}
*/
......@@ -331,11 +324,7 @@ class GitLab extends PluginBase {
*/
private function getUserClient(HelpdeskInterface $helpdesk, int $remoteUserId): Client {
$token = $this->getUserImpersonationToken($helpdesk, $remoteUserId);
if (!$this->userClient || $this->currentImpersonationToken !== $token) {
$this->userClient = $this->doCreateClient($helpdesk, $token);
$this->currentImpersonationToken = $token;
}
return $this->userClient;
return $this->doCreateClient($helpdesk, $token);
}
/**
......@@ -371,7 +360,7 @@ class GitLab extends PluginBase {
$tokens = $this->getAdminClient($helpdesk)->users()
->userImpersonationTokens($remoteUserId, [
'state' => 'active',
'per_page' => 100,
'per_page' => self::PER_PAGE,
]);
foreach ($tokens as $token) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment