Skip to content

Commit

Permalink
MDL-65508 mod_forum: Add private to the quick forum reply
Browse files Browse the repository at this point in the history
  • Loading branch information
peterRd authored and andrewnicols committed May 8, 2019
1 parent 6861c4f commit cee572a
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 16 deletions.
2 changes: 1 addition & 1 deletion mod/forum/amd/build/inpage_reply.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mod/forum/amd/build/posts_list.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mod/forum/amd/build/repository.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mod/forum/amd/src/inpage_reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,15 @@ define([
var postid = form.elements.reply.value;
var subject = form.elements.subject.value;
var currentRoot = submitButton.parents(Selectors.post.forumContent);
var isprivatereply = form.elements.privatereply != undefined ? form.elements.privatereply.checked : false;
var mode = parseInt(root.find(Selectors.post.modeSelect).get(0).value);
var newid;

if (message.length) {
showSubmitButtonLoadingIcon(submitButton);
allButtons.prop('disabled', true);

Repository.addDiscussionPost(postid, subject, message)
Repository.addDiscussionPost(postid, subject, message, isprivatereply)
.then(function(context) {
var message = context.messages.reduce(function(carry, message) {
if (message.type == 'success') {
Expand Down
3 changes: 2 additions & 1 deletion mod/forum/amd/src/posts_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ define([
postid: $(currentRoot).data('post-id'),
"reply_url": $(e.currentTarget).attr('href'),
sesskey: M.cfg.sesskey,
parentsubject: currentSubject.html()
parentsubject: currentSubject.html(),
canreplyprivately: $(e.currentTarget).data('can-reply-privately')
};

if (!currentRoot.find(Selectors.post.inpageReplyContent).length) {
Expand Down
8 changes: 6 additions & 2 deletions mod/forum/amd/src/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,17 @@ define(['core/ajax'], function(Ajax) {
return Ajax.call([request])[0];
};

var addDiscussionPost = function(postid, subject, message) {
var addDiscussionPost = function(postid, subject, message, isprivatereply) {
var request = {
methodname: 'mod_forum_add_discussion_post',
args: {
postid: postid,
message: message,
subject: subject
subject: subject,
options: [{
name: "private",
value: isprivatereply,
}]
}
};
return Ajax.call([request])[0];
Expand Down
9 changes: 8 additions & 1 deletion mod/forum/classes/local/exporters/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ protected static function define_other_properties() {
'null' => NULL_ALLOWED,
'description' => 'Whether the user can control the read status of the post',
],
'canreplyprivately' => [
'type' => PARAM_BOOL,
'null' => NULL_ALLOWED,
'description' => 'Whether the user can post a private reply',
]
]
],
'urls' => [
Expand Down Expand Up @@ -355,6 +360,7 @@ protected function get_other_values(renderer_base $output) {
$canreply = $capabilitymanager->can_reply_to_post($user, $discussion, $post);
$canexport = $capabilitymanager->can_export_post($user, $post);
$cancontrolreadstatus = $capabilitymanager->can_manually_control_post_read_status($user);
$canreplyprivately = $capabilitymanager->can_reply_privately_to_post($user, $post);

$urlfactory = $this->related['urlfactory'];
$viewurl = $canview ? $urlfactory->get_view_post_url_from_post($post) : null;
Expand Down Expand Up @@ -417,7 +423,8 @@ protected function get_other_values(renderer_base $output) {
'split' => $cansplit,
'reply' => $canreply,
'export' => $canexport,
'controlreadstatus' => $cancontrolreadstatus
'controlreadstatus' => $cancontrolreadstatus,
'canreplyprivately' => $canreplyprivately
],
'urls' => [
'view' => $viewurl ? $viewurl->out(false) : null,
Expand Down
1 change: 1 addition & 0 deletions mod/forum/templates/forum_discussion_post.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@
role="menuitem"
data-post-id="{{id}}"
data-action="collapsible-link"
data-can-reply-privately="{{canreplyprivately}}"
title="{{#str}} reply, mod_forum {{/str}}"
>
{{#str}} reply, mod_forum {{/str}}
Expand Down
8 changes: 7 additions & 1 deletion mod/forum/templates/inpage_reply.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@
<button class="btn btn-secondary" title="{{#str}} cancel, core {{/str}}" data-action="collapsible-link">
{{#str}} cancel, core {{/str}}
</button>
<button title="{{#str}} advanced, core {{/str}}" data-action="forum-advanced-reply" class="btn btn-link float-right" type="submit">
{{#canreplyprivately}}
<div class="form-check form-check-inline">
<input type="checkbox" class="form-check-input" id="private-reply" title="{{#str}} privatereply, forum {{/str}}" name="privatereply"/>
<label class="form-check-label" for="private-reply">{{#str}} privatereply, forum {{/str}}</label>
</div>
{{/canreplyprivately}}
<button title="{{#str}} advanced, forum {{/str}}" data-action="forum-advanced-reply" class="btn btn-link float-right" type="submit">
{{#str}} advanced, core {{/str}}
</button>
</div>
Expand Down
19 changes: 16 additions & 3 deletions mod/forum/tests/behat/inpage_reply.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ Feature: Students can reply to a discussion in page.
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "admin"
| teacher1 | C1 | editingteacher |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I add a "Forum" to section "1" and I fill the form with:
| Forum name | Test forum name |
Expand All @@ -23,12 +25,23 @@ Feature: Students can reply to a discussion in page.
| Subject | Discussion 2 |
| Message | Discussion contents 2, first message |
And I log out
And I log in as "student1"
And I am on "Course 1" course homepage

Scenario: Confirm inpage replies work
Given I log in as "student1"
And I am on "Course 1" course homepage
Given I reply "Discussion 2" post from "Test forum name" forum using an inpage reply with:
| post | Discussion contents 1, third message |
Then I should see "Discussion contents 1, third message"
When I reload the page
Then I should see "Discussion contents 1, third message"

Scenario: Confirm inpage replies work - private reply
Given I log in as "teacher1"
And I am on "Course 1" course homepage
And I reply "Discussion 2" post from "Test forum name" forum using an inpage reply with:
| post | Discussion contents 1, third message |
| privatereply | 1 |
Then I should see "Discussion contents 1, third message"
Then I should see "This post was made privately and is not visible to all users."
When I reload the page
Then I should see "Discussion contents 1, third message"
20 changes: 18 additions & 2 deletions mod/forum/tests/exporters_post_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,16 @@ public function test_export_post() {
$canreply = true;
$canexport = true;
$cancontrolreadstatus = true;
$canreplyprivately = true;
$capabilitymanager = new test_capability_manager(
$canview,
$canedit,
$candelete,
$cansplit,
$canreply,
$canexport,
$cancontrolreadstatus
$cancontrolreadstatus,
$canreplyprivately
);
$managerfactory = \mod_forum\local\container::get_manager_factory();
$entityfactory = \mod_forum\local\container::get_entity_factory();
Expand Down Expand Up @@ -412,6 +414,8 @@ class test_capability_manager extends capability_manager {
private $export;
/** @var bool $controlreadstatus Value for can_manually_control_post_read_status */
private $controlreadstatus;
/** @var bool $controlreadstatus Value for can_reply_privately_to_post */
private $canreplyprivatelytopost;

/**
* Constructor.
Expand All @@ -431,7 +435,8 @@ public function __construct(
bool $split = true,
bool $reply = true,
bool $export = true,
bool $controlreadstatus = true
bool $controlreadstatus = true,
bool $canreplyprivatelytopost = true
) {
$this->view = $view;
$this->edit = $edit;
Expand All @@ -440,6 +445,7 @@ public function __construct(
$this->reply = $reply;
$this->export = $export;
$this->controlreadstatus = $controlreadstatus;
$this->canreplyprivatelytopost = $canreplyprivatelytopost;
}

/**
Expand Down Expand Up @@ -522,4 +528,14 @@ public function can_export_post(stdClass $user, post_entity $post) : bool {
public function can_manually_control_post_read_status(stdClass $user) : bool {
return $this->controlreadstatus;
}

/**
* Override can_reply_privately_to_post
* @param stdClass $user
* @param post_entity $post
* @return bool
*/
public function can_reply_privately_to_post(stdClass $user, post_entity $post) : bool {
return $this->canreplyprivatelytopost;
}
}
6 changes: 4 additions & 2 deletions mod/forum/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,8 @@ public function test_mod_forum_get_discussion_posts() {
'split' => 0,
'reply' => 1,
'export' => 0,
'controlreadstatus' => 0
'controlreadstatus' => 0,
'canreplyprivately' => 0
],
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id($discussion1reply2->discussion, $discussion1reply2->id),
Expand Down Expand Up @@ -743,7 +744,8 @@ public function test_mod_forum_get_discussion_posts() {
'split' => 0,
'reply' => 1,
'export' => 0,
'controlreadstatus' => 0
'controlreadstatus' => 0,
'canreplyprivately' => 0
],
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id($discussion1reply1->discussion, $discussion1reply1->id),
Expand Down

0 comments on commit cee572a

Please sign in to comment.