Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-27814 blogs: Cleaning up contexts in blogs

All blogs pages should be in system context. Blogs are in system context just about various things (course, activity etc)
  • Loading branch information...
commit 68fc1cc279ec8cd59ac90aab9d0f1dfc6315402b 1 parent b3661ab
@ankitagarwal ankitagarwal authored
View
11 blog/edit.php
@@ -45,7 +45,6 @@
if (!empty($courseid) && empty($modid)) {
$returnurl->param('courseid', $courseid);
- $PAGE->set_context(context_course::instance($courseid));
}
// If a modid is given, guess courseid
@@ -53,13 +52,12 @@
$returnurl->param('modid', $modid);
$courseid = $DB->get_field('course_modules', 'course', array('id' => $modid));
$returnurl->param('courseid', $courseid);
- $PAGE->set_context(context_module::instance($modid));
}
-// If courseid is empty use the system context
-if (empty($courseid)) {
- $PAGE->set_context(context_system::instance());
-}
+// Blogs are always in system context.
+$sitecontext = context_system::instance();
+$PAGE->set_context($sitecontext);
+
$blogheaders = blog_get_headers();
@@ -77,7 +75,6 @@
print_error('noguestentry', 'blog');
}
-$sitecontext = context_system::instance();
if (!has_capability('moodle/blog:create', $sitecontext) && !has_capability('moodle/blog:manageentries', $sitecontext)) {
print_error('cannoteditentryorblog');
}
View
4 blog/edit_form.php
@@ -141,7 +141,7 @@ function validation($data, $files) {
// validate course association
if (!empty($data['courseassoc'])) {
- $coursecontext = context::instance_by_id($data['courseassoc'], IGNORE_MISSING);
+ $coursecontext = context::instance_by_id($data['courseassoc']);
$canassociatecourse = has_capability('moodle/blog:associatecourse', $coursecontext);
if ($coursecontext->contextlevel == CONTEXT_COURSE && $canassociatecourse) {
@@ -156,7 +156,7 @@ function validation($data, $files) {
// validate mod association
if (!empty($data['modassoc'])) {
$modcontextid = $data['modassoc'];
- $modcontext = context::instance_by_id($modcontextid, IGNORE_MISSING);
+ $modcontext = context::instance_by_id($modcontextid);
$canassociatemodule = has_capability('moodle/blog:associatemodule', $modcontext);
if ($canassociatemodule) {
View
11 blog/index.php
@@ -57,6 +57,8 @@
}
$sitecontext = context_system::instance();
+// Blogs are always in system context.
+$PAGE->set_context($sitecontext);
// check basic permissions
if ($CFG->bloglevel == BLOG_GLOBAL_LEVEL) {
@@ -199,15 +201,6 @@
$courseid = (empty($courseid)) ? SITEID : $courseid;
-if (empty($entryid) && empty($modid) && empty($groupid)) {
- $PAGE->set_context(context_user::instance($USER->id));
-} else if (!empty($modid)) {
- $PAGE->set_context(context_module::instance($modid));
-} else if (!empty($courseid)) {
- $PAGE->set_context(context_course::instance($courseid));
-} else {
- $PAGE->set_context(context_system::instance());
-}
$blogheaders = blog_get_headers();
View
14 blog/preferences.php
@@ -55,20 +55,16 @@
$PAGE->set_url($url);
$PAGE->set_pagelayout('standard');
-if ($courseid == SITEID) {
- require_login();
- $context = context_system::instance();
- $PAGE->set_context($context);
-} else {
- require_login($courseid);
- $context = context_course::instance($courseid);
-}
+$sitecontext = context_system::instance();
+$PAGE->set_context($sitecontext);
+require_login($courseid);
if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}
-require_capability('moodle/blog:view', $context);
+// The preference is site wide not blog specific. Hence user should have permissions in site level.
+require_capability('moodle/blog:view', $sitecontext);
/// If data submitted, then process and store.
Please sign in to comment.
Something went wrong with that request. Please try again.