diff --git a/mod/forum/classes/local/renderers/discussion_list.php b/mod/forum/classes/local/renderers/discussion_list.php index a6907a88a66..a3418c9f7d8 100644 --- a/mod/forum/classes/local/renderers/discussion_list.php +++ b/mod/forum/classes/local/renderers/discussion_list.php @@ -385,14 +385,21 @@ class discussion_list { if ($forum->is_in_group_mode() && !$capabilitymanager->can_access_all_groups($user)) { if ($groupid === null) { - if (!$capabilitymanager->can_post_to_my_groups($user)) { + $isvisiblegroupsmode = $forum->get_effective_group_mode() == VISIBLEGROUPS; + $isgroupmember = !empty(groups_get_user_groups($forum->get_course_id(), $user->id)[0]); + + if ( + !$capabilitymanager->can_post_to_my_groups($user) + && $isvisiblegroupsmode + && $isgroupmember + ) { $notifications[] = (new notification( - get_string('cannotadddiscussiongroup', 'mod_forum'), + get_string('cannotadddiscussionall', 'mod_forum'), \core\output\notification::NOTIFY_WARNING ))->set_show_closebutton(); } else { $notifications[] = (new notification( - get_string('cannotadddiscussionall', 'mod_forum'), + get_string('cannotadddiscussiongroup', 'mod_forum'), \core\output\notification::NOTIFY_WARNING ))->set_show_closebutton(); } diff --git a/mod/forum/tests/behat/separate_group_discussions.feature b/mod/forum/tests/behat/separate_group_discussions.feature index b28d0ddb6cf..00381669807 100644 --- a/mod/forum/tests/behat/separate_group_discussions.feature +++ b/mod/forum/tests/behat/separate_group_discussions.feature @@ -193,14 +193,14 @@ Feature: Posting to all groups in a separate group discussion is restricted to u When I am on the "Standard forum name" "forum activity" page logged in as student4 Then I should see "All participants" And I should see "Initial Disc ALL" - And I should see "You are not able to create a discussion" + And I should see "You are not able to create a discussion because you are not a member of any group." And I should not see "Add discussion topic" Scenario: Students in non-participation groups can see all group discussions, but not post. When I am on the "Standard forum name" "forum activity" page logged in as student3 Then I should see "All participants" And I should see "Initial Disc ALL" - And I should see "You are not able to create a discussion" + And I should see "You are not able to create a discussion because you are not a member of any group." And I should not see "Add discussion topic" Scenario: Students in multiple group can post in all of their group individually diff --git a/mod/forum/tests/behat/visible_group_discussions.feature b/mod/forum/tests/behat/visible_group_discussions.feature index 482a562df50..b70d9b9cc83 100644 --- a/mod/forum/tests/behat/visible_group_discussions.feature +++ b/mod/forum/tests/behat/visible_group_discussions.feature @@ -259,7 +259,7 @@ Feature: Posting to all groups in a visible group discussion is restricted to us And I should see "Initial Disc G1" And I should see "Initial Disc G2" And I should see "Initial Disc G2" - And I should see "You are not able to create a discussion" + And I should see "You are not able to create a discussion because you are not a member of any group." And I should not see "Add discussion topic" Scenario: Students in non-participation groups can see all discussions, but not post. @@ -271,5 +271,5 @@ Feature: Posting to all groups in a visible group discussion is restricted to us And I should see "Initial Disc G1" And I should see "Initial Disc G2" And I should see "Initial Disc G2" - And I should see "You are not able to create a discussion" + And I should see "You do not have permission to add a new discussion topic for all participants." And I should not see "Add discussion topic"