Commit 58d94909 authored by Alexia's avatar Alexia
Browse files

Merge branch 'feature/replace-global-id-usage-with-user-id' into 'master'

Resolve "Replace global ID usage with user ID."

Closes #174

See merge request !136
parents 4958b8d6 e107c9be
Pipeline #117685380 passed with stage
in 1 minute and 21 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"
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Samuel Hilson
* @license GPL-2.0-or-later
**/
*/
$specialPageAliases = [];
......
......@@ -7,7 +7,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license MIT
**/
*/
declare(strict_types=1);
......
......@@ -6,14 +6,14 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
use Http\Discovery\HttpClientDiscovery;
use Http\Discovery\MessageFactoryDiscovery;
use MediaWiki\MediaWikiServices;
use Hydrawiki\Reverb\Client\V1\ClientFactory;
use MediaWiki\MediaWikiServices;
return [
'ReverbApiClient' => function (MediaWikiServices $services) {
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Samuel Hilson
* @license GPL-2.0-or-later
**/
*/
namespace Reverb;
......
<?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 Reverb 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 Reverb service.
*
* @param integer $serviceUserId
*
* @return User|null
*/
public static function getUserForServiceUserId(int $serviceUserId): ?User {
$lookup = CentralIdLookup::factory();
return $lookup->localUserFromCentralId($serviceUserId);
}
}
......@@ -6,20 +6,20 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
namespace Reverb\Api;
use ApiBase;
use CentralIdLookup;
use Hydrawiki\Reverb\Client\V1\Resources\NotificationDismissals as NotificationDismissalsResource;
use MediaWiki\MediaWikiServices;
use Reverb\Identifier\Identifier;
use Reverb\Notification\Notification;
use Reverb\Notification\NotificationBroadcast;
use Reverb\Notification\NotificationBundle;
use Reverb\UserIdHelper;
class ApiNotifications extends ApiBase {
/**
......@@ -146,9 +146,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
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
......
......@@ -6,13 +6,12 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
namespace Reverb\Notification;
use CentralIdLookup;
use DynamicSettings\Wiki;
use Exception;
use Hydrawiki\Reverb\Client\V1\Exceptions\ApiRequestUnsuccessful as ApiRequestUnsuccessful;
......@@ -27,6 +26,7 @@ use Reverb\Identifier\SiteIdentifier;
use Reverb\Identifier\UserIdentifier;
use Reverb\Traits\NotificationListTrait;
use Reverb\Traits\UserContextTrait;
use Reverb\UserIdHelper;
use Title;
use User;
......@@ -295,8 +295,7 @@ class Notification {
public function getAgent(): ?User {
$id = $this->getAgentId();
if ($id !== null) {
$lookup = CentralIdLookup::factory();
$user = $lookup->localUserFromCentralId($id->whoAmI());
$user = UserIdHelper::getUserForServiceUserId(intval($id->whoAmI()));
if ($user !== null) {
return $user;
}
......@@ -450,9 +449,8 @@ class Notification {
* @return null
*/
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;
}
......
......@@ -6,13 +6,12 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
namespace Reverb\Notification;
use CentralIdLookup;
use Hydrawiki\Reverb\Client\V1\Exceptions\ApiRequestUnsuccessful;
use Hydrawiki\Reverb\Client\V1\Resources\NotificationBroadcast as NotificationBroadcastResource;
use MediaWiki\MediaWikiServices;
......@@ -288,8 +287,7 @@ class NotificationBroadcast {
throw new MWException('Invalid agent passed.');
}
$lookup = CentralIdLookup::factory();
$agentGlobalId = $lookup->centralIdFromLocalUser($agent);
$agentGlobalId = UserIdHelper::getUserIdForService($agent);
if (empty($agentGlobalId)) {
return false;
......@@ -317,15 +315,13 @@ class NotificationBroadcast {
* @return void
*/
protected function setTargets(array $targets) {
$lookup = CentralIdLookup::factory();
$targetIdentifiers = [];
foreach ($targets as $key => $target) {
if (!($target instanceof User)) {
throw new MWException('Invalid target passed.');
}
$targetGlobalId = $lookup->centralIdFromLocalUser($target);
$targetGlobalId = UserIdHelper::getUserIdForService($target);
if (!$targetGlobalId) {
unset($targets[$key]);
continue;
......
......@@ -6,19 +6,19 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
namespace Reverb\Notification;
use ArrayObject;
use CentralIdLookup;
use Exception;
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 +121,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 +139,7 @@ class NotificationBundle extends ArrayObject {
array_merge(
$filters,
[
'target-id' => 'hydra:user:' . $globalId
'target-id' => 'hydra:user:' . $serviceUserId
]
)
)->all();
......
......@@ -6,15 +6,15 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
namespace Reverb\Notification;
use Hydrawiki\Reverb\Client\V1\Resources\Notification as NotificationResource;
use MediaWiki\MediaWikiServices;
use MailAddress;
use MediaWiki\MediaWikiServices;
use Reverb\Traits\NotificationListTrait;
use Reverb\TwiggyWiring;
use SpecialPage;
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
declare(strict_types=1);
......
......@@ -6,13 +6,13 @@
* @package Reverb
* @author Samuel Hilson
* @license GPL-2.0-or-later
**/
*/
namespace Reverb\Traits;
use User;
use GlobalVarConfig;
use MediaWiki\MediaWikiServices;
use User;
trait NotificationListTrait {
/**
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license GPL-2.0-or-later
**/
*/
namespace Reverb\Traits;
......
......@@ -6,7 +6,7 @@
* @package Reverb
* @author Alexia E. Smith
* @license MIT
**/
*/
namespace Reverb\Maintenance;
......
......@@ -9,8 +9,8 @@
namespace Tests\Unit\Includes\Notification;
use Reverb\Notification\Notification;
use Hydrawiki\Reverb\Client\V1\Resources\Notification as NotificationResource;
use Reverb\Notification\Notification;
use Tests\TestCase;
class NotificationTest extends TestCase {
......
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