Commit c718dd57 authored by skodak's avatar skodak
Browse files

MDL-8578 new capability for adding and replying to news in forum

parent 18b07efa
......@@ -69,6 +69,7 @@ $string['existingsubscribers'] = 'Existing subscribers';
$string['forcesubscribe'] = 'Force everyone to be subscribed';
$string['forcesubscribeq'] = 'Force everyone to be subscribed?';
$string['forum'] = 'Forum';
$string['forum:addnews'] = 'Add news';
$string['forum:createattachment'] = 'Create attachments';
$string['forum:deleteanypost'] = 'Delete any posts (anytime)';
$string['forum:deleteownpost'] = 'Delete own posts (within deadline)';
......@@ -78,6 +79,7 @@ $string['forum:movediscussions'] = 'Move discussions';
$string['forum:throttlingapplies'] = 'Throttling applies';
$string['forum:rate'] = 'Rate posts';
$string['forum:replypost'] = 'Reply to posts';
$string['forum:replynews'] = 'Reply to news';
$string['forum:splitdiscussions'] = 'Split discussions';
$string['forum:startdiscussion'] = 'Start new discussions';
$string['forum:viewanyrating'] = 'View any ratings';
......
......@@ -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',
......
......@@ -190,7 +190,13 @@
(ismember($discussion->groupid) || $mygroupid == $discussion->groupid) );
}
} else {
if (!has_capability('mod/forum:replypost', $modcontext)) {
if ($forum->type == 'news') {
$capname = 'mod/forum:replynews';
} else {
$capname = 'mod/forum:replypost';
}
if (!has_capability($capname, $modcontext)) {
$coursecontext = get_context_instance(CONTEXT_COURSE, $course->id);
if (!has_capability('moodle/legacy:guest', $coursecontext, NULL, false)) { // User is a guest here!
$canreply = false;
......
......@@ -2923,7 +2923,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;
}
......@@ -2957,11 +2963,17 @@ function forum_user_can_post($forum, $user=NULL) {
}
$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);
}
......
......@@ -527,7 +527,7 @@
$timemessage = 4;
}
if ($fromform->mailnow) {
if (!empty($fromform->mailnow)) {
$message .= get_string("postmailnow", "forum");
$timemessage = 4;
} else {
......
......@@ -5,8 +5,8 @@
// This fragment is called by /admin/index.php
////////////////////////////////////////////////////////////////////////////////
$module->version = 2007020200;
$module->requires = 2007020200; // Requires this Moodle version
$module->version = 2007020201;
$module->requires = 2007020201; // Requires this Moodle version
$module->cron = 60;
?>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment