Added capability to determine who can receive a certificate (#270)
This commit is contained in:
parent
f00a0d739d
commit
cd9cf91769
7 changed files with 57 additions and 10 deletions
|
@ -14,6 +14,7 @@ Note - All hash comments refer to the issue number. Eg. #169 refers to https://g
|
||||||
- Added ability to specify the current date for date related elements (#289).
|
- Added ability to specify the current date for date related elements (#289).
|
||||||
- Added QR code element (#146).
|
- Added QR code element (#146).
|
||||||
- Added Date range element (#185).
|
- Added Date range element (#185).
|
||||||
|
- Added new capability to control who can be issued a certificate (#270).
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|
|
@ -112,8 +112,8 @@ class email_certificate_task extends \core\task\scheduled_task {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't want to email those with the capability to manage the certificate.
|
// Only email those with the capability to receive the certificate.
|
||||||
if (has_capability('mod/customcert:manage', $context, $enroluser->id)) {
|
if (!has_capability('mod/customcert:receiveissue', $context, $enroluser->id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,14 @@ $capabilities = array(
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
'mod/customcert:receiveissue' => array(
|
||||||
|
'captype' => 'read',
|
||||||
|
'contextlevel' => CONTEXT_MODULE,
|
||||||
|
'archetypes' => array(
|
||||||
|
'student' => CAP_ALLOW
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
'mod/customcert:viewreport' => array(
|
'mod/customcert:viewreport' => array(
|
||||||
|
|
||||||
'captype' => 'read',
|
'captype' => 'read',
|
||||||
|
|
|
@ -41,6 +41,7 @@ $string['customcert:manageemailothers'] = 'Manage email others setting';
|
||||||
$string['customcert:manageverifyany'] = 'Manage verification setting';
|
$string['customcert:manageverifyany'] = 'Manage verification setting';
|
||||||
$string['customcert:managerequiredtime'] = 'Manage time required setting';
|
$string['customcert:managerequiredtime'] = 'Manage time required setting';
|
||||||
$string['customcert:manageprotection'] = 'Manage protection setting';
|
$string['customcert:manageprotection'] = 'Manage protection setting';
|
||||||
|
$string['customcert:receiveissue'] = 'Receive a certificate';
|
||||||
$string['customcert:view'] = 'View a custom certificate';
|
$string['customcert:view'] = 'View a custom certificate';
|
||||||
$string['customcert:viewreport'] = 'View course report';
|
$string['customcert:viewreport'] = 'View course report';
|
||||||
$string['customcert:viewallcertificates'] = 'View all certificates';
|
$string['customcert:viewallcertificates'] = 'View all certificates';
|
||||||
|
|
|
@ -44,6 +44,39 @@ class mod_customcert_task_email_certificate_task_testcase extends advanced_testc
|
||||||
$this->resetAfterTest();
|
$this->resetAfterTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the email certificate task for users without a capability to receive a certificate.
|
||||||
|
*/
|
||||||
|
public function test_email_certificates_no_cap() {
|
||||||
|
global $DB;
|
||||||
|
|
||||||
|
// Create a course.
|
||||||
|
$course = $this->getDataGenerator()->create_course();
|
||||||
|
|
||||||
|
// Create some users.
|
||||||
|
$user1 = $this->getDataGenerator()->create_user();
|
||||||
|
$user2 = $this->getDataGenerator()->create_user();
|
||||||
|
|
||||||
|
// Enrol two of them in the course as students but revoke their right to receive a certificate issue.
|
||||||
|
$roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
|
||||||
|
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
|
||||||
|
$this->getDataGenerator()->enrol_user($user2->id, $course->id);
|
||||||
|
|
||||||
|
unassign_capability('mod/customcert:receiveissue', $roleids['student']);
|
||||||
|
|
||||||
|
// Create a custom certificate.
|
||||||
|
$this->getDataGenerator()->create_module('customcert', ['course' => $course->id, 'emailstudents' => 1]);
|
||||||
|
|
||||||
|
// Run the task.
|
||||||
|
$sink = $this->redirectEmails();
|
||||||
|
$task = new \mod_customcert\task\email_certificate_task();
|
||||||
|
$task->execute();
|
||||||
|
$emails = $sink->get_messages();
|
||||||
|
|
||||||
|
// Confirm that we did not send any emails.
|
||||||
|
$this->assertCount(0, $emails);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the email certificate task for students.
|
* Tests the email certificate task for students.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
|
|
||||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||||
|
|
||||||
$plugin->version = 2018051708; // The current module version (Date: YYYYMMDDXX).
|
$plugin->version = 2018051709; // The current module version (Date: YYYYMMDDXX).
|
||||||
$plugin->requires = 2018051700; // Requires this Moodle version (3.5).
|
$plugin->requires = 2018051700; // Requires this Moodle version (3.5).
|
||||||
$plugin->cron = 0; // Period for cron to check this module (secs).
|
$plugin->cron = 0; // Period for cron to check this module (secs).
|
||||||
$plugin->component = 'mod_customcert';
|
$plugin->component = 'mod_customcert';
|
||||||
|
|
||||||
$plugin->maturity = MATURITY_STABLE;
|
$plugin->maturity = MATURITY_STABLE;
|
||||||
$plugin->release = "3.5.7"; // User-friendly version number.
|
$plugin->release = "3.5.8"; // User-friendly version number.
|
||||||
|
|
16
view.php
16
view.php
|
@ -43,6 +43,7 @@ require_login($course, false, $cm);
|
||||||
$context = context_module::instance($cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
require_capability('mod/customcert:view', $context);
|
require_capability('mod/customcert:view', $context);
|
||||||
|
|
||||||
|
$canreceive = has_capability('mod/customcert:receiveissue', $context);
|
||||||
$canmanage = has_capability('mod/customcert:manage', $context);
|
$canmanage = has_capability('mod/customcert:manage', $context);
|
||||||
$canviewreport = has_capability('mod/customcert:viewreport', $context);
|
$canviewreport = has_capability('mod/customcert:viewreport', $context);
|
||||||
|
|
||||||
|
@ -134,11 +135,14 @@ if (!$downloadown && !$downloadissue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the button to download the customcert.
|
// Create the button to download the customcert.
|
||||||
$linkname = get_string('getcustomcert', 'customcert');
|
$downloadbutton = '';
|
||||||
$link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true));
|
if ($canreceive) {
|
||||||
$downloadbutton = new single_button($link, $linkname, 'post', true);
|
$linkname = get_string('getcustomcert', 'customcert');
|
||||||
$downloadbutton->class .= ' m-b-1'; // Seems a bit hackish, ahem.
|
$link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true));
|
||||||
$downloadbutton = $OUTPUT->render($downloadbutton);
|
$downloadbutton = new single_button($link, $linkname, 'post', true);
|
||||||
|
$downloadbutton->class .= ' m-b-1'; // Seems a bit hackish, ahem.
|
||||||
|
$downloadbutton = $OUTPUT->render($downloadbutton);
|
||||||
|
}
|
||||||
|
|
||||||
// Output all the page data.
|
// Output all the page data.
|
||||||
echo $OUTPUT->header();
|
echo $OUTPUT->header();
|
||||||
|
@ -154,7 +158,7 @@ if (!$downloadown && !$downloadissue) {
|
||||||
}
|
}
|
||||||
echo $OUTPUT->footer($course);
|
echo $OUTPUT->footer($course);
|
||||||
exit();
|
exit();
|
||||||
} else { // Output to pdf.
|
} else if ($canreceive) { // Output to pdf.
|
||||||
// Set the userid value of who we are downloading the certificate for.
|
// Set the userid value of who we are downloading the certificate for.
|
||||||
$userid = $USER->id;
|
$userid = $USER->id;
|
||||||
if ($downloadown) {
|
if ($downloadown) {
|
||||||
|
|
Loading…
Reference in a new issue