Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
dd1ba60f
Commit
dd1ba60f
authored
Sep 06, 2018
by
Shamim Rezaie
Browse files
MDL-63117 mod_book: Check if the module is visible to the user
parent
a4fd6c07
Changes
2
Hide whitespace changes
Inline
Side-by-side
mod/book/lib.php
View file @
dd1ba60f
...
...
@@ -768,6 +768,12 @@ function mod_book_core_calendar_provide_event_action(calendar_event $event,
}
$cm
=
get_fast_modinfo
(
$event
->
courseid
,
$userid
)
->
instances
[
'book'
][
$event
->
instance
];
if
(
!
$cm
->
uservisible
)
{
// The module is not visible to the user for any reason.
return
null
;
}
$context
=
context_module
::
instance
(
$cm
->
id
);
if
(
!
has_capability
(
'mod/book:read'
,
$context
,
$userid
))
{
...
...
mod/book/tests/lib_test.php
View file @
dd1ba60f
...
...
@@ -160,6 +160,34 @@ class mod_book_lib_testcase extends advanced_testcase {
$this
->
assertTrue
(
$actionevent
->
is_actionable
());
}
public
function
test_book_core_calendar_provide_event_action_in_hidden_section
()
{
// Create the activity.
$course
=
$this
->
getDataGenerator
()
->
create_course
();
$book
=
$this
->
getDataGenerator
()
->
create_module
(
'book'
,
array
(
'course'
=>
$course
->
id
));
// Enrol a student in the course.
$student
=
$this
->
getDataGenerator
()
->
create_and_enrol
(
$course
,
'student'
);
// Create a calendar event.
$event
=
$this
->
create_action_event
(
$course
->
id
,
$book
->
id
,
\
core_completion\api
::
COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED
);
// Set sections 0 as hidden.
set_section_visible
(
$course
->
id
,
0
,
0
);
// Now, log out.
$this
->
setUser
();
// Create an action factory.
$factory
=
new
\
core_calendar\action_factory
();
// Decorate action event for the student.
$actionevent
=
mod_book_core_calendar_provide_event_action
(
$event
,
$factory
,
$student
->
id
);
// Confirm the event is not shown at all.
$this
->
assertNull
(
$actionevent
);
}
public
function
test_book_core_calendar_provide_event_action_for_user
()
{
// Create the activity.
$course
=
$this
->
getDataGenerator
()
->
create_course
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment