From f5d0b197f8d576426419017a46db5be489c76a1e Mon Sep 17 00:00:00 2001 From: Laurent David Date: Wed, 1 Feb 2023 09:36:41 +0100 Subject: [PATCH] MDL-76970 mod_forum: Login prompt for guest users * When user submit to a forum as an anonymous user, the login prompt should clearly explain the follow up actions. --- mod/forum/lang/en/forum.php | 3 ++- mod/forum/post.php | 5 ++++- mod/forum/tests/behat/guest_users.feature | 16 ++++++++-------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index 388758cb59b..9a748731331 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -466,7 +466,8 @@ $string['noattachments'] = 'There are no attachments to this post'; $string['nodiscussions'] = 'There are no discussion topics yet in this forum'; $string['nodiscussionsstartedby'] = '{$a} has not started any discussions'; $string['nodiscussionsstartedbyyou'] = 'You haven\'t started any discussions yet'; -$string['noguestpost'] = 'Sorry, guests are not allowed to post.'; +$string['noguestpost'] = 'Only logged in users can post to this forum.'; +$string['noguestpost:title'] = 'Log in to continue'; $string['noguestsubscribe'] = 'Sorry, guests are not allowed to subscribe.'; $string['noguesttracking'] = 'Sorry, guests are not allowed to set tracking options.'; $string['nomorepostscontaining'] = 'No more posts containing \'{$a}\' were found'; diff --git a/mod/forum/post.php b/mod/forum/post.php index a3f2925cc0a..ddadf112001 100644 --- a/mod/forum/post.php +++ b/mod/forum/post.php @@ -105,7 +105,10 @@ if (!isloggedin() or isguestuser()) { $referer = get_local_referer(false); echo $OUTPUT->header(); - echo $OUTPUT->confirm(get_string('noguestpost', 'forum').'

'.get_string('liketologin'), get_login_url(), $referer); + echo $OUTPUT->confirm(get_string('noguestpost', 'forum'), get_login_url(), $referer, [ + 'confirmtitle' => get_string('noguestpost:title', 'forum'), + 'continuestr' => get_string('login') + ]); echo $OUTPUT->footer(); exit; } diff --git a/mod/forum/tests/behat/guest_users.feature b/mod/forum/tests/behat/guest_users.feature index 14402630c63..17bf241a772 100644 --- a/mod/forum/tests/behat/guest_users.feature +++ b/mod/forum/tests/behat/guest_users.feature @@ -83,14 +83,14 @@ Feature: Guest and not logged users could see the option to add new post or repl And I am on the "Forum" "forum activity" page Then I should see "Add discussion topic" And I click on "Add discussion topic" "link" - And I should see "Sorry, guests are not allowed to post" + And I should see "Only logged in users can post to this forum" And I click on "Cancel" "button" And I should see "Forum discussion 1" And I click on "Forum discussion 1" "link" And I should see "Reply" And I click on "Reply" "link" - And I should see "Sorry, guests are not allowed to post" - And I click on "Continue" "button" + And I should see "Only logged in users can post to this forum" + And I click on "Log in" "button" And I should see "Log in" Examples: @@ -112,11 +112,11 @@ Feature: Guest and not logged users could see the option to add new post or repl And I should see "Forum (single discussion)" Then I should see "Reply" And I click on "Reply" "link" - And I should see "Sorry, guests are not allowed to post" + And I should see "Only logged in users can post to this forum" And I click on "Cancel" "button" And I should see "Reply" And I click on "Reply" "link" - And I click on "Continue" "button" + And I click on "Log in" "button" And I should see "Log in" Scenario: As an enrolled guest I see the option to reply in a blog type forum @@ -134,10 +134,10 @@ Feature: Guest and not logged users could see the option to add new post or repl And I am on the "Forum" "forum activity" page Then I should see "Add discussion topic" And I click on "Add discussion topic" "link" - And I should see "Sorry, guests are not allowed to post" + And I should see "Only logged in users can post to this forum" And I click on "Cancel" "button" And I should see "Forum discussion 1" And I click on "Add discussion topic" "link" - And I should see "Sorry, guests are not allowed to post" - And I click on "Continue" "button" + And I should see "Only logged in users can post to this forum" + And I click on "Log in" "button" And I should see "Log in"