Permalink
Browse files

MDL-30482 - Glossary - Fixing the capability controls for the recent …

…activity block
  • Loading branch information...
1 parent a72996f commit bcab2b21b3cedf7698a384aeeb8e61881905d84e @jsnfwlr jsnfwlr committed with nebgor Mar 22, 2012
Showing with 18 additions and 21 deletions.
  1. +7 −10 blocks/glossary_random/block_glossary_random.php
  2. +11 −11 mod/glossary/lib.php
View
17 blocks/glossary_random/block_glossary_random.php
@@ -118,23 +118,22 @@ function instance_allow_multiple() {
function get_content() {
global $USER, $CFG, $DB;
- if (!has_capability('mod/glossary:view', $this->context)) {
- return '';
- }
-
if (empty($this->config->glossary)) {
$this->content = new stdClass();
$this->content->text = get_string('notyetconfigured','block_glossary_random');
$this->content->footer = '';
return $this->content;
}
- $glossaryid = $this->config->glossary;
-
- $course = $this->page->course;
-
require_once($CFG->dirroot.'/course/lib.php');
+ $course = $this->page->course;
$modinfo = get_fast_modinfo($course);
+ $glossaryid = $this->config->glossary;
+ $cm = $modinfo->instances['glossary'][$glossaryid];
+
+ if (!has_capability('mod/glossary:view', get_context_instance(CONTEXT_MODULE, $cm->id))) {
+ return '';
+ }
if (!isset($modinfo->instances['glossary'][$glossaryid])) {
// we can get here if the glossary has been deleted, so
@@ -148,8 +147,6 @@ function get_content() {
return $this->content;
}
- $cm = $modinfo->instances['glossary'][$glossaryid];
-
if (empty($this->config->cache)) {
$this->config->cache = '';
}
View
22 mod/glossary/lib.php
@@ -329,7 +329,6 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
if (!defined('GLOSSARY_RECENT_ACTIVITY_LIMIT')) {
define('GLOSSARY_RECENT_ACTIVITY_LIMIT', 50);
}
-
$modinfo = get_fast_modinfo($course);
$ids = array();
@@ -351,18 +350,20 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
$approvals = array();
foreach ($ids as $glinstanceid => $glcmid) {
$context = get_context_instance(CONTEXT_MODULE, $glcmid);
- if (!has_capability('mod/glossary:view', $context)) {
- continue;
- }
- // get records glossary entries that are approved if user has no capability to approve entries.
- if (has_capability('mod/glossary:approve', $context)) {
- $approvals[] = ' ge.glossaryid = :glsid'.$glinstanceid.' ';
- } else {
- $approvals[] = ' (ge.approved = 1 AND ge.glossaryid = :glsid'.$glinstanceid.') ';
+ if (has_capability('mod/glossary:view', $context)) {
+ // get records glossary entries that are approved if user has no capability to approve entries.
+ if (has_capability('mod/glossary:approve', $context)) {
+ $approvals[] = ' ge.glossaryid = :glsid'.$glinstanceid.' ';
+ } else {
+ $approvals[] = ' (ge.approved = 1 AND ge.glossaryid = :glsid'.$glinstanceid.') ';
+ }
+ $params['glsid'.$glinstanceid] = $glinstanceid;
}
- $params['glsid'.$glinstanceid] = $glinstanceid;
}
+ if (count($approvals) == 0) {
+ return false;
+ }
$selectsql = 'SELECT ge.id, ge.concept, ge.approved, ge.timemodified, ge.glossaryid,
'.user_picture::fields('u',null,'userid');
$countsql = 'SELECT COUNT(*)';
@@ -387,7 +388,6 @@ function glossary_print_recent_activity($course, $viewfullnames, $timestart) {
}
echo $OUTPUT->heading(get_string('newentries', 'glossary').':');
-
$strftimerecent = get_string('strftimerecent');
$entrycount = 0;
foreach ($entries as $entry) {

0 comments on commit bcab2b2

Please sign in to comment.