MDL-74121 mod_forum: Fix the posting threshold issue
When a student post exceeds the posting threshold block then 'Add discussion topic' button should not be shown. Also the student cannot reply to a topic if this is exceeded.
This commit is contained in:
+1
-1
@@ -5,6 +5,6 @@
|
||||
* @copyright 2019 Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],(function($,Templates,Notification,Repository,Selectors,FormChangeChecker){var DISPLAYCONSTANTS_NESTED_V2=4,DISPLAYCONSTANTS_THREADED=2,DISPLAYCONSTANTS_NESTED=3,DISPLAYCONSTANTS_FLAT_NEWEST_FIRST=-1,EVENTS={POST_CREATED:"mod_forum-post-created"},CONTENT_FORMATS={MOODLE:0},hideSubmitButtonLoadingIcon=function(button){var textContainer=button.find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer);button.css("width",""),textContainer.removeClass("hidden"),loadingIconContainer.addClass("hidden")},registerEventListeners=function(root){root.on("click",Selectors.post.inpageSubmitBtn,(function(e){e.preventDefault();var newid,button,textContainer,loadingIconContainer,width,submitButton=$(e.currentTarget),allButtons=submitButton.parent().find(Selectors.post.inpageReplyButton),form=submitButton.parents(Selectors.post.inpageReplyForm).get(0),message=form.elements.post.value.trim(),messageformat=CONTENT_FORMATS.MOODLE,postid=form.elements.reply.value,subject=form.elements.subject.value,currentRoot=submitButton.closest(Selectors.post.post),isprivatereply=null!=form.elements.privatereply&&form.elements.privatereply.checked,modeSelector=root.find(Selectors.post.modeSelect),mode=modeSelector.length?parseInt(modeSelector.get(0).value):null;message.length&&(textContainer=(button=submitButton).find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer),width=button.outerWidth(),button.css("width",width),textContainer.addClass("hidden"),loadingIconContainer.removeClass("hidden"),allButtons.prop("disabled",!0),Repository.addDiscussionPost(postid,subject,message,messageformat,isprivatereply,!0).then((function(context){var message=context.messages.reduce((function(carry,message){return"success"==message.type&&(carry+="<p>"+message.message+"</p>"),carry}),"");return Notification.addNotification({message:message,type:"success"}),context})).then((function(context){form.reset();var post=context.post;switch(newid=post.id,mode){case DISPLAYCONSTANTS_NESTED_V2:var capabilities=post.capabilities,currentAuthorName=currentRoot.children().not(Selectors.post.repliesContainer).find(Selectors.post.authorName).text();return post.parentauthorname=currentAuthorName,post.showactionmenu=capabilities.view||capabilities.controlreadstatus||capabilities.edit||capabilities.split||capabilities.delete||capabilities.export||post.urls.viewparent,Templates.render("mod_forum/forum_discussion_nested_v2_post_reply",post);case DISPLAYCONSTANTS_THREADED:return Templates.render("mod_forum/forum_discussion_threaded_post",post);case DISPLAYCONSTANTS_NESTED:return Templates.render("mod_forum/forum_discussion_nested_post",post);default:return Templates.render("mod_forum/forum_discussion_post",post)}})).then((function(html,js){var repliesnode=currentRoot.find(Selectors.post.repliesContainer).first();return mode==DISPLAYCONSTANTS_FLAT_NEWEST_FIRST?Templates.prependNodeContents(repliesnode,html,js):Templates.appendNodeContents(repliesnode,html,js)})).then((function(){return submitButton.trigger(EVENTS.POST_CREATED,newid),hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),FormChangeChecker.resetFormDirtyState(submitButton[0]),currentRoot.find(Selectors.post.inpageReplyContent).hide()})).then((function(){location.href="#p"+newid})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))}))};return{init:function(root){registerEventListeners(root)},CONTENT_FORMATS:CONTENT_FORMATS,EVENTS:EVENTS}}));
|
||||
define("mod_forum/inpage_reply",["jquery","core/templates","core/notification","mod_forum/repository","mod_forum/selectors","core_form/changechecker"],(function($,Templates,Notification,Repository,Selectors,FormChangeChecker){var DISPLAYCONSTANTS_NESTED_V2=4,DISPLAYCONSTANTS_THREADED=2,DISPLAYCONSTANTS_NESTED=3,DISPLAYCONSTANTS_FLAT_NEWEST_FIRST=-1,EVENTS={POST_CREATED:"mod_forum-post-created"},CONTENT_FORMATS={MOODLE:0},hideSubmitButtonLoadingIcon=function(button){var textContainer=button.find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer);button.css("width",""),textContainer.removeClass("hidden"),loadingIconContainer.addClass("hidden")},registerEventListeners=function(root){root.on("click",Selectors.post.inpageSubmitBtn,(function(e){e.preventDefault();var newid,button,textContainer,loadingIconContainer,width,submitButton=$(e.currentTarget),allButtons=submitButton.parent().find(Selectors.post.inpageReplyButton),form=submitButton.parents(Selectors.post.inpageReplyForm).get(0),message=form.elements.post.value.trim(),messageformat=CONTENT_FORMATS.MOODLE,postid=form.elements.reply.value,subject=form.elements.subject.value,currentRoot=submitButton.closest(Selectors.post.post),isprivatereply=null!=form.elements.privatereply&&form.elements.privatereply.checked,modeSelector=root.find(Selectors.post.modeSelect),mode=modeSelector.length?parseInt(modeSelector.get(0).value):null;message.length&&(textContainer=(button=submitButton).find(Selectors.post.inpageSubmitBtnText),loadingIconContainer=button.find(Selectors.post.loadingIconContainer),width=button.outerWidth(),button.css("width",width),textContainer.addClass("hidden"),loadingIconContainer.removeClass("hidden"),allButtons.prop("disabled",!0),Repository.addDiscussionPost(postid,subject,message,messageformat,isprivatereply,!0).then((function(context){var message=context.messages.reduce((function(carry,message){return"success"==message.type&&(carry+="<p>"+message.message+"</p>"),carry}),"");return Notification.addNotification({message:message,type:"success"}),context})).then((function(context){form.reset();var post=context.post;switch(newid=post.id,mode){case DISPLAYCONSTANTS_NESTED_V2:var capabilities=post.capabilities,currentAuthorName=currentRoot.children().not(Selectors.post.repliesContainer).find(Selectors.post.authorName).text();return post.parentauthorname=currentAuthorName,post.showactionmenu=capabilities.view||capabilities.controlreadstatus||capabilities.edit||capabilities.split||capabilities.delete||capabilities.export||post.urls.viewparent,Templates.render("mod_forum/forum_discussion_nested_v2_post_reply",post);case DISPLAYCONSTANTS_THREADED:return Templates.render("mod_forum/forum_discussion_threaded_post",post);case DISPLAYCONSTANTS_NESTED:return Templates.render("mod_forum/forum_discussion_nested_post",post);default:return Templates.render("mod_forum/forum_discussion_post",post)}})).then((function(html,js){var repliesnode=currentRoot.find(Selectors.post.repliesContainer).first();return mode==DISPLAYCONSTANTS_FLAT_NEWEST_FIRST?Templates.prependNodeContents(repliesnode,html,js):Templates.appendNodeContents(repliesnode,html,js)})).then((function(){return submitButton.trigger(EVENTS.POST_CREATED,newid),hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),FormChangeChecker.resetFormDirtyState(submitButton[0]),currentRoot.find(Selectors.post.inpageReplyContent).hide()})).then((function(){location.href="#p"+newid,location.reload()})).catch((function(error){return hideSubmitButtonLoadingIcon(submitButton),allButtons.prop("disabled",!1),Notification.exception(error)})))}))};return{init:function(root){registerEventListeners(root)},CONTENT_FORMATS:CONTENT_FORMATS,EVENTS:EVENTS}}));
|
||||
|
||||
//# sourceMappingURL=inpage_reply.min.js.map
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -9,6 +9,6 @@
|
||||
* @copyright 2019 Peter Dias
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define("mod_forum/posts_list",["jquery","core/templates","core/notification","core/pending","mod_forum/selectors","mod_forum/inpage_reply","core_form/changechecker"],(function($,Templates,Notification,Pending,Selectors,InPageReply,FormChangeChecker){return{init:function(root){!function(root){root.on("click",Selectors.post.inpageReplyLink,(function(e){if(e.preventDefault(),window.location.hash){var url=window.location.href.split("#")[0];history.pushState({},document.title,url)}var pending=new Pending("inpage-reply"),currentTarget=$(e.currentTarget).parents(Selectors.post.forumCoreContent),currentSubject=currentTarget.find(Selectors.post.forumSubject),currentRoot=$(e.currentTarget).parents(Selectors.post.forumContent),context={postid:$(currentRoot).data("post-id"),reply_url:$(e.currentTarget).attr("href"),sesskey:M.cfg.sesskey,parentsubject:currentSubject.data("replySubject"),canreplyprivately:$(e.currentTarget).data("can-reply-privately"),postformat:InPageReply.CONTENT_FORMATS.MOODLE};if(currentRoot.find(Selectors.post.inpageReplyContent).length){var form=currentRoot.find(Selectors.post.inpageReplyContent);form.slideToggle(300,pending.resolve),form.is(":visible")&&form.find("textarea").focus()}else Templates.render("mod_forum/inpage_reply",context).then((function(html,js){return Templates.appendNodeContents(currentTarget,html,js)})).then((function(){return currentRoot.find(Selectors.post.inpageReplyContent).slideToggle(300,pending.resolve).find("textarea").focus()})).then((function(){FormChangeChecker.watchFormById("inpage-reply-".concat(context.postid))})).catch(Notification.exception)}))}(root),InPageReply.init(root)}}}));
|
||||
define("mod_forum/posts_list",["jquery","core/templates","core/notification","core/pending","mod_forum/selectors","mod_forum/inpage_reply","core_form/changechecker"],(function($,Templates,Notification,Pending,Selectors,InPageReply,FormChangeChecker){return{init:function(root,throttlingwarningmsg){!function(root,throttlingwarningmsg){root.on("click",Selectors.post.inpageReplyLink,(function(e){if(e.preventDefault(),window.location.hash){var url=window.location.href.split("#")[0];history.pushState({},document.title,url)}var pending=new Pending("inpage-reply"),currentTarget=$(e.currentTarget).parents(Selectors.post.forumCoreContent),currentSubject=currentTarget.find(Selectors.post.forumSubject),currentRoot=$(e.currentTarget).parents(Selectors.post.forumContent),context={postid:$(currentRoot).data("post-id"),reply_url:$(e.currentTarget).attr("href"),sesskey:M.cfg.sesskey,parentsubject:currentSubject.data("replySubject"),canreplyprivately:$(e.currentTarget).data("can-reply-privately"),postformat:InPageReply.CONTENT_FORMATS.MOODLE,throttlingwarningmsg:throttlingwarningmsg};if(currentRoot.find(Selectors.post.inpageReplyContent).length){var form=currentRoot.find(Selectors.post.inpageReplyContent);form.slideToggle(300,pending.resolve),form.is(":visible")&&form.find("textarea").focus()}else Templates.render("mod_forum/inpage_reply",context).then((function(html,js){return Templates.appendNodeContents(currentTarget,html,js)})).then((function(){return currentRoot.find(Selectors.post.inpageReplyContent).slideToggle(300,pending.resolve).find("textarea").focus()})).then((function(){FormChangeChecker.watchFormById("inpage-reply-".concat(context.postid))})).catch(Notification.exception)}))}(root,throttlingwarningmsg),InPageReply.init(root)}}}));
|
||||
|
||||
//# sourceMappingURL=posts_list.min.js.map
|
||||
File diff suppressed because one or more lines are too long
@@ -178,7 +178,9 @@ define([
|
||||
})
|
||||
.then(function() {
|
||||
location.href = "#p" + newid;
|
||||
return;
|
||||
|
||||
// Reload the page, say if threshold is being set by user those would get reflected through the templates.
|
||||
location.reload();
|
||||
})
|
||||
.catch(function(error) {
|
||||
hideSubmitButtonLoadingIcon(submitButton);
|
||||
|
||||
@@ -42,7 +42,7 @@ define([
|
||||
FormChangeChecker
|
||||
) {
|
||||
|
||||
var registerEventListeners = function(root) {
|
||||
var registerEventListeners = function(root, throttlingwarningmsg) {
|
||||
root.on('click', Selectors.post.inpageReplyLink, function(e) {
|
||||
e.preventDefault();
|
||||
// After adding a reply a url hash is being generated that scrolls (points) to the newly added reply.
|
||||
@@ -65,7 +65,8 @@ define([
|
||||
sesskey: M.cfg.sesskey,
|
||||
parentsubject: currentSubject.data('replySubject'),
|
||||
canreplyprivately: $(e.currentTarget).data('can-reply-privately'),
|
||||
postformat: InPageReply.CONTENT_FORMATS.MOODLE
|
||||
postformat: InPageReply.CONTENT_FORMATS.MOODLE,
|
||||
throttlingwarningmsg: throttlingwarningmsg
|
||||
};
|
||||
|
||||
if (!currentRoot.find(Selectors.post.inpageReplyContent).length) {
|
||||
@@ -93,8 +94,8 @@ define([
|
||||
};
|
||||
|
||||
return {
|
||||
init: function(root) {
|
||||
registerEventListeners(root);
|
||||
init: function(root, throttlingwarningmsg) {
|
||||
registerEventListeners(root, throttlingwarningmsg);
|
||||
InPageReply.init(root);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,6 +119,11 @@ class capability {
|
||||
}
|
||||
}
|
||||
|
||||
// If the user reaches the number of posts equal to warning/blocking setting then return the value of canpost in $warningobj.
|
||||
if ($warningobj = forum_check_throttling($this->forumrecord)) {
|
||||
return $warningobj->canpost;
|
||||
}
|
||||
|
||||
switch ($this->forum->get_type()) {
|
||||
case 'news':
|
||||
$capability = 'mod/forum:addnews';
|
||||
@@ -316,12 +321,19 @@ class capability {
|
||||
public function can_post_in_discussion(stdClass $user, discussion_entity $discussion) : bool {
|
||||
$forum = $this->get_forum();
|
||||
$forumrecord = $this->get_forum_record();
|
||||
|
||||
$discussionrecord = $this->get_discussion_record($discussion);
|
||||
$context = $this->get_context();
|
||||
$coursemodule = $forum->get_course_module_record();
|
||||
$course = $forum->get_course_record();
|
||||
|
||||
return forum_user_can_post($forumrecord, $discussionrecord, $user, $coursemodule, $course, $context);
|
||||
$status = forum_user_can_post($forumrecord, $discussionrecord, $user, $coursemodule, $course, $context);
|
||||
|
||||
// If the user reaches the number of posts equal to warning/blocking setting then logically and canpost value with $status.
|
||||
if ($warningobj = forum_check_throttling($forumrecord)) {
|
||||
return $status && $warningobj->canpost;
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -235,6 +235,14 @@ class discussion {
|
||||
];
|
||||
}
|
||||
|
||||
$exporteddiscussion['throttlingwarningmsg'] = '';
|
||||
if (($warningobj = forum_check_throttling($this->forumrecord)) && $warningobj->canpost) {
|
||||
$throttlewarnnotification = (new notification(
|
||||
get_string($warningobj->errorcode, $warningobj->module, $warningobj->additional)
|
||||
))->set_show_closebutton();
|
||||
$exporteddiscussion['throttlingwarningmsg'] = $throttlewarnnotification->get_message();
|
||||
}
|
||||
|
||||
if ($this->displaymode === FORUM_MODE_NESTED_V2) {
|
||||
$template = 'mod_forum/forum_discussion_nested_v2';
|
||||
} else {
|
||||
@@ -429,6 +437,7 @@ class discussion {
|
||||
'blockperiod' => get_string('secondstotime' . $forum->get_block_period())
|
||||
])
|
||||
))->set_show_closebutton();
|
||||
|
||||
}
|
||||
|
||||
return array_map(function($notification) {
|
||||
|
||||
@@ -27,6 +27,17 @@
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"html": {
|
||||
"hasanyactions": true,
|
||||
"posts": "<article id='p33' class='forum-post-container mb-2' data-post-id='33'></article>",
|
||||
"modeselectorform": "<div class='singleselect d-inline-block'> <form method='get' action='http://localhost/m/pg_stable_master/mod/forum/discuss.php' class='form-inline' id='mode'></div>",
|
||||
"subscribe": null,
|
||||
"movediscussion": null,
|
||||
"pindiscussion": null,
|
||||
"neighbourlinks": "<div class='discussion-nav clearfix'></div>",
|
||||
"exportdiscussion": null
|
||||
},
|
||||
"throttlingwarningmsg": "You are approaching the posting threshold. You have posted 3 times in the last 1 week and the limit is 4 posts."
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -78,7 +89,7 @@ function(
|
||||
) {
|
||||
var root = $("[data-content='forum-discussion']");
|
||||
Discussion.init(root);
|
||||
PostsList.init(root);
|
||||
PostsList.init(root, {{#quote}}{{throttlingwarningmsg}}{{/quote}});
|
||||
root = $('[data-container="discussion-tools"]');
|
||||
LockToggle.init(root, true);
|
||||
FavouriteToggle.init(root, true, function(toggleElement, context) {
|
||||
|
||||
@@ -27,6 +27,17 @@
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"html": {
|
||||
"hasanyactions": true,
|
||||
"posts": "<article id='p33' class='forum-post-container mb-2' data-post-id='33'></article>",
|
||||
"modeselectorform": "<div class='singleselect d-inline-block'> <form method='get' action='http://localhost/m/pg_stable_master/mod/forum/discuss.php' class='form-inline' id='mode'></div>",
|
||||
"subscribe": null,
|
||||
"movediscussion": null,
|
||||
"pindiscussion": null,
|
||||
"neighbourlinks": "<div class='discussion-nav clearfix'></div>",
|
||||
"exportdiscussion": null
|
||||
},
|
||||
"throttlingwarningmsg": "You are approaching the posting threshold. You have posted 3 times in the last 1 week and the limit is 4 posts."
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -47,6 +58,9 @@
|
||||
require(['jquery', 'mod_forum/discussion_nested_v2'], function($, Discussion) {
|
||||
var root = $('#discussion-container-{{uniqid}}');
|
||||
Discussion.init(root, {
|
||||
{{#throttlingwarningmsg}}
|
||||
throttlingwarningmsg: {{#quote}}{{throttlingwarningmsg}}{{/quote}},
|
||||
{{/throttlingwarningmsg}}
|
||||
{{#loggedinuser}}
|
||||
loggedinuser: {
|
||||
profileimageurl: '{{{profileimageurl}}}',
|
||||
|
||||
@@ -30,11 +30,17 @@
|
||||
"postid": 0,
|
||||
"reply_url": "",
|
||||
"sesskey": "",
|
||||
"parentsubject": ""
|
||||
"parentsubject": "",
|
||||
"throttlingwarningmsg": "You are approaching the posting threshold. You have posted 3 times in the last 1 week and the limit is 4 posts."
|
||||
}
|
||||
}}
|
||||
<div class="row" data-content="inpage-reply-content" style="display: none;">
|
||||
<div class="card card-body">
|
||||
{{#throttlingwarningmsg}}
|
||||
<div class="alert alert-danger alert-block fade in " role="alert">
|
||||
{{throttlingwarningmsg}}
|
||||
</div>
|
||||
{{/throttlingwarningmsg}}
|
||||
<form data-post-id="{{postid}}" id="inpage-reply-{{postid}}" data-content="inpage-reply-form" action="{{{reply_url}}}">
|
||||
<div class="row pb-1">
|
||||
<span>
|
||||
|
||||
@@ -53,6 +53,11 @@
|
||||
{{#loggedinuser}}
|
||||
<h4 class="h5 font-weight-bold reply-author">{{#str}} replyauthorself, mod_forum, {{firstname}}{{/str}}</h4>
|
||||
{{/loggedinuser}}
|
||||
{{#throttlingwarningmsg}}
|
||||
<div class="alert alert-danger alert-block fade in " role="alert">
|
||||
{{throttlingwarningmsg}}
|
||||
</div>
|
||||
{{/throttlingwarningmsg}}
|
||||
<form data-post-id="{{postid}}" data-content="inpage-reply-form" action="{{{reply_url}}}">
|
||||
<textarea
|
||||
name="post"
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
@mod @mod_forum
|
||||
Feature: An admin or teacher sets the post threshold for blocking and warning
|
||||
A student should not be able to post more than blocking value
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@example.com |
|
||||
| student1 | Student | 1 | student1@example.com |
|
||||
| student2 | Student | 1 | student2@example.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
| student2 | C1 | student |
|
||||
And the following "activities" exist:
|
||||
| activity | name | intro | course | idnumber | groupmode |
|
||||
| forum | Test forum name | Test forum name | C1 | forum | 0 |
|
||||
|
||||
@javascript
|
||||
Scenario: A student should not be able to post new discussion or reply to the existing discussion once the threshold block count is reached
|
||||
Given I am on the "Test forum name" "forum activity" page logged in as teacher1
|
||||
And I navigate to "Settings" in current page administration
|
||||
And I expand all fieldsets
|
||||
And I set the field "Time period for blocking" to "2 days"
|
||||
And I set the field "Post threshold for blocking" to "3"
|
||||
And I set the field "Post threshold for warning" to "2"
|
||||
And I press "Save and display"
|
||||
And I log out
|
||||
And I am on the "Test forum name" "forum activity" page logged in as student1
|
||||
When I add a new discussion to "Test forum name" forum with:
|
||||
| Subject | Test post subject one |
|
||||
| Message | Test post message one |
|
||||
And I add a new discussion to "Test forum name" forum with:
|
||||
| Subject | Test post subject two |
|
||||
| Message | Test post message two |
|
||||
And I should see "Add discussion topic"
|
||||
# Verify that when navigated to one of the topics and then click reply the warning notification is shown.
|
||||
And I click on "Test post subject two" "link"
|
||||
And I click on "Reply" "link"
|
||||
And I should see "You are approaching the posting threshold. You have posted 2 times in the last 2 days and the limit is 3 posts."
|
||||
And I click on "Test forum name" "link"
|
||||
And I add a new discussion to "Test forum name" forum with:
|
||||
| Subject | Test post subject three |
|
||||
| Message | Test post message three |
|
||||
Then I should not see "Add discussion topic"
|
||||
# Verify that no reply link available in the posts.
|
||||
And I click on "Test post subject three" "link"
|
||||
And I should not see "Reply"
|
||||
And I am on the "Test forum name" "forum activity" page
|
||||
And I click on "Test post subject two" "link"
|
||||
And I should not see "Reply"
|
||||
And I log out
|
||||
# Verify that student2 is not affected by the posts made by student1
|
||||
And I am on the "Test forum name" "forum activity" page logged in as student2
|
||||
And I should see "Add discussion topic"
|
||||
|
||||
@javascript
|
||||
Scenario: A student should see warning when the post is about to reach threshold when experimental nested discussion view is set
|
||||
Given I am on the "Test forum name" "forum activity" page logged in as teacher1
|
||||
And I navigate to "Settings" in current page administration
|
||||
And I expand all fieldsets
|
||||
And I set the field "Time period for blocking" to "2 days"
|
||||
And I set the field "Post threshold for blocking" to "3"
|
||||
And I set the field "Post threshold for warning" to "2"
|
||||
And I press "Save and display"
|
||||
And I log out
|
||||
And I am on the "Test forum name" "forum activity" page logged in as student1
|
||||
When I add a new discussion to "Test forum name" forum with:
|
||||
| Subject | Test post subject one |
|
||||
| Message | Test post message one |
|
||||
And I add a new discussion to "Test forum name" forum with:
|
||||
| Subject | Test post subject two |
|
||||
| Message | Test post message two |
|
||||
And I should see "Add discussion topic"
|
||||
#Now verify that when "Use experimental nested discussion view" is set, the user should see same warning in the Reply.
|
||||
And I follow "Preferences" in the user menu
|
||||
And I click on "Forum preferences" "link"
|
||||
And I set the field "Use experimental nested discussion view" to "Yes"
|
||||
And I press "Save changes"
|
||||
And I am on the "Test forum name" "forum activity" page
|
||||
And I click on "Test post subject two" "link"
|
||||
When I press "Reply"
|
||||
Then I should see "You are approaching the posting threshold. You have posted 2 times in the last 2 days and the limit is 3 posts."
|
||||
@@ -240,6 +240,18 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
|
||||
$this->getDataGenerator()->create_group_member(['userid' => $user->id, 'groupid' => $group->id]);
|
||||
|
||||
$this->assertTrue($capabilitymanager->can_create_discussions($user, $group->id));
|
||||
|
||||
// Test if cut off date is reached.
|
||||
$now = time();
|
||||
$forum = $this->create_forum(['cutoffdate' => $now + 86400 , 'blockafter' => 5, 'blockperiod' => 86400]);
|
||||
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
|
||||
$this->prevent_capability('mod/forum:postwithoutthrottling');
|
||||
$this->assertTrue($capabilitymanager->can_create_discussions($user));
|
||||
|
||||
$forum = $this->create_forum(['cutoffdate' => $now + 86400 , 'blockafter' => 1, 'blockperiod' => 86400]);
|
||||
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
|
||||
$this->prevent_capability('mod/forum:postwithoutthrottling');
|
||||
$this->assertFalse($capabilitymanager->can_create_discussions($user));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -622,6 +634,18 @@ class mod_forum_managers_capability_testcase extends advanced_testcase {
|
||||
$this->getDataGenerator()->create_group_member(['userid' => $user->id, 'groupid' => $group->id]);
|
||||
|
||||
$this->assertTrue($capabilitymanager->can_post_in_discussion($user, $discussion));
|
||||
|
||||
$now = time();
|
||||
$forum = $this->create_forum(['cutoffdate' => $now + 86400 , 'blockafter' => 5, 'blockperiod' => 86400]);
|
||||
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
|
||||
$this->prevent_capability('mod/forum:postwithoutthrottling');
|
||||
$this->give_capability('mod/forum:replypost');
|
||||
$this->assertTrue($capabilitymanager->can_post_in_discussion($user, $discussion));
|
||||
|
||||
$forum = $this->create_forum(['cutoffdate' => $now + 86400 , 'blockafter' => 1, 'blockperiod' => 86400]);
|
||||
$capabilitymanager = $this->managerfactory->get_capability_manager($forum);
|
||||
$this->prevent_capability('mod/forum:postwithoutthrottling');
|
||||
$this->assertFalse($capabilitymanager->can_post_in_discussion($user, $discussion));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user