Skip to content

Commit

Permalink
MDL-46218 reshuffled access checks in blog and notes
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjdavis committed Jul 14, 2014
1 parent 5fd0df9 commit e9fb99b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 50 deletions.
41 changes: 20 additions & 21 deletions blog/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@
$action = required_param('action', PARAM_ALPHA);
$id = optional_param('entryid', 0, PARAM_INT);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$modid = optional_param('modid', 0, PARAM_INT); // To associate the entry with a module instance
$courseid = optional_param('courseid', 0, PARAM_INT); // To associate the entry with a course
$modid = optional_param('modid', 0, PARAM_INT); // To associate the entry with a module instance.
$courseid = optional_param('courseid', 0, PARAM_INT); // To associate the entry with a course.

if ($action == 'edit') {
$id = required_param('entryid', PARAM_INT);
}

$PAGE->set_url('/blog/edit.php', array('action' => $action, 'entryid' => $id, 'confirm' => $confirm, 'modid' => $modid, 'courseid' => $courseid));

Expand All @@ -41,6 +45,20 @@
$id = null;
}

// Blogs are always in system context.
$sitecontext = context_system::instance();
$PAGE->set_context($sitecontext);

require_login($courseid);

if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

if (isguestuser()) {
print_error('noguestentry', 'blog');
}

$returnurl = new moodle_url('/blog/index.php');

if (!empty($courseid) && empty($modid)) {
Expand All @@ -54,27 +72,8 @@
$returnurl->param('courseid', $courseid);
}

// Blogs are always in system context.
$sitecontext = context_system::instance();
$PAGE->set_context($sitecontext);


$blogheaders = blog_get_headers();

require_login($courseid);

if ($action == 'edit') {
$id = required_param('entryid', PARAM_INT);
}

if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

if (isguestuser()) {
print_error('noguestentry', 'blog');
}

if (!has_capability('moodle/blog:create', $sitecontext) && !has_capability('moodle/blog:manageentries', $sitecontext)) {
print_error('cannoteditentryorblog');
}
Expand Down
26 changes: 13 additions & 13 deletions blog/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
}
$PAGE->set_url('/blog/index.php', $url_params);

if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

//correct tagid if a text tag is provided as a param
if (!empty($tag)) {
if ($tagrec = $DB->get_record('tag', array('name' => $tag))) {
Expand All @@ -47,15 +43,6 @@
}
}

// add courseid if modid or groupid is specified: This is used for navigation and title
if (!empty($modid) && empty($courseid)) {
$courseid = $DB->get_field('course_modules', 'course', array('id'=>$modid));
}

if (!empty($groupid) && empty($courseid)) {
$courseid = $DB->get_field('groups', 'courseid', array('id'=>$groupid));
}

$sitecontext = context_system::instance();
// Blogs are always in system context.
$PAGE->set_context($sitecontext);
Expand Down Expand Up @@ -84,6 +71,19 @@
print_error('blogdisable', 'blog');
}

if (empty($CFG->enableblogs)) {
print_error('blogdisable', 'blog');
}

// Add courseid if modid or groupid is specified: This is used for navigation and title.
if (!empty($modid) && empty($courseid)) {
$courseid = $DB->get_field('course_modules', 'course', array('id' => $modid));
}

if (!empty($groupid) && empty($courseid)) {
$courseid = $DB->get_field('groups', 'courseid', array('id' => $groupid));
}


if (!$userid && has_capability('moodle/blog:view', $sitecontext) && $CFG->bloglevel > BLOG_USER_LEVEL) {
if ($entryid) {
Expand Down
17 changes: 8 additions & 9 deletions notes/delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@
print_error('invalidcourseid');
}

// locate user information
if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
print_error('invaliduserid');
}

// require login to access notes
require_login($course);

if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}

if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
print_error('invaliduserid');
}

// locate context information
$context = context_course::instance($course->id);

Expand All @@ -34,10 +37,6 @@
print_error('nopermissiontodelete', 'notes');
}

if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}

if (data_submitted() && confirm_sesskey()) {
//if data was submitted and is valid, then delete note
$returnurl = $CFG->wwwroot . '/notes/index.php?course=' . $course->id . '&user=' . $note->userid;
Expand Down
13 changes: 6 additions & 7 deletions notes/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,19 @@
print_error('invalidcourseid');
}

/// locate user information
if (!$user = $DB->get_record('user', array('id'=>$note->userid))) {
print_error('invaliduserid');
}

/// require login to access notes
require_login($course);

if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
}

/// locate context information
$context = context_course::instance($course->id);
require_capability('moodle/notes:manage', $context);

if (empty($CFG->enablenotes)) {
print_error('notesdisabled', 'notes');
if (!$user = $DB->get_record('user', array('id' => $note->userid))) {
print_error('invaliduserid');
}

/// create form
Expand Down

0 comments on commit e9fb99b

Please sign in to comment.