Skip to content

Commit

Permalink
Merge branch 'MDL-68900-m39' of https://github.com/sumitnegi933/moodle
Browse files Browse the repository at this point in the history
…into MOODLE_39_STABLE
  • Loading branch information
vmdef committed Oct 14, 2020
2 parents 31d3a65 + 2e21c78 commit 22f34e8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 26 deletions.
4 changes: 2 additions & 2 deletions mod/forum/externallib.php
Expand Up @@ -2241,7 +2241,7 @@ public static function get_discussion_posts_by_userid(int $userid = 0, int $cmid
$parentposts = [];
if ($parentids) {
$parentposts = $postbuilder->build(
$user,
$USER,
[$forum],
[$discussion],
$postvault->get_from_ids(array_values($parentids))
Expand All @@ -2257,7 +2257,7 @@ public static function get_discussion_posts_by_userid(int $userid = 0, int $cmid
'timecreated' => $firstpost->get_time_created(),
'authorfullname' => $discussionauthor->get_full_name(),
'posts' => [
'userposts' => $postbuilder->build($user, [$forum], [$discussion], $posts),
'userposts' => $postbuilder->build($USER, [$forum], [$discussion], $posts),
'parentposts' => $parentposts,
],
];
Expand Down
72 changes: 48 additions & 24 deletions mod/forum/tests/externallib_test.php
Expand Up @@ -2609,6 +2609,7 @@ public function test_delete_post_other_user_post() {
* Test get forum posts by user id.
*/
public function test_mod_forum_get_discussion_posts_by_userid() {
global $DB;
$this->resetAfterTest(true);

$urlfactory = mod_forum\local\container::get_url_factory();
Expand Down Expand Up @@ -2720,9 +2721,20 @@ public function test_mod_forum_get_discussion_posts_by_userid() {

// Following line enrol and assign default role id to the user.
// So the user automatically gets mod/forum:viewdiscussion on all forums of the course.
$this->getDataGenerator()->enrol_user($user1->id, $course1->id);
$this->getDataGenerator()->enrol_user($user1->id, $course1->id, 'teacher');
$this->getDataGenerator()->enrol_user($user2->id, $course1->id);

// Changed display period for the discussions in past.
$time = time();
$discussion = new \stdClass();
$discussion->id = $discussion1->id;
$discussion->timestart = $time - 200;
$discussion->timeend = $time - 100;
$DB->update_record('forum_discussions', $discussion);
$discussion = new \stdClass();
$discussion->id = $discussion2->id;
$discussion->timestart = $time - 200;
$discussion->timeend = $time - 100;
$DB->update_record('forum_discussions', $discussion);
// Create what we expect to be returned when querying the discussion.
$expectedposts = array(
'discussions' => array(),
Expand Down Expand Up @@ -2771,34 +2783,36 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'view' => true,
'edit' => true,
'delete' => true,
'split' => false,
'split' => true,
'reply' => true,
'export' => false,
'controlreadstatus' => false,
'canreplyprivately' => false,
'canreplyprivately' => true,
'selfenrol' => false
],
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id(
$discussion1reply1->discussion, $discussion1reply1->id)->out(false),
$discussion1reply1->discussion, $discussion1reply1->id)->out(false),
'viewisolated' => $isolatedurluser->out(false),
'viewparent' => $urlfactory->get_view_post_url_from_post_id(
$discussion1reply1->discussion, $discussion1reply1->parent)->out(false),
$discussion1reply1->discussion, $discussion1reply1->parent)->out(false),
'edit' => (new moodle_url('/mod/forum/post.php', [
'edit' => $discussion1reply1->id
'edit' => $discussion1reply1->id
]))->out(false),
'delete' => (new moodle_url('/mod/forum/post.php', [
'delete' => $discussion1reply1->id
'delete' => $discussion1reply1->id
]))->out(false),
'split' => (new moodle_url('/mod/forum/post.php', [
'prune' => $discussion1reply1->id
]))->out(false),
'split' => null,
'reply' => (new moodle_url('/mod/forum/post.php#mformforum', [
'reply' => $discussion1reply1->id
'reply' => $discussion1reply1->id
]))->out(false),
'export' => null,
'markasread' => null,
'markasunread' => null,
'discuss' => $urlfactory->get_discussion_view_url_from_discussion_id(
$discussion1reply1->discussion)->out(false),
$discussion1reply1->discussion)->out(false),
],
]
],
Expand Down Expand Up @@ -2831,22 +2845,26 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'charcount' => null,
'capabilities' => [
'view' => true,
'edit' => false,
'delete' => false,
'edit' => true,
'delete' => true,
'split' => false,
'reply' => true,
'export' => false,
'controlreadstatus' => false,
'canreplyprivately' => false,
'canreplyprivately' => true,
'selfenrol' => false
],
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id(
$discussion1firstpostobject->discussion, $discussion1firstpostobject->id)->out(false),
'viewisolated' => $isolatedurlparent->out(false),
'viewparent' => null,
'edit' => null,
'delete' => null,
'edit' => (new moodle_url('/mod/forum/post.php', [
'edit' => $discussion1firstpostobject->id
]))->out(false),
'delete' => (new moodle_url('/mod/forum/post.php', [
'delete' => $discussion1firstpostobject->id
]))->out(false),
'split' => null,
'reply' => (new moodle_url('/mod/forum/post.php#mformforum', [
'reply' => $discussion1firstpostobject->id
Expand Down Expand Up @@ -2904,11 +2922,11 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'view' => true,
'edit' => true,
'delete' => true,
'split' => false,
'split' => true,
'reply' => true,
'export' => false,
'controlreadstatus' => false,
'canreplyprivately' => false,
'canreplyprivately' => true,
'selfenrol' => false
],
'urls' => [
Expand All @@ -2923,7 +2941,9 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'delete' => (new moodle_url('/mod/forum/post.php', [
'delete' => $discussion2reply1->id
]))->out(false),
'split' => null,
'split' => (new moodle_url('/mod/forum/post.php', [
'prune' => $discussion2reply1->id
]))->out(false),
'reply' => (new moodle_url('/mod/forum/post.php#mformforum', [
'reply' => $discussion2reply1->id
]))->out(false),
Expand Down Expand Up @@ -2964,22 +2984,26 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'charcount' => null,
'capabilities' => [
'view' => true,
'edit' => false,
'delete' => false,
'edit' => true,
'delete' => true,
'split' => false,
'reply' => true,
'export' => false,
'controlreadstatus' => false,
'canreplyprivately' => false,
'canreplyprivately' => true,
'selfenrol' => false
],
'urls' => [
'view' => $urlfactory->get_view_post_url_from_post_id(
$discussion2firstpostobject->discussion, $discussion2firstpostobject->id)->out(false),
'viewisolated' => $isolatedurlparent->out(false),
'viewparent' => null,
'edit' => null,
'delete' => null,
'edit' => (new moodle_url('/mod/forum/post.php', [
'edit' => $discussion2firstpostobject->id
]))->out(false),
'delete' => (new moodle_url('/mod/forum/post.php', [
'delete' => $discussion2firstpostobject->id
]))->out(false),
'split' => null,
'reply' => (new moodle_url('/mod/forum/post.php#mformforum', [
'reply' => $discussion2firstpostobject->id
Expand Down
6 changes: 6 additions & 0 deletions mod/forum/upgrade.txt
@@ -1,6 +1,12 @@
This files describes API changes in /mod/forum/*,
information provided here is intended especially for developers.

=== 3.9.3 ===

* Changes in external function mod_forum_external::get_discussion_posts_by_userid
Now returns the posts of a given user checking the current user capabilities ($USER, the user who is requesting the posts).
Previously, it returned the posts checking the capabilities of the user that created the posts.

=== 3.8 ===

* The following functions have been finally deprecated and can not be used anymore:
Expand Down

0 comments on commit 22f34e8

Please sign in to comment.