From ddf940808c6832892d5c2ad022d9c50483e8e22e Mon Sep 17 00:00:00 2001
From: Abijeet <abijeetpatro@gmail.com>
Date: Mon, 12 Sep 2022 14:33:11 +0530
Subject: [PATCH] [PATCH] Adds missing block checks to various pages and API

Checks were added for the following:

* Special:PageTranslation,
* Special:ManageMessageGroups
* ApiAggregateGroups,
* Translating a message group
* ManageGroupSynchronizationCacheActionApi

Bug: T302479
Change-Id: Ic2060215ba629acb90dc7ddc5d0bb016933198b9
---
 .../AggregateGroupsActionApi.php               |  4 ++++
 .../PageTranslationSpecialPage.php             | 18 ++++++++++++++++++
 ...anageGroupSynchronizationCacheActionApi.php |  4 ++++
 .../ManageGroupsSpecialPage.php                | 11 +++++++++++
 4 files changed, 37 insertions(+)

diff --git a/src/MessageGroupProcessing/AggregateGroupsActionApi.php b/src/MessageGroupProcessing/AggregateGroupsActionApi.php
index 7dea5fc4a..57f063762 100644
--- a/src/MessageGroupProcessing/AggregateGroupsActionApi.php
+++ b/src/MessageGroupProcessing/AggregateGroupsActionApi.php
@@ -43,6 +43,10 @@ class AggregateGroupsActionApi extends ApiBase {
 
 	public function execute(): void {
 		$this->checkUserRightsAny( self::$right );
+		$block = $this->getUser()->getBlock();
+		if ( $block && $block->isSitewide() ) {
+			$this->dieBlocked( $block );
+		}
 
 		$params = $this->extractRequestParams();
 		$action = $params['do'];
diff --git a/src/PageTranslation/PageTranslationSpecialPage.php b/src/PageTranslation/PageTranslationSpecialPage.php
index ad02eaa08..ddf8cfa71 100644
--- a/src/PageTranslation/PageTranslationSpecialPage.php
+++ b/src/PageTranslation/PageTranslationSpecialPage.php
@@ -34,6 +34,7 @@ use Status;
 use Title;
 use TranslateMetadata;
 use TranslateUtils;
+use UserBlockedError;
 use WebRequest;
 use Wikimedia\Rdbms\IResultWrapper;
 use Xml;
@@ -136,6 +137,23 @@ class PageTranslationSpecialPage extends SpecialPage {
 			return;
 		}
 
+		// Check for blocks
+		$permissionManager = MediaWikiServices::getInstance()->getPermissionManager();
+		if ( $permissionManager->isBlockedFrom( $user, $title, !$request->wasPosted() ) ) {
+			$block = $user->getBlock();
+			if ( $block ) {
+				throw new UserBlockedError(
+					$block,
+					$user,
+					$this->getLanguage(),
+					$request->getIP()
+				);
+			}
+
+			throw new PermissionsError( 'pagetranslation', [ 'badaccess-group0' ] );
+
+		}
+
 		// Check token for all POST actions here
 		$csrfTokenSet = $this->getContext()->getCsrfTokenSet();
 		if ( $request->wasPosted() && !$csrfTokenSet->matchTokenField( 'token' ) ) {
diff --git a/src/Synchronization/ManageGroupSynchronizationCacheActionApi.php b/src/Synchronization/ManageGroupSynchronizationCacheActionApi.php
index 43d1bb0f5..e263dffcd 100644
--- a/src/Synchronization/ManageGroupSynchronizationCacheActionApi.php
+++ b/src/Synchronization/ManageGroupSynchronizationCacheActionApi.php
@@ -35,6 +35,10 @@ class ManageGroupSynchronizationCacheActionApi extends ApiBase {
 
 	public function execute() {
 		$this->checkUserRightsAny( self::RIGHT );
+		$block = $this->getUser()->getBlock();
+		if ( $block && $block->isSitewide() ) {
+			$this->dieBlocked( $block );
+		}
 
 		$params = $this->extractRequestParams();
 		$operation = $params['operation'];
diff --git a/src/Synchronization/ManageGroupsSpecialPage.php b/src/Synchronization/ManageGroupsSpecialPage.php
index 08fad29e7..cf4d2b9b2 100644
--- a/src/Synchronization/ManageGroupsSpecialPage.php
+++ b/src/Synchronization/ManageGroupsSpecialPage.php
@@ -33,6 +33,7 @@ use SpecialPage;
 use TextContent;
 use Title;
 use TranslateUtils;
+use UserBlockedError;
 use WebRequest;
 use Xml;
 
@@ -144,6 +145,16 @@ class ManageGroupsSpecialPage extends SpecialPage {
 			return;
 		}
 
+		$block = $user->getBlock();
+		if ( $block && $block->isSitewide() ) {
+			throw new UserBlockedError(
+				$block,
+				$user,
+				$this->getLanguage(),
+				$req->getIP()
+			);
+		}
+
 		$csrfTokenSet = $this->getContext()->getCsrfTokenSet();
 		if ( !$this->hasRight || !$csrfTokenSet->matchTokenField( 'token' ) ) {
 			throw new PermissionsError( self::RIGHT );
-- 
2.37.3

