Skip to content
GitLab
Menu
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
b5a289c4
Commit
b5a289c4
authored
Aug 11, 2014
by
Daniel Neis Araujo
Committed by
Daniel Neis Araujo
Aug 21, 2014
Browse files
MDL-46509 enrol: Require 'enrol/PLUGIN:config' capabilities to show/hide enrollment instances
parent
0594336d
Changes
15
Hide whitespace changes
Inline
Side-by-side
enrol/category/lib.php
View file @
b5a289c4
...
@@ -53,6 +53,17 @@ class enrol_category_plugin extends enrol_plugin {
...
@@ -53,6 +53,17 @@ class enrol_category_plugin extends enrol_plugin {
return
!
$DB
->
record_exists
(
'user_enrolments'
,
array
(
'enrolid'
=>
$instance
->
id
));
return
!
$DB
->
record_exists
(
'user_enrolments'
,
array
(
'enrolid'
=>
$instance
->
id
));
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/category:config'
,
$context
);
}
/**
/**
* Returns link to page which may be used to add new instance of enrolment plugin in course.
* Returns link to page which may be used to add new instance of enrolment plugin in course.
* @param int $courseid
* @param int $courseid
...
...
enrol/cohort/lib.php
View file @
b5a289c4
...
@@ -360,6 +360,17 @@ class enrol_cohort_plugin extends enrol_plugin {
...
@@ -360,6 +360,17 @@ class enrol_cohort_plugin extends enrol_plugin {
// Nothing to do here, the group members are added in $this->restore_group_restored()
// Nothing to do here, the group members are added in $this->restore_group_restored()
return
;
return
;
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/cohort:config'
,
$context
);
}
}
}
/**
/**
...
...
enrol/database/lib.php
View file @
b5a289c4
...
@@ -54,6 +54,17 @@ class enrol_database_plugin extends enrol_plugin {
...
@@ -54,6 +54,17 @@ class enrol_database_plugin extends enrol_plugin {
return
false
;
return
false
;
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/database:config'
,
$context
);
}
/**
/**
* Does this plugin allow manual unenrolment of a specific user?
* Does this plugin allow manual unenrolment of a specific user?
* Yes, but only if user suspended...
* Yes, but only if user suspended...
...
...
enrol/flatfile/lib.php
View file @
b5a289c4
...
@@ -106,6 +106,17 @@ class enrol_flatfile_plugin extends enrol_plugin {
...
@@ -106,6 +106,17 @@ class enrol_flatfile_plugin extends enrol_plugin {
return
has_capability
(
'enrol/flatfile:manage'
,
$context
);
return
has_capability
(
'enrol/flatfile:manage'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/flatfile:manage'
,
$context
);
}
/**
/**
* Gets an array of the user enrolment actions.
* Gets an array of the user enrolment actions.
*
*
...
...
enrol/guest/lib.php
View file @
b5a289c4
...
@@ -403,4 +403,14 @@ class enrol_guest_plugin extends enrol_plugin {
...
@@ -403,4 +403,14 @@ class enrol_guest_plugin extends enrol_plugin {
return
has_capability
(
'enrol/guest:config'
,
$context
);
return
has_capability
(
'enrol/guest:config'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/guest:config'
,
$context
);
}
}
}
enrol/imsenterprise/lib.php
View file @
b5a289c4
...
@@ -804,4 +804,15 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
...
@@ -804,4 +804,15 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
$context
=
context_course
::
instance
(
$instance
->
courseid
);
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/imsenterprise:config'
,
$context
);
return
has_capability
(
'enrol/imsenterprise:config'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/imsenterprise:config'
,
$context
);
}
}
}
enrol/instances.php
View file @
b5a289c4
...
@@ -146,28 +146,39 @@ if ($canconfig and $action and confirm_sesskey()) {
...
@@ -146,28 +146,39 @@ if ($canconfig and $action and confirm_sesskey()) {
}
else
if
(
$action
===
'disable'
)
{
}
else
if
(
$action
===
'disable'
)
{
$instance
=
$instances
[
$instanceid
];
$instance
=
$instances
[
$instanceid
];
$plugin
=
$plugins
[
$instance
->
enrol
];
$plugin
=
$plugins
[
$instance
->
enrol
];
if
(
$instance
->
status
!=
ENROL_INSTANCE_DISABLED
)
{
if
(
$plugin
->
can_hide_show_instance
(
$instance
))
{
if
(
enrol_accessing_via_instance
(
$instance
))
{
if
(
$instance
->
status
!=
ENROL_INSTANCE_DISABLED
)
{
if
(
!
$confirm2
)
{
if
(
enrol_accessing_via_instance
(
$instance
))
{
$yesurl
=
new
moodle_url
(
'/enrol/instances.php'
,
array
(
'id'
=>
$course
->
id
,
'action'
=>
'disable'
,
'instance'
=>
$instance
->
id
,
'confirm2'
=>
1
,
'sesskey'
=>
sesskey
()));
if
(
!
$confirm2
)
{
$displayname
=
$plugin
->
get_instance_name
(
$instance
);
$yesurl
=
new
moodle_url
(
'/enrol/instances.php'
,
$message
=
markdown_to_html
(
get_string
(
'disableinstanceconfirmself'
,
'enrol'
,
array
(
'name'
=>
$displayname
)));
array
(
'id'
=>
$course
->
id
,
echo
$OUTPUT
->
header
();
'action'
=>
'disable'
,
echo
$OUTPUT
->
confirm
(
$message
,
$yesurl
,
$PAGE
->
url
);
'instance'
=>
$instance
->
id
,
echo
$OUTPUT
->
footer
();
'confirm2'
=>
1
,
die
();
'sesskey'
=>
sesskey
()));
$displayname
=
$plugin
->
get_instance_name
(
$instance
);
$message
=
markdown_to_html
(
get_string
(
'disableinstanceconfirmself'
,
'enrol'
,
array
(
'name'
=>
$displayname
)));
echo
$OUTPUT
->
header
();
echo
$OUTPUT
->
confirm
(
$message
,
$yesurl
,
$PAGE
->
url
);
echo
$OUTPUT
->
footer
();
die
();
}
}
}
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_DISABLED
);
redirect
(
$PAGE
->
url
);
}
}
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_DISABLED
);
redirect
(
$PAGE
->
url
);
}
}
}
else
if
(
$action
===
'enable'
)
{
}
else
if
(
$action
===
'enable'
)
{
$instance
=
$instances
[
$instanceid
];
$instance
=
$instances
[
$instanceid
];
$plugin
=
$plugins
[
$instance
->
enrol
];
$plugin
=
$plugins
[
$instance
->
enrol
];
if
(
$instance
->
status
!=
ENROL_INSTANCE_ENABLED
)
{
if
(
$plugin
->
can_hide_show_instance
(
$instance
))
{
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_ENABLED
);
if
(
$instance
->
status
!=
ENROL_INSTANCE_ENABLED
)
{
redirect
(
$PAGE
->
url
);
$plugin
->
update_status
(
$instance
,
ENROL_INSTANCE_ENABLED
);
redirect
(
$PAGE
->
url
);
}
}
}
}
}
}
}
...
@@ -235,7 +246,7 @@ foreach ($instances as $instance) {
...
@@ -235,7 +246,7 @@ foreach ($instances as $instance) {
$edit
[]
=
$OUTPUT
->
action_icon
(
$aurl
,
new
pix_icon
(
't/delete'
,
$strdelete
,
'core'
,
array
(
'class'
=>
'iconsmall'
)));
$edit
[]
=
$OUTPUT
->
action_icon
(
$aurl
,
new
pix_icon
(
't/delete'
,
$strdelete
,
'core'
,
array
(
'class'
=>
'iconsmall'
)));
}
}
if
(
enrol_is_enabled
(
$instance
->
enrol
))
{
if
(
enrol_is_enabled
(
$instance
->
enrol
)
&&
$plugin
->
can_hide_show_instance
(
$instance
)
)
{
if
(
$instance
->
status
==
ENROL_INSTANCE_ENABLED
)
{
if
(
$instance
->
status
==
ENROL_INSTANCE_ENABLED
)
{
$aurl
=
new
moodle_url
(
$url
,
array
(
'action'
=>
'disable'
,
'instance'
=>
$instance
->
id
));
$aurl
=
new
moodle_url
(
$url
,
array
(
'action'
=>
'disable'
,
'instance'
=>
$instance
->
id
));
$edit
[]
=
$OUTPUT
->
action_icon
(
$aurl
,
new
pix_icon
(
't/hide'
,
$strdisable
,
'core'
,
array
(
'class'
=>
'iconsmall'
)));
$edit
[]
=
$OUTPUT
->
action_icon
(
$aurl
,
new
pix_icon
(
't/hide'
,
$strdisable
,
'core'
,
array
(
'class'
=>
'iconsmall'
)));
...
...
enrol/ldap/lib.php
View file @
b5a289c4
...
@@ -124,6 +124,17 @@ class enrol_ldap_plugin extends enrol_plugin {
...
@@ -124,6 +124,17 @@ class enrol_ldap_plugin extends enrol_plugin {
return
false
;
return
false
;
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/ldap:config'
,
$context
);
}
/**
/**
* Forces synchronisation of user enrolments with LDAP server.
* Forces synchronisation of user enrolments with LDAP server.
* It creates courses if the plugin is configured to do so.
* It creates courses if the plugin is configured to do so.
...
...
enrol/manual/lib.php
View file @
b5a289c4
...
@@ -564,4 +564,15 @@ class enrol_manual_plugin extends enrol_plugin {
...
@@ -564,4 +564,15 @@ class enrol_manual_plugin extends enrol_plugin {
$context
=
context_course
::
instance
(
$instance
->
courseid
);
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/manual:config'
,
$context
);
return
has_capability
(
'enrol/manual:config'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/manual:config'
,
$context
);
}
}
}
enrol/meta/lib.php
View file @
b5a289c4
...
@@ -152,12 +152,22 @@ class enrol_meta_plugin extends enrol_plugin {
...
@@ -152,12 +152,22 @@ class enrol_meta_plugin extends enrol_plugin {
/**
/**
* Is it possible to delete enrol instance via standard UI?
* Is it possible to delete enrol instance via standard UI?
*
*
* @param
object
$instance
* @param
stdClass
$instance
* @return bool
* @return bool
*/
*/
public
function
can_delete_instance
(
$instance
)
{
public
function
can_delete_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/meta:config'
,
$context
);
return
has_capability
(
'enrol/meta:config'
,
$context
);
}
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/meta:config'
,
$context
);
}
}
enrol/mnet/lib.php
View file @
b5a289c4
...
@@ -92,11 +92,22 @@ class enrol_mnet_plugin extends enrol_plugin {
...
@@ -92,11 +92,22 @@ class enrol_mnet_plugin extends enrol_plugin {
/**
/**
* Is it possible to delete enrol instance via standard UI?
* Is it possible to delete enrol instance via standard UI?
*
*
* @param
object
$instance
* @param
stdClass
$instance
* @return bool
* @return bool
*/
*/
public
function
can_delete_instance
(
$instance
)
{
public
function
can_delete_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/mnet:config'
,
$context
);
return
has_capability
(
'enrol/mnet:config'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/mnet:config'
,
$context
);
}
}
}
enrol/paypal/lib.php
View file @
b5a289c4
...
@@ -311,11 +311,22 @@ class enrol_paypal_plugin extends enrol_plugin {
...
@@ -311,11 +311,22 @@ class enrol_paypal_plugin extends enrol_plugin {
/**
/**
* Is it possible to delete enrol instance via standard UI?
* Is it possible to delete enrol instance via standard UI?
*
*
* @param
object
$instance
* @param
stdClass
$instance
* @return bool
* @return bool
*/
*/
public
function
can_delete_instance
(
$instance
)
{
public
function
can_delete_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/paypal:config'
,
$context
);
return
has_capability
(
'enrol/paypal:config'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/paypal:config'
,
$context
);
}
}
}
enrol/self/lib.php
View file @
b5a289c4
...
@@ -651,11 +651,22 @@ class enrol_self_plugin extends enrol_plugin {
...
@@ -651,11 +651,22 @@ class enrol_self_plugin extends enrol_plugin {
/**
/**
* Is it possible to delete enrol instance via standard UI?
* Is it possible to delete enrol instance via standard UI?
*
*
* @param
object
$instance
* @param
stdClass
$instance
* @return bool
* @return bool
*/
*/
public
function
can_delete_instance
(
$instance
)
{
public
function
can_delete_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/self:config'
,
$context
);
return
has_capability
(
'enrol/self:config'
,
$context
);
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
$context
=
context_course
::
instance
(
$instance
->
courseid
);
return
has_capability
(
'enrol/self:config'
,
$context
);
}
}
}
enrol/upgrade.txt
View file @
b5a289c4
...
@@ -4,6 +4,8 @@ information provided here is intended especially for developers.
...
@@ -4,6 +4,8 @@ information provided here is intended especially for developers.
=== 2.8 ===
=== 2.8 ===
* enrol_plugin::instance_deleteable() is deprecated and has been replaced by enrol_plugin::can_delete_instance()
* enrol_plugin::instance_deleteable() is deprecated and has been replaced by enrol_plugin::can_delete_instance()
* enrol_plugin::can_hide_show_instance() is a new function to control who can hide/show enrolment instances.
Returns true by default but plugins must implement their own logic.
=== 2.6 ===
=== 2.6 ===
...
...
lib/enrollib.php
View file @
b5a289c4
...
@@ -1554,13 +1554,24 @@ abstract class enrol_plugin {
...
@@ -1554,13 +1554,24 @@ abstract class enrol_plugin {
/**
/**
* Is it possible to delete enrol instance via standard UI?
* Is it possible to delete enrol instance via standard UI?
*
*
* @param
object
$instance
* @param
stdClass
$instance
* @return bool
* @return bool
*/
*/
public
function
can_delete_instance
(
$instance
)
{
public
function
can_delete_instance
(
$instance
)
{
return
false
;
return
false
;
}
}
/**
* Is it possible to hide/show enrol instance via standard UI?
*
* @param stdClass $instance
* @return bool
*/
public
function
can_hide_show_instance
(
$instance
)
{
debugging
(
"The enrolment plugin '"
.
$this
->
get_name
()
.
"' should override the function can_hide_show_instance()."
,
DEBUG_DEVELOPER
);
return
true
;
}
/**
/**
* Returns link to manual enrol UI if exists.
* Returns link to manual enrol UI if exists.
* Does the access control tests automatically.
* Does the access control tests automatically.
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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