Florianschmidtwelzow has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/303592

Change subject: Add Echo notifications for Special:ManageGoogleLogin actions
......................................................................

Add Echo notifications for Special:ManageGoogleLogin actions

Currently, an user, who is edited through Special:ManageGoogleLogin,
wouldn't get any notification about that, if the GoogleLogin administrator
doesn't send an e-mail with Special:EmailUser. For transparency, GoogleLogin
now supports to send an Echo alert to the affected user whenever a
GoogleLogin administrator changes the connected Google accounts for
a user. This is configurable in Special:Preferences, defaults to true
(enabled), but can be turned off globally by a sysadmin (by setting
$wgGLEnableEchoEvents to false in LocalSettings.php).

Change-Id: I062f02a6f811111ec7c253a688d523f7204d1555
---
M extension.json
M i18n/en.json
M i18n/qqq.json
A includes/EchoGoogleLoginPresentationModel.php
M includes/GoogleLogin.hooks.php
M includes/specials/SpecialManageGoogleLogin.php
6 files changed, 113 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GoogleLogin 
refs/changes/92/303592/1

diff --git a/extension.json b/extension.json
index 7e98c78..7cab228 100644
--- a/extension.json
+++ b/extension.json
@@ -25,6 +25,10 @@
                "GoogleLoginReturn": 
"GoogleLogin\\Specials\\SpecialGoogleLoginReturn",
                "ManageGoogleLogin": 
"GoogleLogin\\Specials\\SpecialManageGoogleLogin"
        },
+       "DefaultUserOptions": {
+               "echo-subscriptions-web-change-googlelogin": true,
+               "echo-subscriptions-email-change-googlelogin": true
+       },
        "APIModules": {
                "googleplusprofileinfo": "ApiGoogleLoginInfo"
        },
@@ -38,6 +42,7 @@
        },
        "AutoloadClasses": {
                "GoogleLogin\\GoogleLogin": "includes/GoogleLogin.body.php",
+               "GoogleLogin\\EchoGoogleLoginPresentationModel": 
"includes/EchoGoogleLoginPresentationModel.php",
                "GoogleLogin\\HTMLGoogleLoginButtonField": 
"includes/htmlform/HTMLGoogleLoginButtonField.php",
                "GoogleLogin\\Specials\\SpecialGoogleLogin": 
"includes/specials/SpecialGoogleLogin.php",
                "GoogleLogin\\Specials\\SpecialGoogleLoginReturn": 
"includes/specials/SpecialGoogleLoginReturn.php",
@@ -130,6 +135,12 @@
                ],
                "UserMergeAccountDeleteTables": [
                        
"GoogleLogin\\GoogleLoginHooks::onUserMergeAccountDeleteTables"
+               ],
+               "BeforeCreateEchoEvent": [
+                       "GoogleLogin\\GoogleLoginHooks::onBeforeCreateEchoEvent"
+               ],
+               "EchoGetBundleRules": [
+                       "GoogleLogin\\GoogleLoginHooks::onEchoGetBundleRules"
                ]
        },
        "config": {
@@ -137,7 +148,8 @@
                "GLAppId": "",
                "GLAllowedDomains": "",
                "GLAllowedDomainsStrict": false,
-               "GLAPIKey": ""
+               "GLAPIKey": "",
+               "GLEnableEchoEvents": true
        },
        "load_composer_autoloader": true,
        "manifest_version": 1
diff --git a/i18n/en.json b/i18n/en.json
index d54bdcd..dc621eb 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -64,5 +64,9 @@
        "tag-googlelogin": "[[Special:GoogleLogin|GoogleLogin]]",
        "tag-googlelogin-description": "Registrations with this tag were made 
with [[Special:GoogleLogin|GoogleLogin]]",
        "action-managegooglelogin": "manage GoogleLogin connections",
