mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 04:52:36 +02:00
Merge branch 'MDL-59913-master' of https://github.com/sammarshallou/moodle
This commit is contained in:
commit
8905d3efe0
@ -557,13 +557,21 @@ if ($hassiteconfig) {
|
||||
$temp->add(new admin_setting_heading('searchengineheading', new lang_string('searchengine', 'admin'), ''));
|
||||
$temp->add(new admin_setting_configselect('searchengine',
|
||||
new lang_string('selectsearchengine', 'admin'), '', 'solr', $engines));
|
||||
$temp->add(new admin_setting_heading('searchindexingheading', new lang_string('searchoptions', 'admin'), ''));
|
||||
$temp->add(new admin_setting_heading('searchoptionsheading', new lang_string('searchoptions', 'admin'), ''));
|
||||
$temp->add(new admin_setting_configcheckbox('searchindexwhendisabled',
|
||||
new lang_string('searchindexwhendisabled', 'admin'), new lang_string('searchindexwhendisabled_desc', 'admin'),
|
||||
0));
|
||||
$temp->add(new admin_setting_configduration('searchindextime',
|
||||
new lang_string('searchindextime', 'admin'), new lang_string('searchindextime_desc', 'admin'),
|
||||
600));
|
||||
$options = [
|
||||
0 => new lang_string('searchallavailablecourses_off', 'admin'),
|
||||
1 => new lang_string('searchallavailablecourses_on', 'admin')
|
||||
];
|
||||
$temp->add(new admin_setting_configselect('searchallavailablecourses',
|
||||
new lang_string('searchallavailablecourses', 'admin'),
|
||||
new lang_string('searchallavailablecourses_desc', 'admin'),
|
||||
0, $options));
|
||||
|
||||
$ADMIN->add('searchplugins', $temp);
|
||||
$ADMIN->add('searchplugins', new admin_externalpage('searchareas', new lang_string('searchareas', 'admin'),
|
||||
|
@ -981,6 +981,10 @@ $string['save'] = 'Save';
|
||||
$string['savechanges'] = 'Save changes';
|
||||
$string['scssinvalid'] = 'SCSS code is not valid, fails with: {$a}';
|
||||
$string['search'] = 'Search';
|
||||
$string['searchallavailablecourses'] = 'Searchable courses';
|
||||
$string['searchallavailablecourses_off'] = 'Search within enrolled courses only';
|
||||
$string['searchallavailablecourses_on'] = 'Search within all courses the user can access';
|
||||
$string['searchallavailablecourses_desc'] = 'In some situations the search engine may not work when searching across a large number of courses. Set to search only enrolled courses if you need to restrict the number of courses searched.';
|
||||
$string['searchalldeleted'] = 'All indexed contents have been deleted';
|
||||
$string['searchareaenabled'] = 'Search area enabled';
|
||||
$string['searchareadisabled'] = 'Search area disabled';
|
||||
|
@ -379,7 +379,8 @@ class manager {
|
||||
}
|
||||
|
||||
// Get the courses where the current user has access.
|
||||
$courses = enrol_get_my_courses(array('id', 'cacherev'));
|
||||
$courses = enrol_get_my_courses(array('id', 'cacherev'), 'id', 0, [],
|
||||
(bool)get_config('core', 'searchallavailablecourses'));
|
||||
|
||||
if (empty($limitcourseids) || in_array(SITEID, $limitcourseids)) {
|
||||
$courses[SITEID] = get_course(SITEID);
|
||||
|
@ -463,6 +463,89 @@ class search_manager_testcase extends advanced_testcase {
|
||||
$this->assertEquals($contexts['block_html-content'], $limitedcontexts['block_html-content']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get_areas_user_accesses with regard to the 'all available courses' config option.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function test_search_user_accesses_allavailable() {
|
||||
global $DB, $CFG;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
// Front page, including a forum.
|
||||
$frontpage = $DB->get_record('course', array('id' => SITEID));
|
||||
$forumfront = $this->getDataGenerator()->create_module('forum', array('course' => $frontpage->id));
|
||||
$forumfrontctx = context_module::instance($forumfront->cmid);
|
||||
|
||||
// Course 1 does not allow guest access.
|
||||
$course1 = $this->getDataGenerator()->create_course((object)array(
|
||||
'enrol_guest_status_0' => ENROL_INSTANCE_DISABLED,
|
||||
'enrol_guest_password_0' => ''));
|
||||
$forum1 = $this->getDataGenerator()->create_module('forum', array('course' => $course1->id));
|
||||
$forum1ctx = context_module::instance($forum1->cmid);
|
||||
|
||||
// Course 2 does not allow guest but is accessible by all users.
|
||||
$course2 = $this->getDataGenerator()->create_course((object)array(
|
||||
'enrol_guest_status_0' => ENROL_INSTANCE_DISABLED,
|
||||
'enrol_guest_password_0' => ''));
|
||||
$course2ctx = context_course::instance($course2->id);
|
||||
$forum2 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
|
||||
$forum2ctx = context_module::instance($forum2->cmid);
|
||||
assign_capability('moodle/course:view', CAP_ALLOW, $CFG->defaultuserroleid, $course2ctx->id);
|
||||
|
||||
// Course 3 allows guest access without password.
|
||||
$course3 = $this->getDataGenerator()->create_course((object)array(
|
||||
'enrol_guest_status_0' => ENROL_INSTANCE_ENABLED,
|
||||
'enrol_guest_password_0' => ''));
|
||||
$forum3 = $this->getDataGenerator()->create_module('forum', array('course' => $course2->id));
|
||||
$forum3ctx = context_module::instance($forum3->cmid);
|
||||
|
||||
// Student user is enrolled in course 1.
|
||||
$student = $this->getDataGenerator()->create_user();
|
||||
$this->getDataGenerator()->enrol_user($student->id, $course1->id, 'student');
|
||||
|
||||
// No access user is just a user with no permissions.
|
||||
$noaccess = $this->getDataGenerator()->create_user();
|
||||
|
||||
// First test without the all available option.
|
||||
$search = testable_core_search::instance();
|
||||
|
||||
// Admin user can access everything.
|
||||
$this->setAdminUser();
|
||||
$this->assertTrue($search->get_areas_user_accesses());
|
||||
|
||||
// No-access user can access only the front page forum.
|
||||
$this->setUser($noaccess);
|
||||
$contexts = $search->get_areas_user_accesses();
|
||||
$this->assertEquals([$forumfrontctx->id], array_keys($contexts[$this->forumpostareaid]));
|
||||
|
||||
// Student can access the front page forum plus the enrolled one.
|
||||
$this->setUser($student);
|
||||
$contexts = $search->get_areas_user_accesses();
|
||||
$this->assertEquals([$forum1ctx->id, $forumfrontctx->id],
|
||||
array_keys($contexts[$this->forumpostareaid]));
|
||||
|
||||
// Now turn on the all available option.
|
||||
set_config('searchallavailablecourses', 1);
|
||||
|
||||
// Admin user can access everything.
|
||||
$this->setAdminUser();
|
||||
$this->assertTrue($search->get_areas_user_accesses());
|
||||
|
||||
// No-access user can access the front page forum and course 2, 3.
|
||||
$this->setUser($noaccess);
|
||||
$contexts = $search->get_areas_user_accesses();
|
||||
$this->assertEquals([$forum2ctx->id, $forum3ctx->id, $forumfrontctx->id],
|
||||
array_keys($contexts[$this->forumpostareaid]));
|
||||
|
||||
// Student can access the front page forum plus the enrolled one plus courses 2, 3.
|
||||
$this->setUser($student);
|
||||
$contexts = $search->get_areas_user_accesses();
|
||||
$this->assertEquals([$forum1ctx->id, $forum2ctx->id, $forum3ctx->id, $forumfrontctx->id],
|
||||
array_keys($contexts[$this->forumpostareaid]));
|
||||
}
|
||||
|
||||
/**
|
||||
* test_is_search_area
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user