Skip to content

Commit

Permalink
MDL-76314 forum: add form check to prevent combining wrong parameters
Browse files Browse the repository at this point in the history
Form validation prevents combining the forum type "single discussion" and the group mode "separate groups".
  • Loading branch information
jboulen committed Feb 10, 2023
1 parent a2b8816 commit 002ed2d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mod/forum/lang/en/forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
$string['cannottrack'] = 'Could not stop tracking that forum';
$string['cannotunsubscribe'] = 'Could not unsubscribe you from that forum';
$string['cannotupdatepost'] = 'You can not update this post';
$string['cannotuseseperategroupsandsingletopic'] = 'Separate groups cannot be used with single discussion topic';
$string['cannotusesingletopicandseperategroups'] = 'Single discussion topic cannot be used with separate groups';
$string['cannotviewpostyet'] = 'You can\'t read other students\' posts in this discussion yet because you haven\'t posted.';
$string['cannotviewusersposts'] = 'There are no posts made by this user that you are able to view.';
$string['cleanreadtime'] = 'Mark old posts as read hour';
Expand Down
5 changes: 5 additions & 0 deletions mod/forum/mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,11 @@ function definition_after_data() {
public function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['type'] === 'single' && $data['groupmode'] == SEPARATEGROUPS) {
$errors['type'] = get_string('cannotusesingletopicandseperategroups', 'forum');
$errors['groupmode'] = get_string('cannotuseseperategroupsandsingletopic', 'forum');
}

if ($data['duedate'] && $data['cutoffdate']) {
if ($data['duedate'] > $data['cutoffdate']) {
$errors['cutoffdate'] = get_string('cutoffdatevalidation', 'forum');
Expand Down
15 changes: 15 additions & 0 deletions mod/forum/tests/behat/add_forum.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,18 @@ Feature: Add forum activities and discussions
And I should see "empty.txt"
And I follow "Edit"
And the field "Attachment" matches value "empty.txt"

@javascript
Scenario: Test forum settings validation
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And I log in as "admin"
And I am on "Course 1" course homepage with editing mode on
And I add a "Forum" to section "0" and I fill the form with:
| Forum name | Test forum |
| Forum type | single |
| Group mode | 1 |
When I press "Save and display"
Then I should see "Separate groups cannot be used with single discussion topic"
And I should see "Single discussion topic cannot be used with separate groups"

0 comments on commit 002ed2d

Please sign in to comment.