Permalink
Browse files

Revert "Merge branch 'wip-MDL-31750-master' of git://github.com/abgre…

…eve/moodle"

This reverts commit 8361f55,
2b9e957 and
fae5191
  • Loading branch information...
1 parent 632f3ef commit 319d93760222bc1a8bda77d89cdba3298e137c6d @danpoltawski danpoltawski committed Jan 10, 2013
Showing with 11 additions and 162 deletions.
  1. +9 −7 course/category.php
  2. +0 −3 course/edit.php
  3. +2 −2 course/edit_form.php
  4. +0 −53 course/lib.php
  5. +0 −96 course/tests/courselib_test.php
  6. +0 −1 lang/en/error.php
View
@@ -101,8 +101,13 @@
// 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 (!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 ($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'));
View
@@ -131,9 +131,6 @@
}
}
} 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);
}
View
@@ -50,7 +50,7 @@ function definition() {
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 @@ function definition() {
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)));
View
@@ -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;
-}
@@ -435,100 +435,4 @@ public function check_module_visibility($mod, $visibility, $visibleold) {
}
}
- /**
- * 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']);
- }
- }
- }
}
View
@@ -106,7 +106,6 @@
$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}';

0 comments on commit 319d937

Please sign in to comment.