Sbisson has uploaded a new change for review.

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

Change subject: Fix history permission check in RevisionFormatter
......................................................................

Fix history permission check in RevisionFormatter

* Add suppress browser tests

* DataManager.rb to simplify creation and
  access of unique data.

* Add root-permission to history to hide
  comments on suppressed topic/post.

Bug T96933
Change-Id: I3e7497d162e77ddc4c0c5aba1725a3290353fbcf
---
M FlowActions.php
M includes/Block/BoardHistory.php
M includes/Formatter/RevisionFormatter.php
M tests/browser/features/moderation.feature
M tests/browser/features/step_definitions/flow_steps.rb
M tests/browser/features/step_definitions/moderation_steps.rb
A tests/browser/features/step_definitions/suppress_steps.rb
A tests/browser/features/support/data_manager.rb
M tests/browser/features/support/hooks.rb
M tests/browser/features/support/pages/flow_page.rb
A tests/browser/features/support/pages/history_page.rb
A tests/browser/features/support/pages/wiki_page.rb
A tests/browser/features/suppress.feature
13 files changed, 215 insertions(+), 41 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/97/207797/1

diff --git a/FlowActions.php b/FlowActions.php
index 3e5e5bb..1e41e15 100644
--- a/FlowActions.php
+++ b/FlowActions.php
@@ -731,6 +731,9 @@
                        PostRevision::MODERATED_DELETED => '',
                        PostRevision::MODERATED_SUPPRESSED => 'flow-suppress',
                ),
+               'root-permissions' => array(
+                       PostRevision::MODERATED_NONE => '',
+               ),
                'history' => array(), // views don't generate history
                'handler-class' => 'Flow\Actions\FlowAction',
        ),
diff --git a/includes/Block/BoardHistory.php b/includes/Block/BoardHistory.php
index 2ff81ca..333cd66 100644
--- a/includes/Block/BoardHistory.php
+++ b/includes/Block/BoardHistory.php
@@ -63,7 +63,7 @@
 
                $revisions = array();
                foreach ( $history as $row ) {
-                       $serialized = $formatter->formatApi( $row, 
$this->context );
+                       $serialized = $formatter->formatApi( $row, 
$this->context, 'history' );
                        if ( $serialized ) {
                                $revisions[$serialized['revisionId']] = 
$serialized;
                        }
diff --git a/includes/Formatter/RevisionFormatter.php 
b/includes/Formatter/RevisionFormatter.php
index 8bf995c..e81d4fa 100644
--- a/includes/Formatter/RevisionFormatter.php
+++ b/includes/Formatter/RevisionFormatter.php
@@ -162,7 +162,7 @@
         * @param IContextSource $ctx
         * @return array|false
         */
-       public function formatApi( FormatterRow $row, IContextSource $ctx ) {
+       public function formatApi( FormatterRow $row, IContextSource $ctx, 
$action = 'view' ) {
                $user = $ctx->getUser();
                // @todo the only permissions currently checked in this class 
are prev-revision
                // mostly permissions is used for the actions,  figure out how 
permissions should
@@ -172,12 +172,9 @@
                        return false;
                }
 
-               $isContentAllowed = $this->includeContent && 
$this->permissions->isAllowed( $row->revision, 'view' );
-               $isHistoryAllowed = $this->permissions->isAllowed( 
$row->revision, 'history' );
-
-               if ( !$isHistoryAllowed ) {
-                       return array();
-               }
+        if ( !$this->permissions->isAllowed( $row->revision, $action ) ) {
+            return false;
+        }
 
                $moderatedRevision = $this->templating->getModeratedRevision( 
$row->revision );
                $ts = $row->revision->getRevisionId()->getTimestampObj();
@@ -234,7 +231,7 @@
                        );
                }
 
