Commit 634af702 authored by Alexia's avatar Alexia
Browse files

Move CentralIdLookup to a central file so it is easier to swap out later.

parent 4958b8d6
Pipeline #117338932 failed with stage
in 1 minute and 14 seconds
......@@ -28,7 +28,6 @@
"AutoloadClasses": {
"Reverb\\Api\\ApiNotifications": "includes/api/ApiNotifications.php",
"Reverb\\Hooks": "includes/Hooks.php",
"Reverb\\TwiggyWiring": "includes/TwiggyWiring.php",
"Reverb\\Identifier\\Identifier": "includes/identifier/Identifier.php",
"Reverb\\Identifier\\InvalidIdentifierException": "includes/identifier/InvalidIdentifierException.php",
"Reverb\\Identifier\\SiteIdentifier": "includes/identifier/SiteIdentifier.php",
......@@ -38,7 +37,9 @@
"Reverb\\Notification\\NotificationBundle": "includes/notification/NotificationBundle.php",
"Reverb\\Notification\\NotificationEmail": "includes/notification/NotificationEmail.php",
"Reverb\\Special\\SpecialNotifications": "includes/special/SpecialNotifications.php",
"Reverb\\Traits\\UserContextTrait": "includes/traits/UserContextTrait.php"
"Reverb\\Traits\\UserContextTrait": "includes/traits/UserContextTrait.php",
"Reverb\\TwiggyWiring": "includes/TwiggyWiring.php",
"Reverb\\UserIdHelper": "includes/UserIdHelper.php"
},
"ServiceWiringFiles": [
"includes/ServiceWiring.php"
......
<?php
/**
* Reverb
* User ID Helper
*
* @package Reverb
* @author Alexia E. Smith
* @license MIT
**/
declare(strict_types=1);
namespace Reverb;
use CentralIdLookup;
use User;
class UserIdHelper {
/**
* Get the user ID for this user in the Cheevos service.
*
* @param User $user
*
* @return integer
*/
public static function getUserIdForService(User $user): int {
$lookup = CentralIdLookup::factory();
return $lookup->centralIdFromLocalUser($user, CentralIdLookup::AUDIENCE_RAW);
}
/**
* Get a local User object for this user ID in the Cheevos service.
*
* @param integer $serviceUserId
*
* @return User|null
*/
public static function getUserForServiceUserId(int $serviceUserId): ?User {
$lookup = CentralIdLookup::factory();
return $lookup->localUserFromCentralId($serviceUserId);
}
}
......@@ -147,8 +147,8 @@ class ApiNotifications extends ApiBase {
$success = false;
$lookup = CentralIdLookup::factory();
$globalId = $lookup->centralIdFromLocalUser($this->getUser());
$userIdentifier = Identifier::newUser($globalId);
$serviceUserId = UserIdHelper::getUserIdForService($this->getUser());
$userIdentifier = Identifier::newUser($serviceUserId);
$dismiss = new NotificationDismissalsResource(
[
'target-id' => (string)$userIdentifier
......
......@@ -451,8 +451,8 @@ class Notification {
*/
public static function dismissNotification(User $user, string $id, int $timestamp): bool {
$lookup = CentralIdLookup::factory();
$globalId = $lookup->centralIdFromLocalUser($user);
$userIdentifier = Identifier::newUser($globalId);
$serviceUserId = UserIdHelper::getUserIdForService($user);
$userIdentifier = Identifier::newUser($serviceUserId);
if (!$userIdentifier) {
return false;
}
......
......@@ -19,6 +19,7 @@ use Hydrawiki\Reverb\Client\V1\Exceptions\ApiResponseInvalid;
use MediaWiki\MediaWikiServices;
use MWException;
use Reverb\Identifier\Identifier;
use Reverb\UserIdHelper;
use User;
class NotificationBundle extends ArrayObject {
......@@ -121,16 +122,15 @@ class NotificationBundle extends ArrayObject {
// Make sure the page number is >= 0.
$pageNumber = max(0, $pageNumber);
$lookup = CentralIdLookup::factory();
$globalId = $lookup->centralIdFromLocalUser($user);
$serviceUserId = UserIdHelper::getUserIdForService($user);
$filters = self::validateFilters($filters);
if (!empty($globalId)) {
if (!empty($serviceUserId)) {
$notifications = [];
$client = MediaWikiServices::getInstance()->getService('ReverbApiClient');
$userIdentifier = Identifier::newUser($globalId);
$userIdentifier = Identifier::newUser($serviceUserId);
try {
$notificationTargetResources = $client->notification_targets()->page(
......@@ -140,7 +140,7 @@ class NotificationBundle extends ArrayObject {
array_merge(
$filters,
[
'target-id' => 'hydra:user:' . $globalId
'target-id' => 'hydra:user:' . $serviceUserId
]
)
)->all();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment