Skip to content

Commit 5468d21

Browse files
Only allow voting and replying when post is reviewed
1 parent 952f7b5 commit 5468d21

File tree

13 files changed

+69
-113
lines changed

13 files changed

+69
-113
lines changed

amd/build/reviewing.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/build/reviewing.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

amd/src/reviewing.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export function init() {
3333
Prefetch.prefetchStrings('mod_moodleoverflow',
3434
['post_was_approved', 'jump_to_next_post_needing_review', 'there_are_no_posts_needing_review', 'post_was_rejected']);
3535

36-
window.console.log('INIT1!');
37-
3836
const root = document.getElementById('moodleoverflow-posts');
3937
root.onclick = async(e) => {
4038
const action = e.target.getAttribute('data-moodleoverflow-action');
@@ -43,8 +41,6 @@ export function init() {
4341
return;
4442
}
4543

46-
window.console.log('INIT!');
47-
4844
const post = e.target.closest('*[data-moodleoverflow-postid]');
4945
const reviewRow = e.target.closest('.reviewrow');
5046
const postID = post.getAttribute('data-moodleoverflow-postid');
@@ -67,6 +63,7 @@ export function init() {
6763
message += await getString('there_are_no_posts_needing_review', 'mod_moodleoverflow');
6864
}
6965
reviewRow.innerHTML = message;
66+
post.classList.remove("pendingreview");
7067
} else if (action === 'reject') {
7168
reviewRow.innerHTML = '.';
7269
reviewRow.innerHTML = await Templates.render('mod_moodleoverflow/reject_post_form', {});

classes/ratings.php

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static function moodleoverflow_add_rating($moodleoverflow, $postid, $rati
8282
$coursecontext = \context_course::instance($course->id);
8383

8484
// Redirect the user if capabilities are missing.
85-
$canrate = self::moodleoverflow_user_can_rate($moodleoverflow, $cm, $modulecontext, $userid);
85+
$canrate = self::moodleoverflow_user_can_rate($post, $modulecontext, $userid);
8686
if (!$canrate) {
8787

8888
// Catch unenrolled users.
@@ -784,13 +784,12 @@ private static function moodleoverflow_update_rating_record($postid, $rating, $u
784784
* Check if a user can rate the post.
785785
*
786786
* @param object $moodleoverflow
787-
* @param null $cm
788-
* @param null $modulecontext
787+
* @param \context_module $modulecontext
789788
* @param null|int $userid
790789
*
791790
* @return bool
792791
*/
793-
private static function moodleoverflow_user_can_rate($moodleoverflow, $cm = null, $modulecontext = null, $userid = null) {
792+
private static function moodleoverflow_user_can_rate($post, $modulecontext, $userid = null) {
794793
global $USER;
795794
if (!$userid) {
796795
// Guests and non-logged-in users can not rate.
@@ -800,20 +799,8 @@ private static function moodleoverflow_user_can_rate($moodleoverflow, $cm = null
800799
$userid = $USER->id;
801800
}
802801

803-
// Retrieve the coursemodule.
804-
if (!$cm) {
805-
if (!$cm = get_coursemodule_from_instance('moodleoverflow', $moodleoverflow->id, $moodleoverflow->course)) {
806-
throw new moodle_exception('invalidcoursemodule');
807-
}
808-
}
809-
810-
// Get the context if not set in the parameters.
811-
if (!$modulecontext) {
812-
$modulecontext = context_module::instance($cm->id);
813-
}
814-
815802
// Check the capability.
816-
return has_capability('mod/moodleoverflow:ratepost', $modulecontext, $userid);
803+
return has_capability('mod/moodleoverflow:ratepost', $modulecontext, $userid) && $post->reviewed == 1;
817804
}
818805

819806
}

classes/review.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public static function get_first_review_post($afterpostid = null) {
9898
$addwhere = ' AND id != :notpostid ';
9999
$params['notpostid'] = $afterpostid;
100100
}
101-
$record = $DB->get_record_sql(
101+
$record = $DB->get_record_sql(
102102
'SELECT id as postid, discussion as discussionid FROM {moodleoverflow_posts} ' .
103103
"WHERE reviewed = 0 $addwhere " .
104104
"ORDER BY $orderby discussion, id " .

0 commit comments

Comments
 (0)