Merge "Make notifyAgent a per-type property rather than per-event"

This commit is contained in:
jenkins-bot 2018-11-02 15:09:19 +00:00 committed by Gerrit Code Review
commit 92ed4e312c
9 changed files with 38 additions and 42 deletions

View file

@ -684,6 +684,7 @@
"user-locators": [ "user-locators": [
"EchoUserLocator::locateEventAgent" "EchoUserLocator::locateEventAgent"
], ],
"canNotifyAgent": true,
"category": "system", "category": "system",
"group": "positive", "group": "positive",
"section": "message", "section": "message",
@ -769,6 +770,7 @@
"EchoUserLocator::locateEventAgent" "EchoUserLocator::locateEventAgent"
] ]
], ],
"canNotifyAgent": true,
"category": "mention-failure", "category": "mention-failure",
"bundle": { "bundle": {
"web": true, "web": true,
@ -784,6 +786,7 @@
"EchoUserLocator::locateEventAgent" "EchoUserLocator::locateEventAgent"
] ]
], ],
"canNotifyAgent": true,
"category": "mention-failure", "category": "mention-failure",
"group": "negative", "group": "negative",
"section": "alert", "section": "alert",
@ -795,6 +798,7 @@
"EchoUserLocator::locateEventAgent" "EchoUserLocator::locateEventAgent"
] ]
], ],
"canNotifyAgent": true,
"category": "mention-success", "category": "mention-success",
"bundle": { "bundle": {
"web": true, "web": true,
@ -845,6 +849,7 @@
"user-locators": [ "user-locators": [
"EchoUserLocator::locateEventAgent" "EchoUserLocator::locateEventAgent"
], ],
"canNotifyAgent": true,
"category": "system", "category": "system",
"notify-type-availability": { "notify-type-availability": {
"email": false "email": false
@ -857,6 +862,7 @@
"user-locators": [ "user-locators": [
"EchoUserLocator::locateEventAgent" "EchoUserLocator::locateEventAgent"
], ],
"canNotifyAgent": true,
"category": "article-reminder", "category": "article-reminder",
"group": "positive", "group": "positive",
"presentation-model": "EchoArticleReminderPresentationModel", "presentation-model": "EchoArticleReminderPresentationModel",

View file

@ -374,4 +374,19 @@ class EchoAttributeManager {
return 'alert'; return 'alert';
} }
/**
* Get notification types that allow their own agent to be notified.
*
* @return string[] Notification types
*/
public function getNotifyAgentEvents() {
$events = [];
foreach ( $this->notifications as $event => $attribs ) {
if ( $attribs['canNotifyAgent'] ?? false ) {
$events[] = $event;
}
}
return $events;
}
} }

View file

@ -228,7 +228,6 @@ abstract class EchoDiscussionParser {
'extra' => [ 'extra' => [
'max-mentions' => $wgEchoMaxMentionsCount, 'max-mentions' => $wgEchoMaxMentionsCount,
'section-title' => $header, 'section-title' => $header,
'notifyAgent' => true
], ],
'agent' => $agent, 'agent' => $agent,
] ); ] );
@ -261,7 +260,6 @@ abstract class EchoDiscussionParser {
'subject-name' => User::newFromId( $mentionedUserId )->getName(), 'subject-name' => User::newFromId( $mentionedUserId )->getName(),
'section-title' => $header, 'section-title' => $header,
'revid' => $revision->getId(), 'revid' => $revision->getId(),
'notifyAgent' => true
], ],
'agent' => $agent, 'agent' => $agent,
] ); ] );
@ -278,7 +276,6 @@ abstract class EchoDiscussionParser {
'subject-name' => $anonymousUser, 'subject-name' => $anonymousUser,
'section-title' => $header, 'section-title' => $header,
'revid' => $revision->getId(), 'revid' => $revision->getId(),
'notifyAgent' => true
], ],
'agent' => $agent, 'agent' => $agent,
] ); ] );
@ -295,7 +292,6 @@ abstract class EchoDiscussionParser {
'subject-name' => $unknownUser, 'subject-name' => $unknownUser,
'section-title' => $header, 'section-title' => $header,
'revid' => $revision->getId(), 'revid' => $revision->getId(),
'notifyAgent' => true
], ],
'agent' => $agent, 'agent' => $agent,
] ); ] );

