Revert "Merge branch 'wip-MDL-31750-master' of git://github.com/abgreeve/moodle"
authorDan Poltawski <dan@moodle.com>
Thu, 10 Jan 2013 03:17:05 +0000 (11:17 +0800)
committerDan Poltawski <dan@moodle.com>
Thu, 10 Jan 2013 03:17:33 +0000 (11:17 +0800)
course/category.php
course/edit.php
course/edit_form.php
course/lib.php
course/tests/courselib_test.php
lang/en/error.php

index 32d78b9..37138b5 100644 (file)
@@ -101,8 +101,13 @@ if ($editingon && $sesskeyprovided) {
 
     // Move a specified course to a new category
     if (!empty($moveto) and $data = data_submitted()) {
-        if (!$destcategory = $DB->get_record('course_categories', array('id' => $moveto))) {
-            print_error('cannotfindcategory', '', '', $moveto);
+        // Some courses are being moved
+        // user must have category update in both cats to perform this
+        require_capability('moodle/category:manage', $context);
+        require_capability('moodle/category:manage', context_coursecat::instance($moveto));
+
+        if (!$destcategory = $DB->get_record('course_categories', array('id' => $data->moveto))) {
+            print_error('cannotfindcategory', '', '', $data->moveto);
         }
 
         $courses = array();
@@ -121,10 +126,7 @@ if ($editingon && $sesskeyprovided) {
                 }
             }
         }
-        if (!can_move_courses_to_category($courses, $moveto, $category->id)) {
-            print_error('cannotmovecoursetocategory');
-        }
-        move_courses($courses, $moveto);
+        move_courses($courses, $data->moveto);
     }
 
     // Hide or show a course
@@ -434,7 +436,7 @@ if (!$courses) {
     if ($abletomovecourses) {
         $movetocategories = array();
         $notused = array();
-        make_categories_list($movetocategories, $notused, array('moodle/course:create', 'moodle/course:delete', 'moodle/category:manage'));
+        make_categories_list($movetocategories, $notused, 'moodle/category:manage');
         $movetocategories[$category->id] = get_string('moveselectedcoursesto');
         echo '<tr><td colspan="3" align="right">';
         echo html_writer::label(get_string('moveselectedcoursesto'), 'movetoid', false, array('class' => 'accesshide'));
index 576bc35..22bdd57 100644 (file)
@@ -131,9 +131,6 @@ if ($editform->is_cancelled()) {
             }
         }
     } else {
-        if (!can_move_courses_to_category($course->id, $data->category)) {
-            print_error('cannotmovecoursetocategory');
-        }
         // Save any changes to the files used in the editor
         update_course($data, $editoroptions);
     }
