jenkins-bot has submitted this change and it was merged.

Change subject: Add 'newsletter-delete' right
......................................................................


Add 'newsletter-delete' right

After this change, users with 'newsletter-delete' right are allowed
to delete newsletters in addition to publishers. This right is assigned
to sysops by default and allows them to be global deleters of newsletters.

Bug: T110327
Change-Id: I344a74d22348748dab28bed1fbdc837d608e6a20
---
M extension.json
M i18n/en.json
M i18n/qqq.json
M includes/Newsletter.php
M includes/specials/SpecialNewsletter.php
5 files changed, 24 insertions(+), 10 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/extension.json b/extension.json
index 8883075..19df561 100644
--- a/extension.json
+++ b/extension.json
@@ -11,6 +11,7 @@
        "type": "other",
        "AvailableRights": [
                "newsletter-create",
+               "newsletter-delete",
                "newsletter-manage"
        ],
        "GroupPermissions": {
@@ -18,6 +19,7 @@
                        "newsletter-create": true
                },
                "sysop": {
+                       "newsletter-delete": true,
                        "newsletter-manage": true
                }
        },
diff --git a/i18n/en.json b/i18n/en.json
index 4e1161d..ff83756 100755
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -54,7 +54,6 @@
        "newsletter-announce-nonexistent-page": "The provided issue page does 
not exist. Please enter an existing page.",
        "newsletter-announce-failure": "A new issue could not be announced. 
Please try again.",
        "newsletter-delete": "Delete newsletter",
-       "newsletter-delete-nopermission": "You do not have the permission to 
delete this newsletter.",
        "newsletter-delete-text": "This interface can be used to delete the 
\"$1\" newsletter. Please confirm that you intend to do this. <strong>This 
action cannot be undone.</strong>",
        "newsletter-deletenewsletter-button": "Delete this newsletter",
        "newsletter-delete-success": "Newsletter #$1 has been deleted.",
@@ -98,6 +97,8 @@
        "newsletter-dropdown-default-message": "Please select one",
        "right-newsletter-create": "Create newsletters",
        "action-newsletter-create": "create newsletters",
+       "right-newsletter-delete": "Delete newsletters",
+       "action-newsletter-delete": "delete newsletters",
        "right-newsletter-manage": "Add or remove publishers from newsletters",
        "action-newsletter-manage": "manage newsletters",
        "newsletters-summary": "This page allows you to browse through a list 
of all newsletters on this wiki and allows users to subscribe to or unsubscribe 
from them. You can also choose your newsletter subscription options through the 
 [[Special:Preferences#mw-prefsection-echo|preferences]] interface.",
diff --git a/i18n/qqq.json b/i18n/qqq.json
index f4dae71..518915a 100644
--- a/i18n/qqq.json
+++ b/i18n/qqq.json
@@ -58,7 +58,6 @@
        "newsletter-announce-nonexistent-page": "Error message shown on 
Special:Newsletter/id/announce if the issue page does not exist.",
        "newsletter-announce-failure": "Error message shown on 
Special:Newsletter/id/announce if a new issue could not be announced.",
        "newsletter-delete": "Header message shown on 
Special:Newsletter/<id>/delete.\n\nSee also:\n* 
{{msg-mw|newsletter-view}}\n*{{msg-mw|newsletter-subscribe}}",
-       "newsletter-delete-nopermission": "Error message shown on 
Special:Newsletter/<id>/delete if the current user does not have the permission 
to delete the newsletter.",
        "newsletter-delete-text": "Introductory message shown on 
Special:Newsletter/<id>/delete.\n\nParameters:\n* $1 - Name of the newsletter 
for the specified id.",
        "newsletter-deletenewsletter-button": "Label for button shown on 
Special:Newsletter/<id>/delete. Deletes the newsletter when clicked on.",
        "newsletter-delete-success": "Success message shown on 
Special:Newsletter/<id>/delete when the newsletter has been 
deleted.\n\nParameters:\n* $1 - Newsletter ID",
@@ -102,6 +101,8 @@
        "newsletter-dropdown-default-message": "Default option of drop down 
menus to select newsletters in [[Special:ManageNewsletter]].\n\nSee also:\n* 
{{msg-mw|Newsletter-name}} (label of the field)",
        "right-newsletter-create": "{{doc-right|newsletter-create}}",
        "action-newsletter-create": "{{doc-action|newsletter-create}}",
+       "right-newsletter-delete": "{{doc-right|newsletter-delete}}",
+       "action-newsletter-delete": "{{doc-action|newsletter-delete}}",
        "right-newsletter-manage": "{{doc-right|newsletter-manage}}",
        "action-newsletter-manage": "{{doc-action|newsletter-manage}}",
        "newsletters-summary": "Introductory message shown on top of 
[[Special:Newsletters]]. Do not translate the anchor of Special:Preferences 
link. (\"#mw-prefsection-echo\" part).",
diff --git a/includes/Newsletter.php b/includes/Newsletter.php
index 11ec0c6..aaf07e0 100644
--- a/includes/Newsletter.php
+++ b/includes/Newsletter.php
@@ -196,4 +196,15 @@
                }
        }
 
+       /**
+        * Check whether the user is allowed to delete the newsletter.
+        *
+        * @param User $user
+        *
+        * @return bool
+        */
+       public function canDelete( User $user ) {
+               return $this->isPublisher( $user ) || $user->isAllowed( 
'newsletter-delete' );
+       }
+
 }
diff --git a/includes/specials/SpecialNewsletter.php 
b/includes/specials/SpecialNewsletter.php
index 7543fb9..cb484d3 100644
--- a/includes/specials/SpecialNewsletter.php
+++ b/includes/specials/SpecialNewsletter.php
@@ -179,8 +179,8 @@
                $buttons = array();
                $this->getOutput()->enableOOUI();
 
-               // Only publishers can manage and delete newsletters
-               if ( $this->newsletter->isPublisher( $user ) ) {
+               if ( $this->newsletter->canDelete( $user ) ) {
+                       // This is visible to publishers and users with 
'newsletter-delete' right
                        $buttons[] = new OOUI\ButtonWidget(
                                array(
                                        'label' => $this->msg( 
'newsletter-delete-button' )->escaped(),
@@ -189,7 +189,10 @@
                                        'href' => SpecialPage::getTitleFor( 
'Newsletter', $id . '/' . self::NEWSLETTER_DELETE )->getFullURL()
                                )
                        );
+               }
 
+               if ( $this->newsletter->isPublisher( $user ) ) {
+                       // @todo show this to all users who can manage, not 
just publishers
                        $buttons[] = new OOUI\ButtonWidget(
                                array(
                                        'label' => $this->msg( 
'newsletter-manage-button' )->escaped(),
@@ -501,12 +504,8 @@
                        throw new UserBlockedError( $user->getBlock() );
                }
 
-               if ( !$this->newsletter->isPublisher( $user ) ) {
-                       // only publishers can delete newsletter (for now)
-                       $out->showPermissionsErrorPage(
-                               array( array( 'newsletter-delete-nopermission' 
) )
-                       );
-                       return;
+               if ( !$this->newsletter->canDelete( $user ) ) {
+                       throw new PermissionsError( 'newsletter-delete' );
                }
 
                $out->setPageTitle( $this->msg( 'newsletter-delete' ) );

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I344a74d22348748dab28bed1fbdc837d608e6a20
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Newsletter
Gerrit-Branch: master
Gerrit-Owner: Glaisher <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Siebrand <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to