mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Echo
synced 2024-11-13 17:57:21 +00:00
3513c642dd
Creates a new push-subscription-manager group and an associated right, manage-all-push-subscriptions. The purpose of this is to allow privileged accounts to purge expired subscriptions from the database on behalf of other users. A user with this right will be permitted to delete any subscription from the DB based on the token alone. For all other users, deletion requests will be limited to those associated with the requesting user's central ID. This right will be granted to a bot account on Metawiki associated with the Wikimedia push notifications service, and the push notifications service account will make push subscription delete requests to the API for subscriptions for which vendor APIs return bad subscription responses. Additionally, the providertoken parameter to ApiPushSubscriptionDelete is updated to allow multiple providertoken values. Bug: T259148 Change-Id: Ia6c17588ee94e6be74e5e3a75eb33e38f172fc93
47 lines
1.3 KiB
PHP
47 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace EchoPush;
|
|
|
|
use EchoAttributeManager;
|
|
use EchoEvent;
|
|
use JobQueueGroup;
|
|
use User;
|
|
|
|
class PushNotifier {
|
|
|
|
/**
|
|
* Submits a notification derived from an Echo event to each push notifications service
|
|
* subscription found for a user, via a configured service handler implementation
|
|
* @param User $user
|
|
* @param EchoEvent $event
|
|
*/
|
|
public static function notifyWithPush( User $user, EchoEvent $event ): void {
|
|
$attributeManager = EchoAttributeManager::newFromGlobalVars();
|
|
$userEnabledEvents = $attributeManager->getUserEnabledEvents( $user, 'push' );
|
|
if ( in_array( $event->getType(), $userEnabledEvents ) ) {
|
|
JobQueueGroup::singleton()->push( self::createJob( $user, $event ) );
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param User $user
|
|
* @param EchoEvent|null $event
|
|
* @return NotificationRequestJob
|
|
*/
|
|
private static function createJob( User $user, EchoEvent $event = null ):
|
|
NotificationRequestJob {
|
|
$centralId = Utils::getPushUserId( $user );
|
|
$params = [ 'centralId' => $centralId ];
|
|
// below params are only needed for debug logging (T255068)
|
|
if ( $event !== null ) {
|
|
$params['eventId'] = $event->getId();
|
|
$params['eventType'] = $event->getType();
|
|
if ( $event->getAgent() !== null ) {
|
|
$params['agent'] = $event->getAgent()->getId();
|
|
}
|
|
}
|
|
return new NotificationRequestJob( 'EchoPushNotificationRequest', $params );
|
|
}
|
|
|
|
}
|