Happy5214 has uploaded a new change for review.

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

Change subject: [WIP] Lock and unlock Flow topics
......................................................................

[WIP] Lock and unlock Flow topics

This patch will allow bots to lock and unlock Flow topics using the
API. Right now, this patch adds a property showing whether a topic
is locked, blocking replies to the topic if it is locked.

Bug: T108288
Change-Id: I4afb6c0fff6bf541a1a05aa2a5f9b0715e67541e
---
M pywikibot/flow.py
M tests/flow_edit_tests.py
2 files changed, 20 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/47/231747/1

diff --git a/pywikibot/flow.py b/pywikibot/flow.py
index 1580edb..7e22057 100644
--- a/pywikibot/flow.py
+++ b/pywikibot/flow.py
@@ -11,7 +11,7 @@
 
 import logging
 
-from pywikibot.exceptions import NoPage, UnknownExtension
+from pywikibot.exceptions import NoPage, UnknownExtension, LockedPage
 from pywikibot.page import BasePage
 from pywikibot.tools import PY2
 
@@ -213,6 +213,11 @@
             self._root = Post.fromJSON(self, self.uuid, self._data)
         return self._root
 
+    @property
+    def is_locked(self):
+        """Whether this topic is locked."""
+        return self.root._current_revision['isLocked']
+
     def replies(self, format='wikitext', force=False):
         """A list of replies to this topic's root post.
 
@@ -408,6 +413,9 @@
         @rtype: Post
         """
         self._load()
+        if self.page.is_locked:
+            raise LockedPage(self.page, 'Topic %s is locked.')
+
         reply_url = self._current_revision['actions']['reply']['url']
         parsed_url = urlparse(reply_url)
         params = parse_qs(parsed_url.query)
diff --git a/tests/flow_edit_tests.py b/tests/flow_edit_tests.py
index 9844f5d..2c675e30 100644
--- a/tests/flow_edit_tests.py
+++ b/tests/flow_edit_tests.py
@@ -9,6 +9,7 @@
 
 __version__ = '$Id$'
 
+from pywikibot.exceptions import LockedPage
 from pywikibot.flow import Board, Topic, Post
 from pywikibot.tools import PY2
 
@@ -149,3 +150,13 @@
         self.assertListEqual(old_nested_replies, [])
         more_root_replies = topic_root.replies(force=True)
         self.assertEqual(len(more_root_replies), len(new_root_replies) + 1)
+
+    def test_reply_to_locked_topic(self):
+        """Test replying to locked topic (should raise exception)."""
+        # Setup
+        content = 'I am a reply to a locked topic. This is not good!'
+        topic = Topic(self.site, 'Topic:Smxnipjfs8umm1wt')
+        # Reply (should raise a LockedPage exception)
+        self.assertRaises(LockedPage, topic.reply, content, 'wikitext')
+        topic_root = topic.root
+        self.assertRaises(LockedPage, topic_root.reply, content, 'wikitext')

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I4afb6c0fff6bf541a1a05aa2a5f9b0715e67541e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Happy5214 <[email protected]>

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

Reply via email to