Aude has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/356629 )

Change subject: Fix default notification preference
......................................................................


Fix default notification preference

Making it default preference was wrong because default preferences
are fallback for missing preferences, whereas it was missing for
all users when the feature was deployed.

Bug: T166657
Change-Id: I5a475b35c5b8392f799b4ff8f64de684b9833544
---
M client/WikibaseClient.hooks.php
M client/includes/Hooks/EchoNotificationsHandlers.php
M client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
3 files changed, 62 insertions(+), 10 deletions(-)

Approvals:
  Aude: Verified; Looks good to me, approved



diff --git a/client/WikibaseClient.hooks.php b/client/WikibaseClient.hooks.php
index 646bbc0..850a46e 100644
--- a/client/WikibaseClient.hooks.php
+++ b/client/WikibaseClient.hooks.php
@@ -458,7 +458,7 @@
 
                // These hooks should only be run if we use the Echo extension
                if ( class_exists( EchoEvent::class ) ) {
-                       $wgHooks['UserGetDefaultOptions'][] = 
EchoNotificationsHandlers::class . '::onUserGetDefaultOptions';
+                       $wgHooks['LocalUserCreated'][] = 
EchoNotificationsHandlers::class . '::onLocalUserCreated';
                        $wgHooks['WikibaseHandleChange'][] = 
EchoNotificationsHandlers::class . '::onWikibaseHandleChange';
                }
 
diff --git a/client/includes/Hooks/EchoNotificationsHandlers.php 
b/client/includes/Hooks/EchoNotificationsHandlers.php
index 35842dc..3c0ff36 100644
--- a/client/includes/Hooks/EchoNotificationsHandlers.php
+++ b/client/includes/Hooks/EchoNotificationsHandlers.php
@@ -165,22 +165,24 @@
        }
 
        /**
-        * Handler for UserGetDefaultOptions hook
-        * @see 
https://www.mediawiki.org/wiki/Manual:Hooks/UserGetDefaultOptions
-        *
-        * @param bool[] &$defaultOptions Array of preference keys and their 
default values.
+        * Handler for LocalUserCreated hook.
+        * @see https://www.mediawiki.org/wiki/Manual:Hooks/LocalUserCreated
+        * @param User $user User object that was created.
+        * @param bool $autocreated True when account was auto-created
         */
-       public static function onUserGetDefaultOptions( array &$defaultOptions 
) {
+       public static function onLocalUserCreated( User $user, $autocreated ) {
                $self = self::newFromGlobalState();
-               $self->doUserGetDefaultOptions( $defaultOptions );
+               $self->doLocalUserCreated( $user, $autocreated );
        }
 
        /**
-        * @param bool[] &$defaultOptions
+        * @param User $user
+        * @param bool $autocreated
         */
-       public function doUserGetDefaultOptions( array &$defaultOptions ) {
+       public function doLocalUserCreated( User $user, $autocreated ) {
                if ( $this->sendEchoNotification === true ) {
-                       
$defaultOptions['echo-subscriptions-web-wikibase-action'] = true;
+                       $user->setOption( 
'echo-subscriptions-web-wikibase-action', true );
+                       $user->saveSettings();
                }
        }
 
diff --git 
a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php 
b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
index c120e44..c32418a 100644
--- a/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
+++ b/client/tests/phpunit/includes/Hooks/EchoNotificationsHandlersTest.php
@@ -5,6 +5,7 @@
 use EchoEvent;
 use MediaWikiTestCase;
 use Title;
+use User;
 use Wikibase\ChangeRow;
 use Wikibase\Client\Hooks\EchoNotificationsHandlers;
 use Wikibase\Client\RepoLinker;
@@ -219,4 +220,53 @@
                }
        }
 
+       public function localUserCreatedProvider() {
+               return [
+                       'disabled no auto' => [
+                               'enabled' => false,
+                               'times' => 0,
+                               'auto' => false,
+                       ],
+                       'disabled auto' => [
+                               'enabled' => false,
+                               'times' => 0,
+                               'auto' => true,
+                       ],
+                       'enabled no auto' => [
+                               'enabled' => true,
+                               'times' => 1,
+                               'auto' => false,
+                       ],
+                       'enabled auto' => [
+                               'enabled' => true,
+                               'times' => 1,
+                               'auto' => true,
+                       ]
+               ];
+       }
+
+       /**
+        * @dataProvider localUserCreatedProvider
+        */
+       public function testLocalUserCreated( $enabled, $times, $auto ) {
+               $handlers = new EchoNotificationsHandlers(
+                       $this->repoLinker,
+                       'enwiki',
+                       $enabled,
+                       '',
+                       'repoSiteName'
+               );
+
+               $user = $this->getMockBuilder( User::class )
+                       ->disableOriginalConstructor()
+                       ->getMock();
+
+               $user->expects( $this->exactly( $times ) )
+                       ->method( 'setOption' );
+               $user->expects( $this->exactly( $times ) )
+                       ->method( 'saveSettings' );
+
+               $handlers->doLocalUserCreated( $user, $auto );
+       }
+
 }

-- 
To view, visit https://gerrit.wikimedia.org/r/356629
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I5a475b35c5b8392f799b4ff8f64de684b9833544
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: wmf/1.30.0-wmf.1
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Lydia Pintscher (WMDE) <lydia.pintsc...@wikimedia.de>
Gerrit-Reviewer: Matěj Suchánek <matejsuchane...@gmail.com>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to