]> git.mjollnir.org Git - moodle.git/commitdiff
adding capabilities
authortoyomoyo <toyomoyo>
Tue, 5 Sep 2006 08:50:23 +0000 (08:50 +0000)
committertoyomoyo <toyomoyo>
Tue, 5 Sep 2006 08:50:23 +0000 (08:50 +0000)
15 files changed:
calendar/set.php
course/editsection.php
course/format/lams/format.php
course/format/topics/format.php
course/format/weeks/format.php
course/format/weekscss/format.php
course/import.php
course/lib.php
course/recent.php
course/report.php
course/report/outline/index.php
course/user.php
file.php
grade/exceptions.php
lib/db/access.php

index 2c3f018ee66c3a0f173787502ac5815ba2a10201..e1496def934dd1f5fad4c986e4e6ff7fedc47397 100644 (file)
@@ -64,7 +64,6 @@
                 calendar_set_referring_course(0);
             }
             else {
-                // We don't check for membership anymore: if(isstudent($id, $USER->id) || isteacher($id, $USER->id)) {
                 if(get_record('course', 'id', $id) === false) {
                     // There is no such course
                     $SESSION->cal_courses_shown = array();
index 2e7437b06377f98f319fc7d572349373213e5ac0..c963f28b331b832b55891e6cd45d646104db768f 100644 (file)
         error("Could not find the course!");
     }
 
-    if (!isteacher($course->id)) {
-        error("Only teachers can edit this!");
-    }
-
+    require_capability('moodle/course:update', get_context_instance(CONTEXT_COURSE, $id));
 
 /// If data submitted, then process and store.
 
index c10e6b3a36a3767d3c230923e9378fea31c84f2b..de01892fe14286002385a89f104b4b6c167be06f 100644 (file)
@@ -30,7 +30,9 @@ if ($topic != -1) {
     }
 }
 
