From 3140dc600d331693da14366c94de9e0b14c1aa10 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Mon, 19 Mar 2007 02:46:33 +0000 Subject: [PATCH] backporting MDL-8578 students can post and reply in news forums --- mod/forum/db/access.php | 26 ++++++++++++++++++++++++++ mod/forum/discuss.php | 8 +++++++- mod/forum/lib.php | 22 +++++++++++++++++----- mod/forum/version.php | 2 +- 4 files changed, 51 insertions(+), 7 deletions(-) diff --git a/mod/forum/db/access.php b/mod/forum/db/access.php index 2519629d475..d8c0ba83bef 100644 --- a/mod/forum/db/access.php +++ b/mod/forum/db/access.php @@ -85,6 +85,32 @@ $mod_forum_capabilities = array( ) ), + 'mod/forum:addnews' => array( + + 'riskbitmask' => RISK_SPAM, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + + 'mod/forum:replynews' => array( + + 'riskbitmask' => RISK_SPAM, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_MODULE, + 'legacy' => array( + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + 'mod/forum:viewrating' => array( 'captype' => 'read', diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 380ed95d7ea..97c7e285deb 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -165,8 +165,14 @@ /// If so, make sure the current person is allowed to see this discussion /// Also, if we know they should be able to reply, then explicitly set $canreply + if ($forum->type == 'news') { + $capname = 'mod/forum:replynews'; + } else { + $capname = 'mod/forum:replypost'; + } + $groupmode = groupmode($course, $cm); - if ($canreply = has_capability('mod/forum:replypost', $modcontext)) { /// Check capability first, if not allowed, no point checking further + if ($canreply = has_capability($capname, $modcontext)) { /// Check capability first, if not allowed, no point checking further // now check groups just in case user is not a member of group in which he can post diff --git a/mod/forum/lib.php b/mod/forum/lib.php index f988924f878..a7de2f0cef3 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3043,7 +3043,13 @@ function forum_user_can_post_discussion($forum, $currentgroup=false, $groupmode= } $context = get_context_instance(CONTEXT_MODULE, $cm->id); - if (!has_capability('mod/forum:startdiscussion', $context)) { + if ($forum->type == 'news') { + $capname = 'mod/forum:addnews'; + } else { + $capname = 'mod/forum:startdiscussion'; + } + + if (!has_capability($capname, $context)) { return false; } @@ -3076,12 +3082,18 @@ function forum_user_can_post($forum, $user=NULL) { error('Course Module ID was incorrect'); } $context = get_context_instance(CONTEXT_MODULE, $cm->id); - - if (isset($user)) { - $canreply = has_capability('mod/forum:replypost', $context, $user->id, false) + + if ($forum->type == 'news') { + $capname = 'mod/forum:replynews'; + } else { + $capname = 'mod/forum:replypost'; + } + + if (!empty($user)) { + $canreply = has_capability($capname, $context, $user->id, false) && !has_capability('moodle/legacy:guest', $context, $user->id, false); } else { - $canreply = has_capability('mod/forum:replypost', $context, NULL, false) + $canreply = has_capability($capname, $context, NULL, false) && !has_capability('moodle/legacy:guest', $context, NULL, false); } diff --git a/mod/forum/version.php b/mod/forum/version.php index d76c644d29f..d390a9316d8 100644 --- a/mod/forum/version.php +++ b/mod/forum/version.php @@ -5,7 +5,7 @@ // This fragment is called by /admin/index.php //////////////////////////////////////////////////////////////////////////////// -$module->version = 2006092002; +$module->version = 2006092003; $module->requires = 2006082600; // Requires this Moodle version $module->cron = 60;