mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
Merge branch 'MDL-58518-master' of git://github.com/ryanwyllie/moodle
This commit is contained in:
commit
472cae12a6
@ -1 +1 @@
|
||||
define(["jquery","block_myoverview/event_list","block_myoverview/calendar_events_repository"],function(a,b,c){var d=86400,e={EVENTS_BY_COURSE_CONTAINER:'[data-region="course-events-container"]'},f=function(f){var g=f.find(e.EVENTS_BY_COURSE_CONTAINER);if(g.length){var h=f.attr("data-midnight"),i=h-14*d,j=g.attr("data-limit"),k=g.map(function(){return a(this).attr("data-course-id")}).get(),l=c.queryByCourses({courseids:k,starttime:i,limit:j});g.each(function(c,d){d=a(d);var e=d.attr("data-course-id"),f=d.find(b.rootSelector),g=a.Deferred();l.done(function(a){var b=[],c=a.groupedbycourse.filter(function(a){return a.courseid==e});c.length&&(b=c[0].events),g.resolve({events:b})}).fail(function(a){g.reject(a)}),b.load(f,g)})}};return{init:function(b){b=a(b),f(b)}}});
|
||||
define(["jquery","block_myoverview/event_list","block_myoverview/calendar_events_repository"],function(a,b,c){var d=86400,e={EVENTS_BY_COURSE_CONTAINER:'[data-region="course-events-container"]',EVENT_LIST_CONTAINER:'[data-region="event-list-container"]'},f=function(f){var g=f.find(e.EVENTS_BY_COURSE_CONTAINER);if(g.length){var h=g.find(e.EVENT_LIST_CONTAINER).first(),i=h.attr("data-midnight"),j=i-14*d,k=h.attr("data-limit"),l=g.map(function(){return a(this).attr("data-course-id")}).get(),m=c.queryByCourses({courseids:l,starttime:j,limit:k});g.each(function(c,d){d=a(d);var e=d.attr("data-course-id"),f=d.find(b.rootSelector),g=a.Deferred();m.done(function(a){var b=[],c=a.groupedbycourse.filter(function(a){return a.courseid==e});c.length&&(b=c[0].events),g.resolve({events:b})}).fail(function(a){g.reject(a)}),b.load(f,g)})}};return{init:function(b){b=a(b),f(b)}}});
|
@ -33,6 +33,7 @@ function($, EventList, EventsRepository) {
|
||||
|
||||
var SELECTORS = {
|
||||
EVENTS_BY_COURSE_CONTAINER: '[data-region="course-events-container"]',
|
||||
EVENT_LIST_CONTAINER: '[data-region="event-list-container"]',
|
||||
};
|
||||
|
||||
/**
|
||||
@ -48,9 +49,10 @@ function($, EventList, EventsRepository) {
|
||||
return;
|
||||
}
|
||||
|
||||
var midnight = root.attr('data-midnight');
|
||||
var eventList = courseBlocks.find(SELECTORS.EVENT_LIST_CONTAINER).first();
|
||||
var midnight = eventList.attr('data-midnight');
|
||||
var startTime = midnight - (14 * SECONDS_IN_DAY);
|
||||
var limit = courseBlocks.attr('data-limit');
|
||||
var limit = eventList.attr('data-limit');
|
||||
var courseIds = courseBlocks.map(function() {
|
||||
return $(this).attr('data-course-id');
|
||||
}).get();
|
||||
|
@ -147,7 +147,16 @@ class container {
|
||||
$cm = $instances[$dbrow->modulename][$dbrow->instance];
|
||||
|
||||
// If the module is not visible to the current user, we should ignore it.
|
||||
if (!$cm->uservisible) {
|
||||
// We have to check enrolment here as well because the uservisible check
|
||||
// looks for the "view" capability however some activities (such as Lesson)
|
||||
// have that capability set on the "Authenticated User" role rather than
|
||||
// on "Student" role, which means uservisible returns true even when the user
|
||||
// is no longer enrolled in the course.
|
||||
$modulecontext = \context_module::instance($cm->id);
|
||||
// A user with the 'moodle/course:view' capability is able to see courses
|
||||
// that they are not a participant in.
|
||||
$canseecourse = (has_capability('moodle/course:view', $modulecontext) || is_enrolled($modulecontext));
|
||||
if (!$cm->uservisible || !$canseecourse) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -233,6 +233,58 @@ class core_calendar_container_testcase extends advanced_testcase {
|
||||
$this->assertNull($factory->create_instance($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that the event factory only returns an event if the logged in user
|
||||
* is enrolled in the course.
|
||||
*/
|
||||
public function test_event_factory_unenrolled_user() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
// Create the course we will be using.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
|
||||
// Add the assignment.
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_lesson');
|
||||
$lesson = $generator->create_instance(array('course' => $course->id));
|
||||
|
||||
// Create a user override event for the lesson.
|
||||
$event = new \stdClass();
|
||||
$event->name = 'An event';
|
||||
$event->description = 'Event description';
|
||||
$event->format = FORMAT_HTML;
|
||||
$event->eventtype = 'close';
|
||||
$event->userid = $user->id;
|
||||
$event->modulename = 'lesson';
|
||||
$event->instance = $lesson->id;
|
||||
$event->courseid = $course->id;
|
||||
$event->groupid = 0;
|
||||
$event->timestart = time();
|
||||
$event->timesort = time();
|
||||
$event->timemodified = time();
|
||||
$event->timeduration = 0;
|
||||
$event->subscriptionid = null;
|
||||
$event->repeatid = 0;
|
||||
$legacyevent = $this->create_event($event);
|
||||
|
||||
// Update the id of the event that was created.
|
||||
$event->id = $legacyevent->id;
|
||||
|
||||
// Set the logged in user to the one we created.
|
||||
$this->setUser($user);
|
||||
|
||||
// Create the factory we are going to be testing the behaviour of.
|
||||
$factory = \core_calendar\local\event\container::get_event_factory();
|
||||
|
||||
// The result should be null since the user is not enrolled in the
|
||||
// course the event is for.
|
||||
$this->assertNull($factory->create_instance($event));
|
||||
|
||||
// Now enrol the user in the course.
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
|
||||
// Check that we get the correct instance.
|
||||
$this->assertInstanceOf(event_interface::class, $factory->create_instance($event));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting the event mapper.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user