Permalink
Browse files

MDL-27814 blogs: Deprecate associate blog caps

moodle/blog:associatemodule and moodle/blog:associatecourse should not be used
anymore as per the discussion in the issue. Everyone is free to blog about anything
they want to blog about.
  • Loading branch information...
1 parent 7ac18cf commit 4ef082980d91750571dd37392d4108419637893d @ankitagarwal ankitagarwal committed Apr 4, 2013
Showing with 42 additions and 91 deletions.
  1. +10 −21 blog/edit_form.php
  2. +8 −19 blog/lib.php
  3. +19 −34 blog/locallib.php
  4. +0 −1 lang/en/blog.php
  5. +2 −2 lang/en/role.php
  6. +3 −14 lib/db/access.php
View
@@ -86,11 +86,9 @@ function definition() {
$contextid = $entry->courseassoc;
}
- if (has_capability('moodle/blog:associatecourse', $context)) {
- $mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
- $mform->addElement('advcheckbox', 'courseassoc', get_string('associatewithcourse', 'blog', $a), null, null, array(0, $contextid));
- $mform->setDefault('courseassoc', $contextid);
- }
+ $mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
+ $mform->addElement('advcheckbox', 'courseassoc', get_string('associatewithcourse', 'blog', $a), null, null, array(0, $contextid));
+ $mform->setDefault('courseassoc', $contextid);
} else if ((!empty($entry->modassoc) || !empty($modid))) {
if (!empty($modid)) {
@@ -108,11 +106,9 @@ function definition() {
$modid = $context->instanceid;
}
- if (has_capability('moodle/blog:associatemodule', $context)) {
- $mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
- $mform->addElement('advcheckbox', 'modassoc', get_string('associatewithmodule', 'blog', $a), null, null, array(0, $context->id));
- $mform->setDefault('modassoc', $context->id);
- }
+ $mform->addElement('header', 'assochdr', get_string('associations', 'blog'));
+ $mform->addElement('advcheckbox', 'modassoc', get_string('associatewithmodule', 'blog', $a), null, null, array(0, $context->id));
+ $mform->setDefault('modassoc', $context->id);
}
}
@@ -143,11 +139,8 @@ function validation($data, $files) {
if (!empty($data['courseassoc'])) {
$coursecontext = context::instance_by_id($data['courseassoc']);
- $canassociatecourse = has_capability('moodle/blog:associatecourse', $coursecontext);
- if ($coursecontext->contextlevel == CONTEXT_COURSE && $canassociatecourse) {
- if (!is_enrolled($coursecontext) and !is_viewing($coursecontext)) {
- $errors['courseassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
- }
+ if ($coursecontext->contextlevel == CONTEXT_COURSE) {
+ $errors['courseassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
} else {
$errors['courseassoc'] = get_string('error');
}
@@ -158,8 +151,7 @@ function validation($data, $files) {
$modcontextid = $data['modassoc'];
$modcontext = context::instance_by_id($modcontextid);
- $canassociatemodule = has_capability('moodle/blog:associatemodule', $modcontext);
- if ($canassociatemodule) {
+ if ($modcontext->contextlevel == CONTEXT_MODULE) {
// get context of the mod's course
$coursecontext = $modcontext->get_course_context(true);
@@ -172,10 +164,7 @@ function validation($data, $files) {
$data['courseassoc'] = $coursecontext->id;
}
- // ensure the user has access to each mod's course
- if (!is_enrolled($modcontext) and !is_viewing($modcontext)) {
- $errors['modassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
- }
+ $errors['modassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
} else {
$errors['modassoc'] = get_string('error');
}
View
@@ -461,10 +461,6 @@ function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
// Check that the user can associate with the course
$sitecontext = context_system::instance();
- $coursecontext = context_course::instance($course->id);
- if (!has_capability('moodle/blog:associatecourse', $coursecontext)) {
- return $options;
- }
// Generate the cache key
$key = $course->id.':';
if (!empty($user)) {
@@ -477,36 +473,35 @@ function blog_get_options_for_course(stdClass $course, stdClass $user=null) {
return $courseoptions[$key];
}
- $canparticipate = (is_enrolled($coursecontext) or is_viewing($coursecontext));
- if (has_capability('moodle/blog:view', $coursecontext)) {
+ if (has_capability('moodle/blog:view', $sitecontext)) {
// We can view!
if ($CFG->bloglevel >= BLOG_SITE_LEVEL) {
// View entries about this course
$options['courseview'] = array(
'string' => get_string('viewcourseblogs', 'blog'),
- 'link' => new moodle_url('/blog/index.php', array('courseid'=>$course->id))
+ 'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id))
);
}
// View MY entries about this course
$options['courseviewmine'] = array(
'string' => get_string('viewmyentriesaboutcourse', 'blog'),
- 'link' => new moodle_url('/blog/index.php', array('courseid'=>$course->id, 'userid'=>$USER->id))
+ 'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id, 'userid' => $USER->id))
);
if (!empty($user) && ($CFG->bloglevel >= BLOG_SITE_LEVEL)) {
// View the provided users entries about this course
$options['courseviewuser'] = array(
'string' => get_string('viewentriesbyuseraboutcourse', 'blog', fullname($user)),
- 'link' => new moodle_url('/blog/index.php', array('courseid'=>$course->id, 'userid'=>$user->id))
+ 'link' => new moodle_url('/blog/index.php', array('courseid' => $course->id, 'userid' => $user->id))
);
}
}
- if (has_capability('moodle/blog:create', $sitecontext) and $canparticipate) {
+ if (has_capability('moodle/blog:create', $sitecontext)) {
// We can blog about this course
$options['courseadd'] = array(
'string' => get_string('blogaboutthiscourse', 'blog'),
- 'link' => new moodle_url('/blog/edit.php', array('action'=>'add', 'courseid'=>$course->id))
+ 'link' => new moodle_url('/blog/edit.php', array('action' => 'add', 'courseid' => $course->id))
);
}
@@ -536,12 +531,7 @@ function blog_get_options_for_module($module, $user=null) {
return $options;
}
- // Check the user can associate with the module
- $modcontext = context_module::instance($module->id);
$sitecontext = context_system::instance();
- if (!has_capability('moodle/blog:associatemodule', $modcontext)) {
- return $options;
- }
// Generate the cache key
$key = $module->id.':';
@@ -555,9 +545,8 @@ function blog_get_options_for_module($module, $user=null) {
return $moduleoptions[$key];
}
- $canparticipate = (is_enrolled($modcontext) or is_viewing($modcontext));
- if (has_capability('moodle/blog:view', $modcontext)) {
+ if (has_capability('moodle/blog:view', $sitecontext)) {
// Save correct module name for later usage.
$modulename = get_string('modulename', $module->modname);
@@ -588,7 +577,7 @@ function blog_get_options_for_module($module, $user=null) {
}
}
- if (has_capability('moodle/blog:create', $sitecontext) and $canparticipate) {
+ if (has_capability('moodle/blog:create', $sitecontext)) {
// The user can blog about this module
$options['moduleadd'] = array(
'string' => get_string('blogaboutthismodule', 'blog', $modulename),
View
@@ -679,41 +679,26 @@ public function print_entries() {
if (empty($userid) || (!empty($userid) && $userid == $USER->id)) {
- $canaddentries = true;
$courseid = optional_param('courseid', null, PARAM_INT);
- if ($modid = optional_param('modid', null, PARAM_INT)) {
- if (!has_capability('moodle/blog:associatemodule', context_module::instance($modid))) {
- $canaddentries = false;
- }
- } else if ($courseid) {
- if (!has_capability('moodle/blog:associatecourse', context_course::instance($courseid))) {
- $canaddentries = false;
- }
- }
-
- if ($canaddentries) {
- $addurl = new moodle_url("$CFG->wwwroot/blog/edit.php");
- $urlparams = array('action' => 'add',
- 'userid' => $userid,
- 'courseid' => $courseid,
- 'groupid' => optional_param('groupid', null, PARAM_INT),
- 'modid' => $modid,
- 'tagid' => optional_param('tagid', null, PARAM_INT),
- 'tag' => optional_param('tag', null, PARAM_INT),
- 'search' => optional_param('search', null, PARAM_INT));
-
- foreach ($urlparams as $var => $val) {
- if (empty($val)) {
- unset($urlparams[$var]);
- }
- }
- $addurl->params($urlparams);
-
- $addlink = '<div class="addbloglink">';
- $addlink .= '<a href="'.$addurl->out().'">'. $blogheaders['stradd'].'</a>';
- $addlink .= '</div>';
- echo $addlink;
- }
+ $modid = optional_param('modid', null, PARAM_INT);
+
+ $addurl = new moodle_url("$CFG->wwwroot/blog/edit.php");
+ $urlparams = array('action' => 'add',
+ 'userid' => $userid,
+ 'courseid' => $courseid,
+ 'groupid' => optional_param('groupid', null, PARAM_INT),
+ 'modid' => $modid,
+ 'tagid' => optional_param('tagid', null, PARAM_INT),
+ 'tag' => optional_param('tag', null, PARAM_INT),
+ 'search' => optional_param('search', null, PARAM_INT));
+
+ $urlparams = array_filter($urlparams);
+ $addurl->params($urlparams);
+
+ $addlink = '<div class="addbloglink">';
+ $addlink .= '<a href="'.$addurl->out().'">'. $blogheaders['stradd'].'</a>';
+ $addlink .= '</div>';
+ echo $addlink;
}
}
View
@@ -106,7 +106,6 @@
$string['invalidurl'] = 'This URL is unreachable';
$string['linktooriginalentry'] = 'Link to original blog entry';
$string['maxexternalblogsperuser'] = 'Maximum number of external blogs per user';
-$string['mustassociatecourse'] = 'If you are publishing to course or group members, you must associate a course with this entry';
$string['name'] = 'Name';
$string['name_help'] = 'Enter a descriptive name for your external blog. (If no name is supplied, the title of your external blog will be used).';
$string['noentriesyet'] = 'No visible entries here';
View
@@ -83,8 +83,8 @@
$string['badges:viewotherbadges'] = 'View public badges in other users\' profiles';
$string['block:edit'] = 'Edit a block\'s settings';
$string['block:view'] = 'View block';
-$string['blog:associatecourse'] = 'Associate blog entries with courses';
-$string['blog:associatemodule'] = 'Associate blog entries with activity modules';
+$string['blog:associatecourse'] = 'This capability is deprecated and does nothing.';
+$string['blog:associatemodule'] = 'This capability is deprecated and does nothing.';
$string['blog:create'] = 'Create new blog entries';
$string['blog:manageentries'] = 'Edit and manage entries';
$string['blog:manageexternal'] = 'Edit and manage external blogs';
View
@@ -1127,30 +1127,19 @@
)
),
+ // TODO: Remove 'moodle/blog:associatecourse' and 'moodle/blog:associatemodule' after a few releases.
'moodle/blog:associatecourse' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
- 'archetypes' => array(
- 'student' => CAP_ALLOW,
- 'user' => CAP_ALLOW,
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- )
+ 'archetypes' => array()
),
'moodle/blog:associatemodule' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
- 'archetypes' => array(
- 'student' => CAP_ALLOW,
- 'user' => CAP_ALLOW,
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'manager' => CAP_ALLOW
- )
+ 'archetypes' => array()
),
'moodle/calendar:manageownentries' => array( // works in CONTEXT_SYSTEM only

0 comments on commit 4ef0829

Please sign in to comment.