-       "right-managegooglelogin": "Can add, remove and view GoogleLogin 
connections"
+       "right-managegooglelogin": "Can add, remove and view GoogleLogin 
connections",
+       "echo-category-title-change-googlelogin": "Connected Google account 
changes",
+       "notification-header-change-googlelogin": "Your connected Google 
accounts has been changed",
+       "notification-change-googlelogin": "The {{GENDER:$2|GoogleLogin 
administrator}} $1 changed your connected Google accounts.",
+       "echo-pref-tooltip-change-googlelogin": "Notify me, when a GoogleLogin 
administrator changes my connected Google accounts."
 }
diff --git a/i18n/qqq.json b/i18n/qqq.json
index 324ef08..f350584 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -69,5 +69,9 @@
        "tag-googlelogin": "Tag in [[Special:RecentChanges]] for user account 
creations made with GoogleLogin.\n\nSee also:\n* 
{{msg-mw|Tag-googlelogin-description}}",
        "tag-googlelogin-description": "Short description, that account 
creations with this tag are made with GoogleLogin.",
        "action-managegooglelogin": "Message key for user right 
\"managegooglelogin\"\n\n{{doc-action|managegooglelogin}}",
-       "right-managegooglelogin": "Description of user right to view, edit and 
remove Google Login connections.\n\n{{Doc-right|managegooglelogin}}"
+       "right-managegooglelogin": "Description of user right to view, edit and 
remove Google Login connections.\n\n{{Doc-right|managegooglelogin}}",
+       "echo-pref-tooltip-change-googlelogin": "This is a short description of 
the change-googlelogin notification category.\n{{Related|Echo-pref-tooltip}}",
+       "echo-category-title-change-googlelogin": "Message in 
{{Special:Preferences}} for if the user wants to get notified with an Echo 
alert, if the connected Google accounts are changed by a GoogleLogin 
administrator.",
+       "notification-header-change-googlelogin": "Title of the GoogleLogin 
changed Echo alert.",
+       "notification-change-googlelogin": "Message of the GoogleLogin changed 
Echo alert.\n\nParameters:\n* $1 - Username of the agent in wikitext\n* $2 - 
Username of the agent in plain text (for GENDER support)"
 }
diff --git a/includes/EchoGoogleLoginPresentationModel.php 
b/includes/EchoGoogleLoginPresentationModel.php
new file mode 100644
index 0000000..e39eb7b
--- /dev/null
+++ b/includes/EchoGoogleLoginPresentationModel.php
@@ -0,0 +1,19 @@
+<?php
+namespace GoogleLogin;
+
+class EchoGoogleLoginPresentationModel extends \EchoEventPresentationModel {
+       public function getIconType() {
+               return 'user-rights';
+       }
+
+       public function getPrimaryLink() {
+               return array(
+                       'url' => \SpecialPage::getTitleFor( 'ChangeCredentials' 
)->getLocalURL(),
+                       'label' => '',
+               );
+       }
+
+       public function getBodyMessage() {
+               return $this->getMessageWithAgent( 
'notification-change-googlelogin' );
+       }
+}
diff --git a/includes/GoogleLogin.hooks.php b/includes/GoogleLogin.hooks.php
index 5093493..ba5d01e 100644
--- a/includes/GoogleLogin.hooks.php
+++ b/includes/GoogleLogin.hooks.php
@@ -104,4 +104,59 @@
                        unset( $formDescriptor['googlelogin']['type'] );
                }
        }