-if (($marker >=0) and isteacher($course->id) and confirm_sesskey()) {
+$context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+if (($marker >=0) and has_capability('moodle/course:setcurrentsection', $context) and confirm_sesskey()) {
     $course->marker = $marker;
     if (! set_field("course", "marker", $marker, "id", $course->id)) {
         error("Could not mark that topic for this course");
@@ -216,7 +218,7 @@ while ($section <= $course->numsections) {
         }
     }
 
-    $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
+    $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
 
     if (!empty($displaysection) and $displaysection != $section) {
         if ($showsection) {
@@ -249,7 +251,7 @@ while ($section <= $course->numsections) {
         echo '<td class="left side">&nbsp;</td>';
 
         echo '<td class="content">';
-        if (!isteacher($course->id) and !$thissection->visible) {   // Hidden for students
+        if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
             echo get_string('notavailable');
         } else {
             echo '<div class="summary">';
index 6280ba86a9deaf0da40025a27a9daca9f973f9e6..c2b63c1ad73acc099f667b83ea325c87079be819 100644 (file)
@@ -35,7 +35,9 @@
         }
     }
 
-    if (($marker >=0) && isteacher($course->id) && confirm_sesskey()) {
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
+
+    if (($marker >=0) && has_capability('moodle/course:setcurrentsection', $context) && confirm_sesskey()) {
         $course->marker = $marker;
         if (! set_field("course", "marker", $marker, "id", $course->id)) {
             error("Could not mark that topic for this course");
             }
         }
 
-        $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
+        $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
 
         if (!empty($displaysection) and $displaysection != $section) {
             if ($showsection) {
             echo '<td class="left side">'.$section.'</td>';
 
             echo '<td class="content">';
-            if (!isteacher($course->id) and !$thissection->visible) {   // Hidden for students
+            if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
                 echo get_string('notavailable');
             } else {
                 echo '<div class="summary">';
index 73b47780420d81f8b4d273a4925b581f8994e892..f2646d219e444611ddb5f998dfbe41018d98746d 100644 (file)
@@ -48,7 +48,7 @@
         $strmovedown = get_string('movedown');
     }
 
-
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
 /// Layout the whole page as three big columns.
     echo '<table id="layout-table" cellspacing="0"><tr>';
 
             }
         }
 
-        $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
+        $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
 
         if (!empty($displaysection) and $displaysection != $section) {  // Check this week is visible
             if ($showsection) {
             echo '<td class="left side">&nbsp;</td>';
 
             echo '<td class="content">';
-            if (!isteacher($course->id) and !$thissection->visible) {   // Hidden for students
+            if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
                 echo '<div class="weekdates">'.$weekday.' - '.$endweekday.' ('.get_string('notavailable').')</div>';
 
             } else {
index 395760291e500f4f632482dcb44de6bf2cc7fd63..3168314045df7aac78e8750a5d8cf7ea2b4ff6dd 100644 (file)
@@ -60,7 +60,7 @@
         $strmovedown = get_string('movedown');
     }
 
-
+    $context = get_context_instance(CONTEXT_COURSE, $course->id);
 /* Internet Explorer min-width fix. (See theme/standard/styles_layout.css: min-width for Firefox.)
    Window width: 800px, Firefox 763px, IE 752px. (Window width: 640px, Firefox 602px, IE 588px.)    
 */
             }
         }
 
-        $showsection = (isteacher($course->id) or $thissection->visible or !$course->hiddensections);
+        $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $thissection->visible or !$course->hiddensections);
 
         if (!empty($displaysection) and $displaysection != $section) {  // Check this week is visible
             if ($showsection) {
             echo '</div>';
 
             echo '<div class="content">';
-            if (!isteacher($course->id) and !$thissection->visible) {   // Hidden for students
+            if (!has_capability('moodle/course:viewhiddensections', $context) and !$thissection->visible) {   // Hidden for students
                 echo '<div class="weekdates">'.$weekday.' - '.$endweekday.' ('.get_string('notavailable').')</div>';
 
             } else {
index c1b32b00bf1d98078d19a7ac277b5e63b907067d..809d8e626ddf669017a0330fe399e27bbf713909 100644 (file)
@@ -9,9 +9,7 @@
         error("That's an invalid course id");
     }
 
-    if (!isteacher($course->id)) {
-        error("You are not allowed to look at this page");
-    }
+    require_capability('moodle/site:import', get_context_instance(CONTEXT_COURSE, $id));
 
 /// Always we begin an import, we delete all backup/restore/import session structures
     if (isset($SESSION->course_header)) {
index 20ddc2302b067177bbeff9cffaee97265b4e59c0..e6b8e9c9998081d330d8470da1550d2f4549da76 100644 (file)
@@ -82,7 +82,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
                 if ($mod->mod == "label") {
                     continue;
                 }
-                if (!$mod->visible and !$isteacher) {
+                if (!$mod->visible and !has_capability('moodle/course:viewhiddenactivities',get_context_instance(CONTEXT_MODULE, $mod->cm))) {
                     continue;
                 }
 
@@ -174,7 +174,7 @@ function print_recent_selector_form($course, $advancedfilter=0, $selecteduser=0,
 
         $groupmode =  groupmode($course);
 
-        if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) {
+        if ($groupmode == VISIBLEGROUPS or ($groupmode and has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id)))) {
             if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) {
             echo '<td><b>';
                 if ($groupmode == VISIBLEGROUPS) {
@@ -272,7 +272,7 @@ function build_logs_array($course, $user=0, $date=0, $order="l.time ASC", $limit
 
     /// 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 !$isteacheredit) {
+    if ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) {
         $groupid = get_current_group($course->id);
     }
     /// If this course doesn't have groups, no groupid can be specified.
@@ -985,7 +985,7 @@ function get_all_mods($courseid, &$mods, &$modnames, &$modnamesplural, &$modname
             }
             $mods[$mod->id] = $mod;
             $mods[$mod->id]->modfullname = $modnames[$mod->modname];
-            if ($mod->visible or isteacher($courseid)) {
+            if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $courseid))) {
                 $modnamesused[$mod->modname] = $modnames[$mod->modname];
             }
         }
@@ -1099,7 +1099,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
             }
             $mod = $mods[$modnumber];
 
-            if ($mod->visible or $isteacher) {
+            if ($mod->visible or has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
                 echo '<li class="activity '.$mod->modname.'" id="module-'.$modnumber.'">';  // Unique ID
                 if ($ismoving) {
                     if ($mod->id == $USER->activitycopy) {
@@ -1149,7 +1149,7 @@ function print_section($course, $section, $mods, $modnamesused, $absolute=false,
                 }
                 if ($usetracking && $mod->modname == 'forum') {
                     $groupmode = groupmode($course, $mod);
-                    $groupid = ($groupmode == SEPARATEGROUPS && !isteacheredit($course->id)) ?
+                    $groupid = ($groupmode == SEPARATEGROUPS && !has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) ?
                                get_current_group($course->id) : false;
 
                     if (forum_tp_can_track_forums() && !isset($untracked[$mod->instance])) {
index 632fab0605fd9cf5084c43c30ec202a45c1f5e12..56b6f1b2be3b564f92720f3ba9c2342b41d8e91f 100644 (file)
 
     } else { // you chose a group of activities
 
-        if (isteacher($course->id)) {
+        if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
             $hiddenfilter = "";
         } else {
             $hiddenfilter = " AND cs.visible = '1' ";
             $activityfilter = "";
         }
 
-        if (isteacher($course->id)) {
+        if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
             $hiddenfilter = "";
         } else {
             $hiddenfilter = " AND cm.visible = '1' ";
 
         $section = 0;
 
-        if (isteacher($course->id)) {
+        if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE, $course->id))) {
             $teacher = true;
         } else {
             $teacher = false;
index 408350247de1b1fe86302a363c8962fe86ba808d..b846ac0fad65a3717fcbace08873192f9c1c8898 100644 (file)
@@ -9,9 +9,7 @@
         error("That's an invalid course id");
     }
 
-    if (!isteacher($course->id)) {
-        error("You are not allowed to look at this page");
-    }
+    require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $id));
 
     $strreports = get_string('reports');
 
index e2d742d91ca28b5f05121e44ce4bccc2cff2d776..d696dcb45fdadee236e9ee516aad91dd89d55272 100644 (file)
@@ -17,9 +17,7 @@
         error("Course id is incorrect.");
     }
 
-    if (!isteacher($course->id)) {
-        error("You are not allowed to look at this page");
-    }
+    require_capability('moodle/site:viewreports', get_context_instance(CONTEXT_COURSE, $courseid));
 
     add_to_log($course->id, "course", "report outline", "report/outline/index.php?id=$course->id", $course->id); 
 
index 4519103d00994a3b55f6e96f560528af9f247db7..ce5974298495e5b33e1aca0f9360ae83f01334a6 100644 (file)
         error("User ID is incorrect");
     }
 
-    if (! (isteacher($course->id) or ($course->showreports and $USER->id == $user->id))) {
+    $coursecontext = get_context_instance(CONTEXT_COURSE, $id);
+    $personalcontext = get_context_instance(CONTEXT_USERID, $user->id);
+
+    // if in either context, we can read report, then we can proceed
+    if (!(has_capability('moodle/site:viewreports', $coursecontext) or ($course->showreports and $USER->id == $user->id) or has_capability('moodle/user:viewuseractivitiesreport', $personalcontext))) {
         error("You are not allowed to look at this page");
     }
 
                 if (isset($sections[$i])) {   // should always be true
 
                     $section = $sections[$i];
-                    $showsection = (isteacher($course->id) or $section->visible or !$course->hiddensections);
+                    $showsection = (has_capability('moodle/course:viewhiddensections', $context) or $section->visible or !$course->hiddensections);
 
                     if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
 
index 0e3f6f447c689b24be5541e505531682dc8e782e..190208cced7c420ddbc0a380623bbcbafbd82fe3 100644 (file)
--- a/file.php
+++ b/file.php
@@ -54,7 +54,7 @@
     }
 
     // security: only editing teachers can access backups
-    if ((!isteacheredit($course->id))
+    if ((!has_capability('moodle/site:backup', get_context_instance(CONTEXT_COURSE, $course->id)))
         and (count($args) >= 2)
         and (strtolower($args[1]) == 'backupdata')) {
 
@@ -83,7 +83,7 @@
         and (strtolower($args[2]) == 'assignment')) {
 
         $lifetime = 0;  // do not cache assignments, students may reupload them
-        if ((!isteacher($course->id)) && (count($args) != 6 || $args[4] != $USER->id)) {
+        if ((!has_capability('mod/assignment:grade', get_context_instance(CONTEXT_COURSE, $course->id))) && (count($args) != 6 || $args[4] != $USER->id)) {
            error('Access not allowed');
         }
     }
index 431c2efbaa060b95006240db96eaf668a9a25605..3ac4a6e90602621df27085782d72be5528bb0800 100644 (file)
@@ -12,9 +12,7 @@
 
     require_login($course->id);
 
-    if (!isteacher($course->id)) {
-        error(get_string('notteachererror', 'grades'));
-    }
+    require_capability('moodle/course:managegrades', get_context_instance(CONTEXT_MODULE, $id));
 
     $group = get_current_group($course->id);
     
index d29e889f6594055e8f99457002433b3d323a0fd7..de5eed1189bc006f736fc69e99d1cd8e2aa2a9e1 100644 (file)
@@ -766,6 +766,84 @@ $moodle_capabilities = array(
             'coursecreator' => CAP_ALLOW,
             'admin' => CAP_ALLOW
         )
+    ),
+    
+    'moodle/course:sectionvisibility' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'moodle/course:viewhiddensections' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'moodle/course:setcurrentsection' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'moodle/course:viewcoursegrades' => 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:managegrades' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_PREVENT,
+            'teacher' => CAP_PREVENT,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
+    ),
+    
+    'moodle/user:viewusergrades' => array(
+        'captype' => 'write',
+        'contextlevel' => CONTEXT_COURSE,
+        'legacy' => array(
+            'guest' => CAP_PREVENT,
+            'student' => CAP_ALLOW,
+            'teacher' => CAP_ALLOW,
+            'editingteacher' => CAP_ALLOW,
+            'coursecreator' => CAP_ALLOW,
+            'admin' => CAP_ALLOW
+        )
     )
 );