View file

@ -577,7 +577,6 @@ class EchoHooks {
'agent' => $user, 'agent' => $user,
// Edit threshold notifications are sent to the agent // Edit threshold notifications are sent to the agent
'extra' => [ 'extra' => [
'notifyAgent' => true,
'editCount' => $thresholdCount, 'editCount' => $thresholdCount,
] ]
] ]
@ -667,10 +666,6 @@ class EchoHooks {
EchoEvent::create( [ EchoEvent::create( [
'type' => 'welcome', 'type' => 'welcome',
'agent' => $user, 'agent' => $user,
// Welcome notification is sent to the agent
'extra' => [
'notifyAgent' => true
]
] ); ] );
} }

View file

@ -25,7 +25,6 @@ class ApiEchoArticleReminder extends ApiBase {
'agent' => $user, 'agent' => $user,
'title' => $this->getTitleFromTitleOrPageId( $params ), 'title' => $this->getTitleFromTitleOrPageId( $params ),
'extra' => [ 'extra' => [
'notifyAgent' => true,
'comment' => $params['comment'], 'comment' => $params['comment'],
], ],
] ); ] );

View file

@ -449,9 +449,8 @@ class EchoNotificationController {
return true; return true;
} ); } );
// Don't notify the person who initiated the event unless the event extra says to do so // Don't notify the person who initiated the event unless the event allows it
$extra = $event->getExtra(); if ( !$event->canNotifyAgent() && $event->getAgent() ) {
if ( ( !isset( $extra['notifyAgent'] ) || !$extra['notifyAgent'] ) && $event->getAgent() ) {
$agentId = $event->getAgent()->getId(); $agentId = $event->getAgent()->getId();
$notify->addFilter( function ( $user ) use ( $agentId ) { $notify->addFilter( function ( $user ) use ( $agentId ) {
return $user->getId() != $agentId; return $user->getId() != $agentId;

View file

@ -506,6 +506,21 @@ class EchoEvent extends EchoAbstractEntity implements Bundleable {
return $this->agent; return $this->agent;
} }
/**
* Check whether this event allows its agent to be notified.
*
* Notifying the agent is only allowed if the event's type allows it, or if the event extra
* explicity specifies 'notifyAgent' => true.
*
* @return bool
*/
public function canNotifyAgent() {
global $wgEchoNotifications;
$allowedInConfig = $wgEchoNotifications[$this->getType()]['canNotifyAgent'] ?? false;
$allowedInExtra = $this->getExtraParam( 'notifyAgent', false );
return $allowedInConfig || $allowedInExtra;
}
/** /**
* @param bool $fromMaster * @param bool $fromMaster
* @return null|Title * @return null|Title

View file

@ -298,9 +298,6 @@ class GenerateSampleNotifications extends Maintenance {
EchoEvent::create( [ EchoEvent::create( [
'type' => 'welcome', 'type' => 'welcome',
'agent' => $user, 'agent' => $user,
'extra' => [
'notifyAgent' => true
],
'timestamp' => $this->getTimestamp(), 'timestamp' => $this->getTimestamp(),
] ); ] );
} }

View file

@ -418,14 +418,12 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Hello Users', 'section-title' => 'Hello Users',
'notifyAgent' => true,
'subject-name' => 'Ping', 'subject-name' => 'Ping',
], ],
[ [
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Hello Users', 'section-title' => 'Hello Users',
'notifyAgent' => true,
'subject-name' => 'Po?ng', 'subject-name' => 'Po?ng',
], ],
], ],
@ -442,14 +440,12 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'type' => 'mention', 'type' => 'mention',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Hello Users', 'section-title' => 'Hello Users',
'notifyAgent' => null,
'subject-name' => null, 'subject-name' => null,
], ],
[ [
'type' => 'mention-success', 'type' => 'mention-success',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Hello Users', 'section-title' => 'Hello Users',
'notifyAgent' => true,
'subject-name' => 'Test11', 'subject-name' => 'Test11',
], ],
], ],
@ -466,7 +462,6 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'notifyAgent' => true,
'subject-name' => 'NoUser', 'subject-name' => 'NoUser',
], ],
], ],
@ -483,7 +478,6 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'notifyAgent' => true,
'subject-name' => 'NoUser', 'subject-name' => 'NoUser',
], ],
], ],
@ -510,14 +504,12 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1.5', 'section-title' => 'Section 1.5',
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
[ [
'type' => 'mention-success', 'type' => 'mention-success',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1.5', 'section-title' => 'Section 1.5',
'subject-name' => 'Test11', 'subject-name' => 'Test11',
'notifyAgent' => true,
], ],
], ],
], ],
@ -534,14 +526,12 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1.5', 'section-title' => 'Section 1.5',
'subject-name' => 'NoUser1.5', 'subject-name' => 'NoUser1.5',
'notifyAgent' => true,
], ],
[ [
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'subject-name' => 'NoUser2', 'subject-name' => 'NoUser2',
'notifyAgent' => true,
], ],
], ],
], ],
@ -558,21 +548,18 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1', 'section-title' => 'Section 1',
'subject-name' => 'NoUser1', 'subject-name' => 'NoUser1',
'notifyAgent' => true,
], ],
[ [
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1.75', 'section-title' => 'Section 1.75',
'subject-name' => 'NoUser1.75', 'subject-name' => 'NoUser1.75',
'notifyAgent' => true,
], ],
[ [
'type' => 'mention-failure', 'type' => 'mention-failure',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'subject-name' => 'NoUser2', 'subject-name' => 'NoUser2',
'notifyAgent' => true,
], ],
], ],
[ [
@ -587,7 +574,6 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => false, 'section-title' => false,
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
] ], ] ],
], ],
[ [
@ -603,21 +589,18 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1', 'section-title' => 'Section 1',
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
[ [
'type' => 'mention-success', 'type' => 'mention-success',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1', 'section-title' => 'Section 1',
'subject-name' => 'Test11', 'subject-name' => 'Test11',
'notifyAgent' => true,
], ],
[ [
'type' => 'edit-user-talk', 'type' => 'edit-user-talk',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1', 'section-title' => 'Section 1',
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
], ],
], ],
@ -635,21 +618,18 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1', 'section-title' => 'Section 1',
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
[ [
'type' => 'mention-success', 'type' => 'mention-success',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 1', 'section-title' => 'Section 1',
'subject-name' => 'Test11', 'subject-name' => 'Test11',
'notifyAgent' => true,
], ],
[ [
'type' => 'edit-user-talk', 'type' => 'edit-user-talk',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => false, 'section-title' => false,
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
], ],
], ],
@ -666,21 +646,18 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
[ [
'type' => 'mention-success', 'type' => 'mention-success',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'subject-name' => 'Test11', 'subject-name' => 'Test11',
'notifyAgent' => true,
], ],
[ [
'type' => 'edit-user-talk', 'type' => 'edit-user-talk',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => 'Section 2', 'section-title' => 'Section 2',
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
], ],
], ],
@ -697,14 +674,12 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => false, 'section-title' => false,
'subject-name' => null, 'subject-name' => null,
'notifyAgent' => null,
], ],
[ [
'type' => 'mention-success', 'type' => 'mention-success',
'agent' => 'Admin', 'agent' => 'Admin',
'section-title' => false, 'section-title' => false,
'subject-name' => 'Test11', 'subject-name' => 'Test11',
'notifyAgent' => true,
], ],
], ],
], ],
@ -729,7 +704,6 @@ class EchoDiscussionParserTest extends MediaWikiTestCase {
'type' => $event->getType(), 'type' => $event->getType(),
'agent' => $event->getAgent()->getName(), 'agent' => $event->getAgent()->getName(),
'section-title' => $event->getExtraParam( 'section-title' ), 'section-title' => $event->getExtraParam( 'section-title' ),
'notifyAgent' => $event->getExtraParam( 'notifyAgent' ),
'subject-name' => $event->getExtraParam( 'subject-name' ), 'subject-name' => $event->getExtraParam( 'subject-name' ),
]; ];
return false; return false;