mirror of
https://github.com/catalyst/moodle-auth_outage.git
synced 2026-05-17 05:48:43 +02:00
Compare commits
2 Commits
TOTARA_13_
...
admin-mess
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
244084b4c0 | ||
|
|
c6cee3cd4f |
@@ -96,6 +96,79 @@ class outagedb {
|
||||
return new outage($outage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Also sends all admins the event as a message
|
||||
*
|
||||
* @param $outage
|
||||
* @param $event
|
||||
*/
|
||||
private static function notify($outage, $event) {
|
||||
|
||||
$admins = get_admins();
|
||||
|
||||
foreach ($admins as $admin) {
|
||||
self::notify_user($outage, $event, $admin);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Send outage info to one user
|
||||
*
|
||||
* @param $outage outage
|
||||
* @param $event event
|
||||
* @param $to user object
|
||||
*/
|
||||
private static function notify_user($outage, $event, $to) {
|
||||
|
||||
global $SITE, $CFG;
|
||||
|
||||
$from = \core_user::get_user($event->userid);
|
||||
$fields = [
|
||||
'site_shortname' => $SITE->shortname,
|
||||
'site_fullname' => $SITE->fullname,
|
||||
'site_wwwroot' => $CFG->wwwroot,
|
||||
|
||||
'outage_id' => $outage->id,
|
||||
'outage_title' => $outage->get_title(),
|
||||
'outage_desc' => $outage->get_description(),
|
||||
'outage_start' => userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
|
||||
'outage_stop' => userdate($outage->stoptime, get_string('datetimeformat', 'auth_outage')),
|
||||
'outage_duration' => format_time($outage->get_duration_planned()),
|
||||
|
||||
'event_name' => $event->get_name(),
|
||||
'event_desc' => $event->get_description(),
|
||||
'event_link' => $event->get_url()->out(),
|
||||
|
||||
'from_name' => fullname($from),
|
||||
'to_name' => fullname($to),
|
||||
'prefs_link' => (new \moodle_url('/message/notificationpreferences.php'))->out(),
|
||||
|
||||
];
|
||||
|
||||
$message = new \core\message\message();
|
||||
$message->component = 'auth_outage';
|
||||
$message->name = 'updatenotify';
|
||||
$message->userto = $to;
|
||||
$message->subject = get_string('messagesubject', 'auth_outage', $fields);
|
||||
$message->fullmessage = get_string('messagetext', 'auth_outage', $fields);
|
||||
$message->fullmessagehtml = get_string('messagehtml', 'auth_outage', $fields);
|
||||
$message->fullmessageformat = FORMAT_HTML;
|
||||
|
||||
$threadid = generate_email_messageid('outage' . $outage->id);
|
||||
$message->userfrom = $from;
|
||||
$message->userfrom->customheaders = [
|
||||
"In-Reply-To: $threadid",
|
||||
"References: $threadid",
|
||||
"Thread-Topic: " . $message->subject,
|
||||
"Thread-Index: $threadid",
|
||||
];
|
||||
|
||||
$message->notification = '1';
|
||||
$messageid = message_send($message);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves an outage to the database.
|
||||
*
|
||||
@@ -126,6 +199,7 @@ class outagedb {
|
||||
]);
|
||||
$event->add_record_snapshot('auth_outage', (object)(array) $outage);
|
||||
$event->trigger();
|
||||
self::notify($outage, $event);
|
||||
|
||||
// Create calendar entry.
|
||||
calendar::create($outage);
|
||||
@@ -140,6 +214,7 @@ class outagedb {
|
||||
|
||||
$event->add_record_snapshot('auth_outage', (object)(array) $outage);
|
||||
$event->trigger();
|
||||
self::notify($outage, $event);
|
||||
|
||||
// Remove the createdby field so it does not get updated.
|
||||
unset($outage->createdby);
|
||||
@@ -183,6 +258,7 @@ class outagedb {
|
||||
|
||||
$event->add_record_snapshot('auth_outage', $previous);
|
||||
$event->trigger();
|
||||
self::notify($outage, $event);
|
||||
|
||||
// Delete it and remove from calendar.
|
||||
$DB->delete_records('auth_outage', ['id' => $id]);
|
||||
|
||||
@@ -39,13 +39,23 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_created extends base {
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventoutagecreated', 'auth_outage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_description() {
|
||||
return "The user with the id '{$this->userid}' created outage {$this->other['id']} '{$this->other['title']}'";
|
||||
return "The user with the id '{$this->userid}' scheduled outage {$this->other['id']} '{$this->other['title']}'";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,16 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_deleted extends base {
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventoutagedeleted', 'auth_outage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
|
||||
@@ -39,6 +39,16 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class outage_updated extends base {
|
||||
|
||||
/**
|
||||
* Return localised event name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function get_name() {
|
||||
return get_string('eventoutageupdated', 'auth_outage');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns non-localised event description with id's for admin use only.
|
||||
*
|
||||
|
||||
37
db/access.php
Normal file
37
db/access.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines capabilities
|
||||
*
|
||||
* @package auth_outage
|
||||
* @copyright 2020 Brendan Heywood <brendan@catalyst-au.net>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$capabilities = [
|
||||
'auth/outage:updatenotify' => [
|
||||
'captype' => 'write',
|
||||
'riskbitmask' => RISK_XSS,
|
||||
'contextlevel' => CONTEXT_SYSTEM,
|
||||
'archetypes' => [
|
||||
'manager' => CAP_ALLOW,
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
32
db/messages.php
Normal file
32
db/messages.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines message providers for outage
|
||||
*
|
||||
* @package auth_outage
|
||||
* @copyright 2020 Brendan Heywood <brendan@catalyst-au.net>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$messageproviders = [
|
||||
'updatenotify' => [
|
||||
'capability' => 'auth/outage:updatenotify',
|
||||
]
|
||||
];
|
||||
|
||||
@@ -90,6 +90,9 @@ $string['defaultdescriptiondescription'] = 'Default warning message for outages.
|
||||
$string['defaultdescriptionvalue'] = 'There is an scheduled maintenance from {{start}} to {{stop}} and our system will not be available during that time.';
|
||||
$string['description'] = 'Public Description';
|
||||
$string['description_help'] = 'A full description of the outage, publicly visible by all users.';
|
||||
$string['eventoutagecreated'] = 'Outage scheduled';
|
||||
$string['eventoutagedeleted'] = 'Outage cancelled';
|
||||
$string['eventoutageupdated'] = 'Outage updated';
|
||||
$string['finish'] = 'Finish';
|
||||
$string['info15secondsbefore'] = '15 seconds before';
|
||||
$string['infoendofoutage'] = 'end of outage';
|
||||
@@ -110,6 +113,45 @@ $string['messageoutagebackonline'] = 'We are back online!';
|
||||
$string['messageoutagebackonlinedescription'] = 'You may resume browsing safely.';
|
||||
$string['messageoutageongoing'] = 'Back online at {$a->stop}.';
|
||||
$string['messageoutagewarning'] = 'Shutting down in {{countdown}}';
|
||||
$string['messageprovider:updatenotify'] = 'Changes to planned outages';
|
||||
$string['messagesubject'] = '[{$a->site_shortname}] {$a->event_name} #{$a->outage_id}: {$a->outage_start}';
|
||||
$string['messagetext'] = '{$a->event_name}
|
||||
|
||||
{$a->site_fullname} ({$a->site_wwwroot})
|
||||
|
||||
{$a->event_link}
|
||||
|
||||
ID: {$a->outage_id}
|
||||
NAME: {$a->outage_title}
|
||||
START: {$a->outage_start}
|
||||
DURATION: {$a->outage_duration}
|
||||
DESCRIPTION:
|
||||
{$a->outage_desc}
|
||||
|
||||
--
|
||||
|
||||
To unsubscribe visit:
|
||||
{$a->prefs_link}';
|
||||
$string['messagehtml'] = '
|
||||
<h3>{$a->event_name}</h3>
|
||||
|
||||
<p>{$a->site_fullname} (<a href="{$a->site_wwwroot}">{$a->site_wwwroot}</a>)</p>
|
||||
|
||||
<p><a href="{$a->event_link}">{$a->event_link}</a></p>
|
||||
|
||||
<h4>Name:</h4>
|
||||
<p>{$a->outage_title}</p>
|
||||
<h4>Start:</h4>
|
||||
<p>{$a->outage_start}</p>
|
||||
<h4>Duration:</h4>
|
||||
<p>{$a->outage_duration}</p>
|
||||
<h4>Description:</h4>
|
||||
<p>{$a->outage_desc}</p>
|
||||
|
||||
<hr>
|
||||
<p>To unsubscribe visit:<br>
|
||||
<a href="{$a->prefs_link}">{$a->prefs_link}</a></p>
|
||||
';
|
||||
$string['na'] = 'n/a';
|
||||
$string['notfound'] = 'No outages found.';
|
||||
$string['outageedit'] = 'Edit outage';
|
||||
|
||||
Reference in New Issue
Block a user