index 6ee0c67..34dbe12 100644 (file)
@@ -50,7 +50,7 @@ class course_edit_form extends moodleform {
             if (has_capability('moodle/course:create', $categorycontext)) {
                 $displaylist = array();
                 $parentlist = array();
-                make_categories_list($displaylist, $parentlist, array('moodle/course:create', 'moodle/course:delete', 'moodle/category:manage'));
+                make_categories_list($displaylist, $parentlist, 'moodle/course:create');
                 $mform->addElement('select', 'category', get_string('category'), $displaylist);
                 $mform->addHelpButton('category', 'category');
                 $mform->setDefault('category', $category->id);
@@ -63,7 +63,7 @@ class course_edit_form extends moodleform {
             if (has_capability('moodle/course:changecategory', $coursecontext)) {
                 $displaylist = array();
                 $parentlist = array();
-                make_categories_list($displaylist, $parentlist, array('moodle/course:create', 'moodle/course:delete', 'moodle/category:manage'));
+                make_categories_list($displaylist, $parentlist, 'moodle/course:create');
                 if (!isset($displaylist[$course->category])) {
                     //always keep current
                     $displaylist[$course->category] = format_string($DB->get_field('course_categories', 'name', array('id'=>$course->category)));
index a9d5b47..5230240 100644 (file)
@@ -4605,56 +4605,3 @@ function get_sorted_course_formats($enabledonly = false) {
 function course_get_url($courseorid, $section = null, $options = array()) {
     return course_get_format($courseorid)->get_view_url($section, $options);
 }
-
-/**
- * Determine whether a user can move a course to a different category.
- *
- * @param int|array $courseid  The course ID (int) or course IDs (array) that are being moved.
- * @param int       $moveto    The category ID of where we are moving the course to.
- * @param int       $movefrom  The current category ID. If not provided will be looked up.
- * @return bool  True if the user can move the course. False if the user can't move the course.
- */
-function can_move_courses_to_category($courseid, $moveto, $movefrom = null) {
-    global $DB;
-
-    $tocontext = context_coursecat::instance($moveto);
-
-    if (!has_capability('moodle/category:manage', $tocontext)) {
-        return false;
-    }
-
-    if (is_array($courseid)) {
-        foreach ($courseid as $id) {
-            if (!$movefrom) {
-                $movefrom = $DB->get_field('course', 'category', array('id' => $id));
-            }
-
-            $fromcontext = context_coursecat::instance($movefrom);
-            if (!has_capability('moodle/category:manage', $fromcontext)) {
-                return false;
-            }
-
-            $coursecontext = context_course::instance($id);
-            $capabilities = array('moodle/course:delete', 'moodle/course:create');
-            if (!has_all_capabilities($capabilities, $coursecontext)) {
-                return false;
-            }
-        }
-    } else {
-        if (!$movefrom) {
-            $movefrom = $DB->get_field('course', 'category', array('id' => $courseid));
-        }
-
-        $fromcontext = context_coursecat::instance($movefrom);
-        if (!has_capability('moodle/category:manage', $fromcontext)) {
-            return false;
-        }
-
-        $coursecontext = context_course::instance($courseid);
-        $capabilities = array('moodle/course:delete', 'moodle/course:create');
-        if (!has_all_capabilities($capabilities, $coursecontext)) {
-            return false;
-        }
-    }
-    return true;
-}
index c4cc55e..a59351b 100644 (file)
@@ -435,100 +435,4 @@ class courselib_testcase extends advanced_testcase {
         }
     }
 
-    /**
-     * These tests check for moving courses around categories with different permissions enabled and disabled.
-     * (@see course/lib.php can_move_courses_to_category())
-     */
-    function test_move_course_to_category_check() {
-        $this->resetAfterTest(true);
-
-        // Create a user.
-        $user = $this->getDataGenerator()->create_user();
-
-        // Log in as the user.
-        $this->setUser($user);
-
-        $catstructure[] = array(
-                    'fromcategory' => array('catcap' => 'moodle/category:manage', 'allow' => CAP_ALLOW),
-                    'tocategory' => array('catcap' => 'moodle/category:manage', 'allow' => CAP_ALLOW),
-                    'courses' => array(
-                        array('coursecap' => array('moodle/course:create')),
-                        array('coursecap' => array('moodle/course:delete')),
-                        array('coursecap' => array('moodle/course:delete', 'moodle/course:create'))
-                    ),
-                    'movecourse' => array(
-                        array('course' => 0, 'result' => false),
-                        array('course' => 1, 'result' => false),
-                        array('course' => 2, 'result' => true),
-                        array('course' => array(0,1), 'result' => false),
-                        array('course' => array(0,1,2), 'result' => false),
-                    )
-            );
-
-        // Create a system context to ascertain the correct role id.
-        $systemcontext = context_system::instance();
-
-        $roleid = 4; // role id of student?
-        // This is to ensure that we get the correct role id.
-        $roles = role_get_names($systemcontext);
-        foreach ($roles as $role) {
-            if ($role->shortname == 'student') {
-                $roleid = $role->id;
-            }
-        }
-
-        // Create category.
-        foreach ($catstructure as $key => $value) {
-            // Create to catgory.
-            $cat = $this->getDataGenerator()->create_category(array('name' => 'FromTestCat '.$key));
-            $catstructure[$key]['tocategory']['catid'] = $cat->id;
-            $catstructure[$key]['tocategory']['catcontext'] = context_coursecat::instance($cat->id);
-            $catcap = $catstructure[$key]['tocategory']['catcap'];
-            $catallow = $catstructure[$key]['tocategory']['allow'];
-            assign_capability($catcap, $catallow, $roleid, $catstructure[$key]['tocategory']['catcontext'], true);
-
-            // Create from category.
-            $fromcat = $this->getDataGenerator()->create_category(array('name' => 'ToTestCat '.$key));
-            $catstructure[$key]['fromcategory']['catid'] = $fromcat->id;
-            $catstructure[$key]['fromcategory']['catcontext'] = context_coursecat::instance($fromcat->id);
-            $catcap = $catstructure[$key]['fromcategory']['catcap'];
-            $catallow = $catstructure[$key]['fromcategory']['allow'];
-            assign_capability($catcap, $catallow, $roleid, $catstructure[$key]['fromcategory']['catcontext'], true);
-
-            // Create course in from category.
-            foreach($value['courses'] as $coursekey => $coursedata) {
-                $coursed = array('category' => $fromcat->id,
-                                    'fullname' => 'Coursefullname '.$fromcat->id.$coursekey,
-                                    'shortname' => 'Courseshortname'.$fromcat->id.$coursekey);
-
-                $course = $this->getDataGenerator()->create_course($coursed);
-                $catstructure[$key]['courses'][$coursekey]['id'] = $course->id;
-                $coursecontext = context_course::instance($course->id);
-
-                foreach ($coursedata['coursecap'] as $coursecap) {
-                    assign_capability($coursecap, CAP_ALLOW, $roleid, $coursecontext, true);
-                }
-            }
-            // Assign course creator to user on category.
-            role_assign($roleid, $user->id, $catstructure[$key]['tocategory']['catcontext']);
-            role_assign($roleid, $user->id, $catstructure[$key]['fromcategory']['catcontext']);
-        }
-
-        // We loop through the catstructure array and test moving courses to different categories with different permissions.
-        foreach ($catstructure as $key => $data) {
-            foreach ($data['movecourse'] as $move) {
-                if (is_array($move['course'])) {
-                    $courseids = array();
-                    foreach ($move['course'] as $courseindex) {
-                        $courseids[] = $data['courses'][$courseindex]['id'];
-                    }
-                } else {
-                    $courseids = $data['courses'][$move['course']]['id'];
-                }
-
-                $canmove = can_move_courses_to_category($courseids, $data['tocategory']['catid']);
-                $this->assertEquals($canmove, $move['result']);
-            }
-        }
-    }
 }
index 93118b3..0bf030b 100644 (file)
@@ -106,7 +106,6 @@ $string['cannotmigratedatacomments'] = 'Cannot migrate data module comments';
 $string['cannotmodulename'] = 'Cannot get the module name in build navigation';
 $string['cannotmoduletype'] = 'Cannot get the module type in build navigation';
 $string['cannotmoverolewithid'] = 'Cannot move role with ID {$a}';
-$string['cannotmovecoursetocategory'] = 'You can not move this course to the category specified';
 $string['cannotopencsv'] = 'Cannot open CSV file';
 $string['cannotopenfile'] = 'Cannot open file ({$a})';
 $string['cannotopenforwrit'] = 'Cannot open for writing: {$a}';