+
+       /**
+        * Add GoogleLogin management events to Echo
+        *
+        * @param array $notifications Echo notifications
+        * @param array $notificationCategories Echo categories
+        * @param array $icons Echo icons
+        * @return bool
+        */
+       public static function onBeforeCreateEchoEvent(
+               &$notifications, &$notificationCategories, &$icons
+       ) {
+               if ( GoogleLogin::getGLConfig()->get( 'GLEnableEchoEvents' ) ) {
+                       $notificationCategories['change-googlelogin'] = [
+                               'priority' => 1,
+                               'tooltip' => 
'echo-pref-tooltip-change-googlelogin',
+                       ];
+                       $notifications['change-googlelogin'] = [
+                               \EchoAttributeManager::ATTR_LOCATORS => [
+                                       [ 
'EchoUserLocator::locateFromEventExtra', [ 'user' ] ],
+                               ],
+                               'category' => 'change-googlelogin',
+                               'group' => 'neutral',
+                               'section' => 'alert',
+                               'presentation-model' => 
'GoogleLogin\\EchoGoogleLoginPresentationModel',
+                               'bundle' => [
+                                       'web' => true,
+                                       'expandable' => true,
+                               ],
+                       ];
+               }
+               return true;
+       }
+
+       /**
+        * Bundle GoogleLogin echo notifications if they're made from the same 
administrator.
+        *
+        * @param \EchoEvent $event
+        * @param String $bundleString
+        * @return boolean
+        */
+       public static function onEchoGetBundleRules( \EchoEvent $event, 
&$bundleString ) {
+               if (
+                       $event->getType() === 'change-googlelogin' &&
+                       GoogleLogin::getGLConfig()->get( 'GLEnableEchoEvents' )
+               ) {
+                       $bundleString = 'change-googlelogin';
+                       $agentUser = $event->getAgent();
+                       if ( $agentUser ) {
+                               $bundleString .= $agentUser->getId();
+                       }
+               }
+
+               return true;
+       }
 }
diff --git a/includes/specials/SpecialManageGoogleLogin.php 
b/includes/specials/SpecialManageGoogleLogin.php
index b82352a..ccb4c4e 100644
--- a/includes/specials/SpecialManageGoogleLogin.php
+++ b/includes/specials/SpecialManageGoogleLogin.php
@@ -5,6 +5,7 @@
 
 namespace GoogleLogin\Specials;
 
+use GoogleLogin\GoogleLogin;
 use SpecialPage;
 use Html;
 use HTMLForm;
@@ -161,6 +162,7 @@
                $user = $this->getUser();
                $request = $this->getRequest();
                $out = $this->getOutput();
+               $glConfig = GoogleLogin::getGLConfig();
                $name = ( isset( $data['username'] ) ? $data['username'] : '' );
                if ( $checkSession && !$user->matchEditToken( $request->getVal( 
'wpEditToken' ), $name ) ) {
                        throw new ErrorPageError( 'sessionfailure-title', 
'sessionfailure' );
@@ -188,6 +190,7 @@
                                $id = str_replace( 'google-', '', $googleId );
                                if ( GoogleUser::terminateGoogleConnection( 
$this->manageableUser, $id ) ) {
                                        $out->addWikiMsg( 
'googlelogin-manage-terminatesuccess' );
+                                       $this->notifyUser( $glConfig );
                                } else {
                                        $out->addWikiMsg( 
'googlelogin-manage-changederror' );
                                }
@@ -205,7 +208,6 @@
                                $out->wrapWikiMsg( '<div 
class="error">$1</div>', 'googlelogin-manage-givenid' );
                        } else {
                                // check, if the google id has a google plus 
profile
-                               $glConfig = 
ConfigFactory::getDefaultInstance()->makeConfig( 'googlelogin' );
                                $plusCheck = Http::get(
                                        
'https://www.googleapis.com/plus/v1/people/' .
                                        $requestAddGoogleId .
@@ -220,6 +222,7 @@
 
                                if ( GoogleUser::connectWithGoogle( 
$this->manageableUser, $requestAddGoogleId ) ) {
                                        $out->addWikiMsg( 
'googlelogin-manage-changedsuccess' );
+                                       $this->notifyUser( $glConfig );
                                } else {
                                        $out->addWikiMsg( 
'googlelogin-manage-changederror' );
                                }
@@ -231,4 +234,16 @@
        protected function getGroupName() {
                return 'users';
        }
+
+       protected function notifyUser( \Config $config ) {
+               if ( $config->get( 'GLEnableEchoEvents' ) ) {
+                       \EchoEvent::create( [
+                               'type' => 'change-googlelogin',
+                               'extra' => [
+                                       'user' => 
$this->manageableUser->getID(),
+                               ],
+                               'agent' => $this->getUser(),
+                       ] );
+               }
+       }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I062f02a6f811111ec7c253a688d523f7204d1555
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GoogleLogin
Gerrit-Branch: master
Gerrit-Owner: Florianschmidtwelzow <florian.schmidt.stargatewis...@gmail.com>

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

Reply via email to