jenkins-bot has submitted this change. ( 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1217850?usp=email )

Change subject: Add partial block detection for User and Site
......................................................................

Add partial block detection for User and Site

This patch introduces is_partial_block() and get_block_info()
methods to the User class, and is_partial_block() to the APISite
class. This allows scripts to distinguish between sitewide blocks
and partial blocks.

Bug: T412613
Change-Id: I5e94357365c008f26bf9390ba5fdb697a1b2ff97
---
M README.rst
M pywikibot/page/_user.py
M pywikibot/site/_apisite.py
M tests/user_tests.py
4 files changed, 84 insertions(+), 0 deletions(-)

Approvals:
  TheSandDoctor: Looks good to me, but someone else must approve
  jenkins-bot: Verified
  WASP-Outis: Looks good to me, but someone else must approve
  Xqt: Looks good to me, approved




diff --git a/README.rst b/README.rst
index a2ac3c8..d251928 100644
--- a/README.rst
+++ b/README.rst
@@ -148,6 +148,17 @@

 See https://github.com/wikimedia/pywikibot/blob/stable/HISTORY.rst

+Current Development
+===================
+
+The following features are available in the development version and will be
+included in the next release:
+
+* Add ``is_partial_blocked()`` method to ``User`` and ``APISite`` classes to 
detect partial blocks
+* Add ``get_block_info()`` method to ``User`` class to retrieve detailed block 
information including block ID, reason, expiry, and restrictions
+
+See `T412613 <https://phabricator.wikimedia.org/T412613>`_ for details.
+
 Contributing
 ============

diff --git a/pywikibot/page/_user.py b/pywikibot/page/_user.py
index 9d4ea52..7753850 100644
--- a/pywikibot/page/_user.py
+++ b/pywikibot/page/_user.py
@@ -159,6 +159,32 @@
         """
         return 'blockedby' in self.getprops(force)

+    def is_partial_blocked(self, force: bool = False) -> bool:
+        """Return True if this user is partially blocked, False otherwise.
+
+        .. versionadded:: 11.0
+        """
+        return 'blockpartial' in self.getprops(force)
+
+    def get_block_info(self, force: bool = False) -> dict[str, Any] | None:
+        """Return a dictionary of block information if the user is blocked.
+
+        Returns None if the user is not blocked.
+        The returned dictionary contains keys like:
+        - blockid
+        - blockedby
+        - blockreason
+        - blockexpiry
+        - blockpartial (only if partial block)
+
+        .. versionadded:: 11.0
+        """
+        props = self.getprops(force)
+        if 'blockid' not in props:
+            return None
+
+        return {k: v for k, v in props.items() if k.startswith('block')}
+
     def is_locked(self, force: bool = False) -> bool:
         """Determine whether the user is currently locked globally.

diff --git a/pywikibot/site/_apisite.py b/pywikibot/site/_apisite.py
index 8664488..91837f5 100644
--- a/pywikibot/site/_apisite.py
+++ b/pywikibot/site/_apisite.py
@@ -779,6 +779,15 @@
             del self.userinfo
         return 'blockinfo' in self.userinfo

+    def is_partial_blocked(self, force: bool = False) -> bool:
+        """Return True if the logged-in user is partially blocked.
+
+        .. versionadded:: 11.0
+        """
+        if force:
+            del self.userinfo
+        return 'partial' in self.userinfo.get('blockinfo', {})
+
     def is_locked(self,
                   user: str | int | None = None,
                   force: bool = False) -> bool:
diff --git a/tests/user_tests.py b/tests/user_tests.py
index 651734a..8099e30 100755
--- a/tests/user_tests.py
+++ b/tests/user_tests.py
@@ -168,6 +168,44 @@
         user = User(self.site, 'TonjaHeritage2')
         self.assertTrue(user.is_locked())

+    def test_block_info(self) -> None:
+        """Test block information methods."""
+        # 1. Test partial block detection
+        user = User(self.site, 'PartialUser')
+        user._userprops = {
+            'userid': 1234,
+            'blockid': 12345,
+            'blockpartial': '',
+            'blockreason': 'Test partial'
+        }
+
+        self.assertTrue(user.is_partial_blocked())
+        info = user.get_block_info()
+        self.assertIsNotNone(info)
+        self.assertIn('blockpartial', info)
+        self.assertEqual(info['blockid'], 12345)
+
+        # 2. Test full block (not partial)
+        user = User(self.site, 'FullUser')
+        user._userprops = {
+            'userid': 5678,
+            'blockid': 67890,
+            'blockreason': 'Test full'
+        }
+
+        self.assertFalse(user.is_partial_blocked())
+        info = user.get_block_info()
+        self.assertIsNotNone(info)
+        self.assertNotIn('blockpartial', info)
+        self.assertEqual(info['blockid'], 67890)
+
+        # 3. Test unblocked user
+        user = User(self.site, 'NormalUser')
+        user._userprops = {'userid': 999}
+
+        self.assertFalse(user.is_partial_blocked())
+        self.assertIsNone(user.get_block_info())
+

 class TestUserMethods(DefaultSiteTestCase):


--
To view, visit 
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1217850?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.wikimedia.org/r/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I5e94357365c008f26bf9390ba5fdb697a1b2ff97
Gerrit-Change-Number: 1217850
Gerrit-PatchSet: 4
Gerrit-Owner: WASP-Outis <[email protected]>
Gerrit-Reviewer: TheSandDoctor <[email protected]>
Gerrit-Reviewer: WASP-Outis <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to