-               if ( $isContentAllowed ) {
+               if ( $this->includeContent ) {
                        // topic titles are always forced to plain text
                        $contentFormat = $this->decideContentFormat( 
$row->revision );
 
diff --git a/tests/browser/features/moderation.feature 
b/tests/browser/features/moderation.feature
index 7718e1a..9df149b 100644
--- a/tests/browser/features/moderation.feature
+++ b/tests/browser/features/moderation.feature
@@ -16,15 +16,6 @@
         And I click Delete topic
     Then the top post should be marked as deleted
 
-  Scenario: Suppressing a topic
-    Given I have created a Flow topic with title "Suppressmeifyoudare"
-    When I hover on the Topic Actions link
-        And I click the Suppress topic button
-        And I see a dialog box
-        And I give reason for suppression as being "Quelling the peasants"
-        And I click Suppress topic
-    Then the top post should be marked as suppressed
-
   Scenario: Cancelling a dialog without text
     Given I have created a Flow topic with title "Testing cancel deletion of 
topic"
     When I hover on the Topic Actions link
diff --git a/tests/browser/features/step_definitions/flow_steps.rb 
b/tests/browser/features/step_definitions/flow_steps.rb
index aca75dc..a774459 100644
--- a/tests/browser/features/step_definitions/flow_steps.rb
+++ b/tests/browser/features/step_definitions/flow_steps.rb
@@ -65,10 +65,6 @@
   on(FlowPage).post_actions_link_element.when_present.hover
 end
 
-When(/^I click the Suppress topic button$/) do
-  on(FlowPage).topic_suppress_button_element.when_present.click
-end
-
 When(/^I hover on the Topic Actions link$/) do
   on(FlowPage).topic_actions_link_element.when_present.hover
 end
@@ -82,18 +78,34 @@
 end
 
 When(/^I type "(.+)" into the new topic content field$/) do |flow_body|
-  body_string = flow_body + @random_string + @automated_test_marker
+  body_string = @data_manager.get flow_body
   on(FlowPage).new_topic_body_element.when_present.send_keys(body_string)
 end
 
 When(/^I type "(.+)" into the new topic title field$/) do |flow_title|
-  @automated_test_marker = " browsertest edit"
   on(FlowPage) do |page|
-    @topic_string = flow_title + @random_string + @automated_test_marker
+    @topic_string = @data_manager.get flow_title
     page.new_topic_title_element.when_present.click
     page.new_topic_title_element.when_present.focus
     page.new_topic_title_element.when_present.send_keys(@topic_string)
   end
+end
+
+When(/I log out/) do
+  on(FlowPage) do |page|
+    page.logout
+    page.logout_element.when_not_visible
+  end
+end
+
+When(/^I visit the board history page$/) do
+  visit HistoryPage
+  on(HistoryPage).flow_board_history_element.when_present
+end
+
+When(/^I visit the topic history page$/) do
+  on(FlowPage).view_history
+  on(HistoryPage).flow_board_history_element.when_present
 end
 
 Then(/^I am on my user page$/) do
@@ -165,3 +177,37 @@
 Then(/^the top post should not have a heading which contains "(.+)"$/) do 
|text|
   expect(on(FlowPage).flow_first_topic_heading).not_to match(text)
 end
+
+Then(/^I see the topic "(.*?)" on the board$/) do |title|
+  full_title = @data_manager.get title
+  on(FlowPage).topic_with_title(full_title).when_present
+end
+
+Then(/^everybody sees the topic "(.*?)" on the board$/) do |title|
+  step 'I log out'
+  step 'I am on Flow page'
+  step "I see the topic \"#{title}\" on the board"
+end
+
+Then(/^I see the following entries in history$/) do |table|
+  on(HistoryPage) do |page|
+    table.hashes.each do |row|
+      action = row['action']
+      topic = @data_manager.get row['topic']
+      entry = %Q{#{action} "#{topic}"}
+      expect(page.flow_board_history).to match(entry)
+    end
+  end
+end
+
+Then(/^I do not see the following entries in history$/) do |table|
+  on(HistoryPage) do |page|
+    table.hashes.each do |row|
+      action = row['action']
+      topic = @data_manager.get row['topic']
+      entry = %Q{#{action} "#{topic}"}
+      expect(page.flow_board_history).to_not match(entry)
+    end
+  end
+end
+
diff --git a/tests/browser/features/step_definitions/moderation_steps.rb 
b/tests/browser/features/step_definitions/moderation_steps.rb
index c642116..d72fd67 100644
--- a/tests/browser/features/step_definitions/moderation_steps.rb
+++ b/tests/browser/features/step_definitions/moderation_steps.rb
@@ -10,10 +10,6 @@
   on(FlowPage).dialog_submit_hide_element.when_present.click
 end
 
-When(/^I click Suppress topic$/) do
-  on(FlowPage).dialog_submit_suppress_element.when_present.click
-end
-
 When(/^I give reason for deletion as being "(.*?)"$/) do |delete_reason|
   on(FlowPage).dialog_input_element.when_present.send_keys(delete_reason)
 end
@@ -22,12 +18,12 @@
   on(FlowPage).dialog_input_element.when_present.send_keys(hide_reason)
 end
 
-When(/^I give reason for suppression as being "(.*?)"$/) do |suppress_reason|
-  on(FlowPage).dialog_input_element.when_present.send_keys(suppress_reason)
-end
-
 When(/^I see a dialog box$/) do
   on(FlowPage).dialog_element.when_present
+end
+
+When(/^I type "(.*?)" in the dialog box$/) do |text|
+  on(FlowPage).dialog_input_element.when_present.send_keys(text)
 end
 
 Then(/^I confirm$/) do
@@ -40,8 +36,4 @@
 
 Then(/^the top post should be marked as deleted$/) do
   
expect(on(FlowPage).flow_first_topic_moderation_msg_element.when_present.text).to
 match("This topic has been deleted")
-end
-
-Then(/^the top post should be marked as suppressed$/) do
-  
expect(on(FlowPage).flow_first_topic_moderation_msg_element.when_present.text).to
 match("This topic has been suppressed")
 end
diff --git a/tests/browser/features/step_definitions/suppress_steps.rb 
b/tests/browser/features/step_definitions/suppress_steps.rb
new file mode 100644
index 0000000..66f4262
--- /dev/null
+++ b/tests/browser/features/step_definitions/suppress_steps.rb
@@ -0,0 +1,37 @@
+
+Given(/^I have suppressed and restored the first topic$/) do
+  step 'I suppress the first topic with reason "no reason given"'
+  step 'I undo the suppression'
+end
+
+When(/^I click the Suppress topic button$/) do
+  on(FlowPage).topic_suppress_button_element.when_present.click
+end
+
+When(/^I click Suppress topic$/) do
+  on(FlowPage).dialog_submit_suppress_element.when_present.click
+end
+
+When(/^I undo the suppression$/) do
+  on(FlowPage) do |page|
+    page.undo_suppression_button_element.when_present.click
+         page.undo_suppression_button_element.when_not_visible
+    end
+end
+
+When(/^I suppress the first topic with reason "(.*?)"$/) do |reason|
+  step 'I hover on the Topic Actions link'
+  step 'I click the Suppress topic button'
+  step 'I see a dialog box'
+  step "I type \"#{reason}\" in the dialog box"
+  step 'I click Suppress topic'
+  step 'the top post should be marked as suppressed'
+end
+
+When(/^I suppress the first topic$/) do
+  step "I suppress the first topic with reason \"no reason given\""
+end
+
+Then(/^the top post should be marked as suppressed$/) do
+  
expect(on(FlowPage).flow_first_topic_moderation_msg_element.when_present.text).to
 match("This topic has been suppressed")
+end
\ No newline at end of file
diff --git a/tests/browser/features/support/data_manager.rb 
b/tests/browser/features/support/data_manager.rb
new file mode 100644
index 0000000..952dd49
--- /dev/null
+++ b/tests/browser/features/support/data_manager.rb
@@ -0,0 +1,12 @@
+class DataManager
+  def initialize
+    @data = {}
+  end
+
+  def get (part)
+    unless @data.key? part
+      @data[part] = "#{part}-#{rand}"
+    end
+    @data[part]
+  end
+end
\ No newline at end of file
diff --git a/tests/browser/features/support/hooks.rb 
b/tests/browser/features/support/hooks.rb
index 5ab6259..59a7e71 100644
--- a/tests/browser/features/support/hooks.rb
+++ b/tests/browser/features/support/hooks.rb
@@ -1,3 +1,6 @@
 # Allow running of bundle exec cucumber --dry-run -f stepdefs
 require "mediawiki_selenium"
 require 'page-object'
+require_relative 'data_manager.rb'
+
+Before { @data_manager = DataManager.new }
\ No newline at end of file
diff --git a/tests/browser/features/support/pages/flow_page.rb 
b/tests/browser/features/support/pages/flow_page.rb
index d7c5909..3a682ea 100644
--- a/tests/browser/features/support/pages/flow_page.rb
+++ b/tests/browser/features/support/pages/flow_page.rb
@@ -1,7 +1,4 @@
-class WikiPage
-  include PageObject
-  a(:logout, css: "#pt-logout a")
-end
+require_relative 'wiki_page'
 
 class FlowPage < WikiPage
   include URL
@@ -44,6 +41,10 @@
   # Posts
   ## Highlighted post
   div(:highlighted_post, css: ".flow-post-highlighted")
+
+  def topic_with_title title
+    div_element(text: title)
+  end
 
   ## First topic
   div(:flow_first_topic, css: ".flow-topic", index: 0)
@@ -252,4 +253,10 @@
 
   a(:board_unwatch_link, href: /Flow_QA&action=unwatch/)
   a(:board_watch_link, href: /Flow_QA&action=watch/)
+
+  # undo suppression
+  button(:undo_suppression_button, text: "Undo")
+
+  # history
+  a(:view_history, text: 'View history')
 end
diff --git a/tests/browser/features/support/pages/history_page.rb 
b/tests/browser/features/support/pages/history_page.rb
new file mode 100644
index 0000000..e7a3c5d
--- /dev/null
+++ b/tests/browser/features/support/pages/history_page.rb
@@ -0,0 +1,9 @@
+class HistoryPage
+  include PageObject
+
+  include URL
+  
+  page_url URL.url("Talk:Flow_QA?action=history")
+
+  div(:flow_board_history, class: 'flow-board-history')
+end
diff --git a/tests/browser/features/support/pages/wiki_page.rb 
b/tests/browser/features/support/pages/wiki_page.rb
new file mode 100644
index 0000000..bbe5eb7
--- /dev/null
+++ b/tests/browser/features/support/pages/wiki_page.rb
@@ -0,0 +1,4 @@
+class WikiPage
+  include PageObject
+  a(:logout, css: "#pt-logout a")
+end
\ No newline at end of file
diff --git a/tests/browser/features/suppress.feature 
b/tests/browser/features/suppress.feature
new file mode 100644
index 0000000..07ab8bc
--- /dev/null
+++ b/tests/browser/features/suppress.feature
@@ -0,0 +1,73 @@
+@chrome @clean @en.wikipedia.beta.wmflabs.org @firefox @internet_explorer_10 
@login @test2.wikipedia.org
+Feature: Suppress
+
+  Assumes Flow is enabled for the User_talk namespace.
+
+  Background:
+    Given I am logged in
+        And I am on Flow page
+
+  Scenario: Suppressing a topic
+    Given I have created a Flow topic with title "suppress-topic"
+    When I suppress the first topic with reason "I suppress you"
+    Then the top post should be marked as suppressed
+
+  Scenario: Restoring a topic
+    Given I have created a Flow topic with title "suppress-restore-topic"
+    When I suppress the first topic with reason "I suppress you temporarily"
+        And I undo the suppression
+    Then I see the topic "suppress-restore-topic" on the board
+        And everybody sees the topic "suppress-restore-topic" on the board
+
+  Scenario: A suppressed topic is not in board history
+    Given I have created a Flow topic with title "suppress-not-in-history"
+        And I suppress the first topic
+    When I visit the board history page
+    Then I see the following entries in history
+        |action              |topic                  |
+        |suppressed the topic|suppress-not-in-history|
+        |created the topic   |suppress-not-in-history|
+    When I log out
+        And I visit the board history page
+    Then I do not see the following entries in history
+        |action              |topic                  |
+        |suppressed the topic|suppress-not-in-history|
+        |created the topic   |suppress-not-in-history|
+
+  Scenario: A suppressed and restored topic is in board history
+    Given I have created a Flow topic with title "suppress-restore-in-history"
+        And I have suppressed and restored the first topic
+    When I visit the board history page
+    Then I see the following entries in history
+        |action              |topic                      |
+        |restored the topic  |suppress-restore-in-history|
+        |suppressed the topic|suppress-restore-in-history|
+        |created the topic   |suppress-restore-in-history|
+    When I log out
+        And I visit the board history page
+    Then I see the following entries in history
+        |action              |topic                      |
+        |created the topic   |suppress-restore-in-history|
+    Then I do not see the following entries in history
+        |action              |topic                      |
+        |restored the topic  |suppress-restore-in-history|
+        |suppressed the topic|suppress-restore-in-history|
+
+  Scenario: A suppressed and restored topic is in topic history
+    Given I have created a Flow topic with title "suppress-restore-in-history"
+        And I have suppressed and restored the first topic
+    When I visit the topic history page
+    Then I see the following entries in history
+        |action              |topic                      |
+        |restored the topic  |suppress-restore-in-history|
+        |suppressed the topic|suppress-restore-in-history|
+        |created the topic   |suppress-restore-in-history|
+    When I log out
+        And I visit the board history page
+    Then I see the following entries in history
+        |action              |topic                      |
+        |created the topic   |suppress-restore-in-history|
+    Then I do not see the following entries in history
+        |action              |topic                      |
+        |restored the topic  |suppress-restore-in-history|
+        |suppressed the topic|suppress-restore-in-history|

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3e7497d162e77ddc4c0c5aba1725a3290353fbcf
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Sbisson <sbis...@wikimedia.org>

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

Reply via email to