From 1c45e42e3c4b7a07642a4d5a7a56c69cb159832a Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Mon, 11 Sep 2006 08:56:23 +0000 Subject: [PATCH] adding capabilities --- calendar/event.php | 4 ++-- course/lib.php | 26 +++++++++----------------- grade/index.php | 4 ++-- grade/lib.php | 45 ++++++++++++++++++++++++--------------------- lib/accesslib.php | 21 ++++++++++++++++++--- lib/datalib.php | 8 +++++--- lib/db/access.php | 28 ++++++++++++++++++++++++++++ lib/moodlelib.php | 2 +- lib/weblib.php | 8 ++++---- mod/chat/lib.php | 5 +---- user/index.php | 2 +- 11 files changed, 95 insertions(+), 58 deletions(-) diff --git a/calendar/event.php b/calendar/event.php index 9d81e95c1a..d735576c92 100644 --- a/calendar/event.php +++ b/calendar/event.php @@ -612,9 +612,9 @@ function calendar_get_allowed_types(&$allowed) { $allowed->user = true; // User events always allowed $allowed->groups = false; // This may change just below $allowed->courses = false; // This may change just below - $allowed->site = isteacher(SITEID); + $allowed->site = has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_SYSTEM, SITEID)); - if(!empty($SESSION->cal_course_referer) && $SESSION->cal_course_referer != SITEID && isteacher($SESSION->cal_course_referer, $USER->id)) { + if(!empty($SESSION->cal_course_referer) && $SESSION->cal_course_referer != SITEID && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $SESSION->cal_course_referer))) { $course = get_record('course', 'id', $SESSION->cal_course_referer); $allowed->courses = array($course->id => 1); diff --git a/course/lib.php b/course/lib.php index 927b6aaf3b..aafcfe715f 100644 --- a/course/lib.php +++ b/course/lib.php @@ -28,7 +28,6 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, global $USER, $CFG; - $isteacher = isteacher($course->id); if ($advancedfilter) { // Get all the possible users @@ -36,7 +35,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0, if ($courseusers = get_course_users($course->id, '', '', 'u.id, u.firstname, u.lastname')) { foreach ($courseusers as $courseuser) { - $users[$courseuser->id] = fullname($courseuser, $isteacher); + $users[$courseuser->id] = fullname($courseuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); } } if ($guest = get_guest()) { @@ -267,9 +266,7 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit global $db; /// Setup for group handling. - $isteacher = isteacher($course->id); - $isteacheredit = isteacheredit($course->id); - + /// If the group mode is separate, and this user does not have editing privileges, /// then only the user's group can be viewed. if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { @@ -373,7 +370,6 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); $strftimedatetime = get_string("strftimedatetime"); - $isteacher = isteacher($course->id); echo "

\n"; print_string("displayingrecords", "", $totalcount); @@ -431,7 +427,7 @@ function print_log($course, $user=0, $date=0, $order="l.time ASC", $page=0, $per echo "\n"; link_to_popup_window("/iplookup/index.php?ip=$log->ip&user=$log->userid", 'iplookup',$log->ip, 400, 700); echo "\n"; - $fullname = fullname($log, $isteacher); + $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); echo "\n"; echo " wwwroot/user/view.php?id={$log->userid}&course={$log->course}\">$fullname\n"; echo "\n"; @@ -473,7 +469,6 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); $strftimedatetime = get_string("strftimedatetime"); - $isteacher = isteacher($course->id); $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false); $filename .= '.txt'; @@ -510,7 +505,7 @@ function print_log_csv($course, $user, $date, $order='l.time DESC', $modname, $log->url = str_replace('&', '&', $log->url); // XHTML compatibility $firstField = $courses[$log->course]; - $fullname = fullname($log, $isteacher); + $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info); $text = implode("\t", $row); echo $text." \n"; @@ -546,7 +541,6 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); $strftimedatetime = get_string("strftimedatetime"); - $isteacher = isteacher($course->id); $nroPages = ceil(count($logs)/(EXCELROWS-FIRSTUSEDEXCELROW+1)); $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false); @@ -612,7 +606,7 @@ function print_log_xls($course, $user, $date, $order='l.time DESC', $modname, $excelTime=25569+$log->time/(3600*24); $myxls->write($row, 1, $excelTime, $formatDate); $myxls->write($row, 2, $log->ip, ''); - $fullname = fullname($log, $isteacher); + $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); $myxls->write($row, 3, $fullname, ''); $myxls->write($row, 4, $log->module.' '.$log->action, ''); $myxls->write($row, 5, $log->info, ''); @@ -654,7 +648,6 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, $today = mktime (0, 0, 0, $tt["mon"], $tt["mday"], $tt["year"]); $strftimedatetime = get_string("strftimedatetime"); - $isteacher = isteacher($course->id); $filename = 'logs_'.userdate(time(),get_string('backupnameformat'),99,false); $filename .= '.sxw'; @@ -708,7 +701,7 @@ function print_log_ooo($course, $user, $date, $order='l.time DESC', $modname, $log->url = str_replace('&', '&', $log->url); // XHTML compatibility $firstField = $courses[$log->course]; - $fullname = fullname($log, $isteacher); + $fullname = fullname($log, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); $row = array($firstField, userdate($log->time, $strftimedatetime), $log->ip, $fullname, $log->module.' '.$log->action, $log->info); $data[] = $row; @@ -771,7 +764,7 @@ function print_recent_activity($course) { global $CFG, $USER, $SESSION; - $isteacher = isteacher($course->id); + $isteacher = has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id)); $timestart = time() - COURSE_MAX_RECENT_PERIOD; @@ -809,7 +802,7 @@ function print_recent_activity($course) { echo "

    \n"; foreach ($users as $user) { - $fullname = fullname($user, $isteacher); + $fullname = fullname($user, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); echo '
  1. id&course=$course->id\">$fullname
  2. \n"; } echo "
\n\n"; @@ -1068,7 +1061,6 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false, if (!isset($isteacher)) { $groupbuttons = ($course->groupmode or (!$course->groupmodeforce)); $groupbuttonslink = (!$course->groupmodeforce); - $isteacher = isteacher($course->id); $isediting = isediting($course->id); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { @@ -1540,7 +1532,7 @@ function print_course($course, $width="100%") { if (!$teacher->role) { $teacher->role = $course->teacher; } - $fullname = fullname($teacher, isteacher($course->id)); // is the USER a teacher of that course + $fullname = fullname($teacher, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_COURSE, $course->id))); // is the USER a teacher of that course echo $teacher->role.': '.$fullname.'
'; } diff --git a/grade/index.php b/grade/index.php index 5130bcd4ae..75d87d33b5 100644 --- a/grade/index.php +++ b/grade/index.php @@ -14,7 +14,7 @@ require_login($course->id); - if (isteacher($course->id)) { + if (has_capability('moodle/site:accessallgroups', get_context_instance(CONTEXT_COURSE, $course->id))) { $group = get_and_set_current_group($course, $course->groupmode, $group); } else { $group = get_current_group($course->id); @@ -50,7 +50,7 @@ grade_set_uncategorized(); - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $course->id))) { switch ($action) { case "cats": grade_set_categories(); diff --git a/grade/lib.php b/grade/lib.php index 0bd9dc546d..2e1d1c263f 100644 --- a/grade/lib.php +++ b/grade/lib.php @@ -675,7 +675,7 @@ function grade_get_grades() { if ($mods) { foreach ($mods as $mod) { // hidden is a gradebook setting for an assignment and visible is a course_module setting - if (($mod->hidden != 1 && $mod->visible==1) or (isteacher($course->id) && $preferences->show_hidden==1)) { + if (($mod->hidden != 1 && $mod->visible==1) or (has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id)) && $preferences->show_hidden==1)) { $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php"; if (file_exists($libfile)) { require_once($libfile); @@ -1195,9 +1195,7 @@ function grade_download($download, $id) { error("Course ID was incorrect"); } - if (!isteacher($course->id)) { - error("Only teachers can use this page!"); - } + require_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $id)); $strgrades = get_string("grades"); $strgrade = get_string("grade"); @@ -1681,7 +1679,10 @@ function grade_view_category_grades($view_by_student) { global $USER; global $preferences; global $group; - if (!isteacher($course->id)) { + + $context = get_context_instance(CONTEXT_COURSE, $course->id); + + if (!has_capability('moodle/course:viewcoursegrades', $context)) { $view_by_student = $USER->id; } @@ -1714,7 +1715,7 @@ function grade_view_category_grades($view_by_student) { //$maxpoints = 0; $maxpercent = 0; $reprint = 0; - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $student_heading_link = get_string('student','grades'); //only set sorting links if more than one student displayed. if ($view_by_student == -1) { @@ -1726,7 +1727,7 @@ function grade_view_category_grades($view_by_student) { } } echo ''; - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $header = ''; } else { @@ -1778,7 +1779,7 @@ function grade_view_category_grades($view_by_student) { // set the links to student information based on multiview or individual... if individual go to student info... if many go to individual grades view. - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { if ($view_by_student != -1) { $student_link = ''; } @@ -1867,7 +1868,7 @@ function grade_view_category_grades($view_by_student) { } if ($first == 0) { - if (isteacher($course->id) && $view_by_student == -1) { + if (has_capability('moodle/course:viewcoursegrades', $context) && $view_by_student == -1) { $total_sort_link = ''.get_string('highgradedescending','grades').''; $total_sort_link .= ''.get_string('highgradeascending','grades').''; } @@ -1899,7 +1900,7 @@ function grade_view_category_grades($view_by_student) { $header1 .= ''; } - if (isteacher($course->id) ) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $header .= ''; } else { @@ -1917,7 +1918,7 @@ function grade_view_category_grades($view_by_student) { echo get_string('grades','grades'); } - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { helpbutton('teacher', get_string('gradehelp','grades'), 'grade'); } else { @@ -1951,7 +1952,7 @@ function grade_view_category_grades($view_by_student) { $row .= ''; } - if (isteacher($course->id) ) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $row .= ''; } $row .= ''; @@ -1977,7 +1978,9 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a global $group; // yu: fix for 5814 global $preferences; - if (!isteacher($course->id)) { + $context = get_context_instance(CONTEXT_COURSE, $course->id); + + if (!has_capability('moodle/course:viewcoursegrades', $context)) { $view_by_student = $USER->id; } @@ -2005,7 +2008,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a $reprint=0; echo '
'.$student_heading_link.''.$all_categories[$cview]['stats']['weight'].get_string('pctoftotalgrade','grades').''.$student_heading_link.'
'.$grades_by_student[$student][$cview]['stats']['weighted'].'%'.$student_link.'
'; - if (isteacher($course->id) ) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $student_heading_link = get_string('student','grades'); if ($view_by_student == -1) { $student_heading_link .='
'.get_string('sortbylastname','grades').'
'; @@ -2040,7 +2043,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a $oddrow = !$oddrow; // set the links to student information based on multiview or individual... if individual go to student info... if many go to individual grades view. - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { if ($view_by_student != -1) { $studentviewlink = ''.$grades_by_student[$student]['student_data']['lastname'].', '.$grades_by_student[$student]['student_data']['firstname'].''; } @@ -2113,7 +2116,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a $total_columns = $grade_columns; } - if (isteacher($course->id) && $view_by_student == -1) { + if (has_capability('moodle/course:viewcoursegrades', $context) && $view_by_student == -1) { $grade_sort_link = ''.get_string('highgradedescending','grades').''; $grade_sort_link .= ''.get_string('highgradeascending','grades').''; $points_sort_link = ''.get_string('pointsdescending','grades').''; @@ -2125,7 +2128,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a } $stats_link = ''.get_string('statslink','grades').''; $header .= ''; - if (isteacher($course->id) && $view_by_student == -1) { + if (has_capability('moodle/course:viewcoursegrades', $context) && $view_by_student == -1) { if ($preferences->show_points) { $header1 .= ''; } - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $header .= ''; } // adjust colcount to reflect actual number of columns output $colcount = $colcount * $grade_columns + $total_columns + 2; echo ''; } else { @@ -2887,7 +2890,7 @@ function grade_download_form($type='both') { $type = 'both'; } - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', get_context_instance(CONTEXT_COURSE, $course->id))) { echo '
'.get_string('total','grades').' '.$stats_link.''.get_string('points','grades').'('.$all_categories['stats']['totalpoints'].')'; if ($category != 'student_data' && $all_categories[$category]['stats']['bonus_points'] != 0) { @@ -2164,14 +2167,14 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a } $header1 .= '
'.$student_heading_link.'
'.get_string('allgrades','grades').''; - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { helpbutton('teacher', get_string('gradehelp','grades'), 'grade'); } else { @@ -2214,7 +2217,7 @@ function grade_view_all_grades($view_by_student) { // if mode=='grade' then we a } } } - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewcoursegrades', $context)) { $row .= ''. $studentviewlink .'
'; $options['id'] = $course->id; $options['sesskey'] = $USER->sesskey; diff --git a/lib/accesslib.php b/lib/accesslib.php index 25a365f7e5..377707bc92 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -2029,11 +2029,26 @@ function get_overridable_roles ($context) { * @param $sort - the sort order * @param $limitfrom - number of records to skip (offset) * @param $limitnum - number of records to fetch + * @param $groups - single group or array of groups - group(s) user is in */ -function get_users_by_capability($context, $capability, $fields='u.*', $sort='', $limitfrom='', $limitnum='') { +function get_users_by_capability($context, $capability, $fields='u.*', $sort='', $limitfrom='', $limitnum='', $groups='') { global $CFG; + if ($groups) { + + $groupjoin = 'LEFT JOIN '.$CFG->prefix.'groups_members gm ON gm.userid = ra.userid'; + + if (is_array($groups)) { + $groupsql = 'AND gm.id IN ('.implode(',', $groups).')'; + } else { + $groupsql = 'AND gm.id = '.$groups; + } + } else { + $groupjoin = ''; + $groupsql = ''; + } + // first get all roles with this capability in this context, or above $possibleroles = get_roles_with_capability($capability, CAP_ALLOW, $context); $validroleids = array(); @@ -2055,8 +2070,8 @@ function get_users_by_capability($context, $capability, $fields='u.*', $sort='', $roleids = '('.implode(',', $validroleids).')'; $select = ' SELECT '.$fields; - $from = ' FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id '; - $where = ' WHERE (ra.contextid = '.$context->id.' OR ra.contextid in '.$listofcontexts.') AND u.deleted = 0 AND ra.roleid in '.$roleids.' '; + $from = ' FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'role_assignments ra ON ra.userid = u.id '.$groupjoin; + $where = ' WHERE (ra.contextid = '.$context->id.' OR ra.contextid in '.$listofcontexts.') AND u.deleted = 0 AND ra.roleid in '.$roleids.' '.$groupsql; return get_records_sql($select.$from.$where.$sort, $limitfrom, $limitnum); diff --git a/lib/datalib.php b/lib/datalib.php index 7ad858af99..dcb263228e 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -699,7 +699,7 @@ function get_courses_search($searchterms, $sort='fullname ASC', $page=0, $record if ($courses) { /// Remove unavailable courses from the list foreach ($courses as $key => $course) { if (!$course->visible) { - if (!isteacher($course->id)) { + if (!has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { unset($courses[$key]); $totalcount--; } @@ -1066,7 +1066,7 @@ function get_all_instances_in_courses($modulename,$courses) { foreach ($courses as $course) { // Hide non-visible instances from students - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { $invisible = -1; } else { $invisible = 0; @@ -1125,7 +1125,7 @@ function get_all_instances_in_course($modulename, $course) { } // Hide non-visible instances from students - if (isteacher($course->id)) { + if (has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $course->id))) { $invisible = -1; } else { $invisible = 0; @@ -1246,6 +1246,8 @@ function add_to_log($courseid, $module, $action, $url='', $info='', $cm=0, $user WHERE id = \''. $userid .'\' '); if ($courseid != SITEID && !empty($courseid)) { // logins etc dont't have a courseid and isteacher will break without it. if (defined('MDL_PERFDB')) { global $PERF ; $PERF->dbqueries++;}; + + /// since we are quering the log table for lastaccess time now, can stop doing this? tables are gone if (isstudent($courseid)) { $db->Execute('UPDATE '. $CFG->prefix .'user_students SET timeaccess = \''. $timenow .'\' '. 'WHERE course = \''. $courseid .'\' AND userid = \''. $userid .'\''); diff --git a/lib/db/access.php b/lib/db/access.php index 56157dc855..fd39f5c926 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -451,6 +451,34 @@ $moodle_capabilities = array( ) ), + 'moodle/course:viewhiddenuserfields' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'guest' => CAP_PREVENT, + 'student' => CAP_PREVENT, + 'teacher' => CAP_ALLOW, + 'editingteacher' => CAP_ALLOW, + 'coursecreator' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + + 'moodle/course:viewhiddencourses' => array( + + 'captype' => 'read', + 'contextlevel' => CONTEXT_COURSE, + 'legacy' => array( + 'guest' => CAP_PREVENT, + 'student' => CAP_PREVENT, + 'teacher' => CAP_PREVENT, + 'editingteacher' => CAP_PREVENT, + 'coursecreator' => CAP_ALLOW, + 'admin' => CAP_ALLOW + ) + ), + 'moodle/course:visibility' => array( 'captype' => 'write', diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 761addaad9..bec7314446 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -1543,7 +1543,7 @@ function require_login($courseid=0, $autologinguest=true, $cm=null) { if (! $course = get_record('course', 'id', $courseid)) { error('That course doesn\'t exist'); } - if (!isteacher($courseid) && !($course->visible && course_parent_visible($course))) { + if (!has_capability('moodle/course:viewhiddencourses', get_context_instance(CONTEXT_COURSE, $courseid)) && !($course->visible && course_parent_visible($course))) { print_header(); notice(get_string('coursehidden'), $CFG->wwwroot .'/'); } diff --git a/lib/weblib.php b/lib/weblib.php index aeebd5f897..0e66df55cf 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3034,7 +3034,7 @@ function print_user($user, $course, $messageselect=false, $return=false) { } /// Get the hidden field list - if ($isteacher || $isadmin) { + if (has_capability('moodle/course:viewhiddenuserfields', get_context_instance(CONTEXT_COURSE, $course->id))) { $hiddenfields = array(); } else { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); @@ -3522,8 +3522,8 @@ function print_textarea($usehtmleditor, $rows, $cols, $width, $height, $name, $v } if ($usehtmleditor) { - - if (!empty($courseid) and isteacher($courseid)) { + // not sure if this capability is appropriate + if (!empty($courseid) and has_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $courseid))) { $str .= ($scriptcount < 1) ? ''."\n" : ''; } else { @@ -4078,7 +4078,7 @@ function navmenulist($course, $sections, $modinfo, $isteacher, $strsection, $str if ($mod->section >= 0 and $section <> $mod->section) { $thissection = $sections[$mod->section]; - if ($thissection->visible or !$course->hiddensections or $isteacher) { + if ($thissection->visible or !$course->hiddensections or has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) { $thissection->summary = strip_tags(format_string($thissection->summary,true)); if (!empty($doneheading)) { $menu[] = ''; diff --git a/mod/chat/lib.php b/mod/chat/lib.php index c98b83e305..48b7605ce8 100644 --- a/mod/chat/lib.php +++ b/mod/chat/lib.php @@ -188,8 +188,6 @@ function chat_print_recent_activity($course, $isteacher, $timestart) { return false; } - $isteacher = isteacher($course->id); - $outputstarted = false; $current = 0; foreach ($chatusers as $chatuser) { @@ -211,7 +209,6 @@ function chat_print_recent_activity($course, $isteacher, $timestart) { // needs to be fixed if (!(has_capability('mod/chat:readlog', $context) or instance_is_visible('chat', $chat))) { // Chat hidden to students - //if (!($isteacher or instance_is_visible('chat', $chat))) { // Chat hidden to students continue; } if (!$outputstarted) { @@ -222,7 +219,7 @@ function chat_print_recent_activity($course, $isteacher, $timestart) { } $current = $chatuser->chatid; } - $fullname = fullname($chatuser, $isteacher); + $fullname = fullname($chatuser, has_capability('moodle/site:viewfullnames', get_context_instance(CONTEXT_MODULE, $cm->id))); echo '
  • '.$fullname.'
  • '; } diff --git a/user/index.php b/user/index.php index 16f15484fa..866796022c 100644 --- a/user/index.php +++ b/user/index.php @@ -150,7 +150,7 @@ /// Get the hidden field list - if ($isteacher || isadmin()) { + if (has_capability('moodle/course:viewhiddenuserfields', get_context_instance(CONTEXT_COURSE, $course->id))) { $hiddenfields = array(); // teachers and admins are allowed to see everything } else { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); -- 2.39.5