mirror of
https://github.com/moodle/moodle.git
synced 2025-01-29 11:46:19 +01:00
MDL-27814 blogs: Refactoring code to use proper context and such
Based on the decisions made in the issue, most places in blog should use site context. There are also minor other refactoring to support all changes made in the issue.
This commit is contained in:
parent
4ef082980d
commit
f42d2a22bc
@ -139,9 +139,7 @@ class blog_edit_form extends moodleform {
|
||||
if (!empty($data['courseassoc'])) {
|
||||
$coursecontext = context::instance_by_id($data['courseassoc']);
|
||||
|
||||
if ($coursecontext->contextlevel == CONTEXT_COURSE) {
|
||||
$errors['courseassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
|
||||
} else {
|
||||
if ($coursecontext->contextlevel != CONTEXT_COURSE) {
|
||||
$errors['courseassoc'] = get_string('error');
|
||||
}
|
||||
}
|
||||
@ -163,8 +161,6 @@ class blog_edit_form extends moodleform {
|
||||
} else {
|
||||
$data['courseassoc'] = $coursecontext->id;
|
||||
}
|
||||
|
||||
$errors['modassoc'] = get_string('studentnotallowed', '', fullname($USER, true));
|
||||
} else {
|
||||
$errors['modassoc'] = get_string('error');
|
||||
}
|
||||
|
@ -124,11 +124,9 @@ if (!empty($courseid)) {
|
||||
}
|
||||
|
||||
$courseid = $course->id;
|
||||
$coursecontext = context_course::instance($course->id);
|
||||
|
||||
require_login($course);
|
||||
|
||||
if (!has_capability('moodle/blog:view', $coursecontext)) {
|
||||
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
||||
print_error('cannotviewcourseblog', 'blog');
|
||||
}
|
||||
} else {
|
||||
@ -152,7 +150,7 @@ if (!empty($groupid)) {
|
||||
$courseid = $course->id;
|
||||
require_login($course);
|
||||
|
||||
if (!has_capability('moodle/blog:view', $coursecontext)) {
|
||||
if (!has_capability('moodle/blog:view', $sitecontext)) {
|
||||
print_error(get_string('cannotviewcourseorgroupblog', 'blog'));
|
||||
}
|
||||
|
||||
@ -210,7 +208,7 @@ if ($CFG->enablerssfeeds) {
|
||||
$thingid = null;
|
||||
list($thingid, $rsscontext, $filtertype) = blog_rss_get_params($blogheaders['filters']);
|
||||
if (empty($rsscontext)) {
|
||||
$rsscontext = get_system_context();
|
||||
$rsscontext = context_system::instance();
|
||||
}
|
||||
$rsstitle = $blogheaders['heading'];
|
||||
|
||||
|
@ -123,26 +123,15 @@ function blog_rss_get_params($filters) {
|
||||
|
||||
if (!$filters) {
|
||||
$thingid = SITEID;
|
||||
$rsscontext = $sitecontext;
|
||||
$filtertype = 'site';
|
||||
} else if (array_key_exists('course', $filters)) {
|
||||
$thingid = $filters['course'];
|
||||
|
||||
$coursecontext = context_course::instance($thingid);
|
||||
$rsscontext = $coursecontext;
|
||||
|
||||
$filtertype = 'course';
|
||||
} else if (array_key_exists('user', $filters)) {
|
||||
$thingid = $filters['user'];
|
||||
|
||||
$usercontext = context_user::instance($thingid);
|
||||
$rsscontext = $usercontext;
|
||||
|
||||
$filtertype = 'user';
|
||||
} else if (array_key_exists('group', $filters)) {
|
||||
$thingid = $filters['group'];
|
||||
|
||||
$rsscontext = $sitecontext; //is this the context we should be using for group blogs?
|
||||
$filtertype = 'group';
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user