Skip to content

Commit

Permalink
MDL-65574 forum: discussion_list vault uses post table for author
Browse files Browse the repository at this point in the history
Update the discussion_list vault to use the first post record from
the posts table join to get the author of the first post rather
than relying on it's own "userid" column which can be incorrect in
the case of split discussions.
  • Loading branch information
ryanwyllie committed May 13, 2019
1 parent 6a7451f commit 9a6f29b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mod/forum/classes/local/vaults/discussion_list.php
Expand Up @@ -137,9 +137,9 @@ protected function generate_get_records_sql(string $wheresql = null, ?string $so
$issortbyreplies = in_array($sortsql, $sortkeys);

$tables = $thistable->get_from_sql();
$tables .= ' JOIN {user} fa ON fa.id = ' . $alias . '.userid';
$tables .= ' JOIN {user} la ON la.id = ' . $alias . '.usermodified';
$tables .= ' JOIN ' . $posttable->get_from_sql() . ' ON fp.id = ' . $alias . '.firstpost';
$tables .= ' JOIN {user} fa ON fa.id = fp.userid';
$tables .= ' JOIN {user} la ON la.id = ' . $alias . '.usermodified';
$tables .= $favsql;

if ($issortbyreplies) {
Expand Down
17 changes: 17 additions & 0 deletions mod/forum/tests/behat/split_forum_discussion.feature
Expand Up @@ -9,13 +9,15 @@ Feature: Forum discussions can be split
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
| student1 | Student | 1 | student1@example.com |
| student2 | Student | 2 | student2@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Science 101 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
And I log in as "teacher1"
And I am on "Science 101" course homepage with editing mode on
And I add a "Forum" to section "1" and I fill the form with:
Expand All @@ -31,6 +33,16 @@ Feature: Forum discussions can be split
And I reply "Photosynethis discussion" post from "Study discussions" forum with:
| Message | Can anyone tell me which number is the mass number in the periodic table? |
And I log out
And I log in as "student2"
And I am on "Science 101" course homepage
And I follow "Study discussions"
And I follow "Photosynethis discussion"
And I click on "Reply" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' forumpost ')][contains(., 'Can anyone tell me which number is the mass number in the periodic table?')]" "xpath_element"
And I wait to be redirected
And I set the following fields to these values:
| Message | I would also like to know this |
And I press "Post to forum"
And I log out

Scenario: Split a forum discussion
Given I log in as "teacher1"
Expand All @@ -44,4 +56,9 @@ Feature: Forum discussions can be split
Then I should see "Mass number in periodic table"
And I follow "Study discussions"
And I should see "Teacher 1" in the "Photosynethis" "table_row"
# Confirm that the last post author has been updated.
And I should not see "Student 2" in the "Photosynethis" "table_row"
# Confirm that the corrent author has been shown for the new split discussion.
And I should see "Student 1" in the "Mass number in periodic table" "table_row"
# Confirm that the last post author has been updated for the new discussion.
And I should see "Student 2" in the "Mass number in periodic table" "table_row"

0 comments on commit 9a6f29b

Please sign in to comment.