Skip to content

Commit

Permalink
Merge branch 'MDL-74584-master-v1' of https://github.com/mihailges/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed May 6, 2022
2 parents 7aa68e3 + 154dbce commit 48cab7f
Show file tree
Hide file tree
Showing 30 changed files with 387 additions and 7 deletions.
19 changes: 15 additions & 4 deletions admin/modules.php
Expand Up @@ -38,11 +38,22 @@
}

if (!empty($show) and confirm_sesskey()) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($show, true);
$canenablemodule = true;
$modulename = $show;

// Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications,
// modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin
// should continue after these actions or not.
if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) {
$canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions');
}

admin_get_root(true, false); // settings not required - only pages
redirect(new moodle_url('/admin/modules.php'));
if ($canenablemodule) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($show, true);
admin_get_root(true, false); // Settings not required - only pages.
redirect(new moodle_url('/admin/modules.php'));
}
}

echo $OUTPUT->header();
Expand Down
7 changes: 7 additions & 0 deletions admin/upgrade.txt
@@ -1,5 +1,12 @@
This files describes API changes in /admin/*.

=== 4.0.1 ===

* A new callback xxx_pre_enable_plugin_actions has been added in admin/modules.php. Plugins can use this callback to
force additional actions (e.g. displaying notifications, modals, etc.) before enabling the plugin. The expected
return value (bool) from the plugin callback method specifies whether the process of enabling the plugin should
continue after the added actions or not.

=== 3.11 ===

* New admin setting admin_setting_encryptedpassword allows passwords in admin settings to be
Expand Down
5 changes: 3 additions & 2 deletions course/lib.php
Expand Up @@ -391,12 +391,13 @@ function course_integrity_check($courseid, $rawmods = null, $sections = null, $f
* and the value is a lang_string object with a human-readable string.
*
* @param bool $plural If true, the function returns the plural forms of the names.
* @param bool $resetcache If true, the static cache will be reset
* @return lang_string[] Localised human-readable names of all used modules.
*/
function get_module_types_names($plural = false) {
function get_module_types_names($plural = false, $resetcache = false) {
static $modnames = null;
global $DB, $CFG;
if ($modnames === null) {
if ($modnames === null || $resetcache) {
$modnames = array(0 => array(), 1 => array());
if ($allmods = $DB->get_records("modules")) {
foreach ($allmods as $mod) {
Expand Down
11 changes: 11 additions & 0 deletions mod/bigbluebuttonbn/amd/build/accept_dpa.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mod/bigbluebuttonbn/amd/build/accept_dpa.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions mod/bigbluebuttonbn/amd/src/accept_dpa.js
@@ -0,0 +1,56 @@
// 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/>.

/**
* Javascript module for confirming the acceptance of the current data processing agreement before enabling
* the BigBlueButton activity module.
*
* @module mod_bigbluebuttonbn/accept_dpa
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

import ModalForm from 'core_form/modalform';
import Notification from 'core/notification';
import {get_string as getString} from 'core/str';

/**
* Initialize module.
*/
export const init = () => {

const modalForm = new ModalForm({
modalConfig: {
title: getString('enablingbigbluebutton', 'mod_bigbluebuttonbn'),
large: false,
},
formClass: 'mod_bigbluebuttonbn\\form\\accept_dpa',
saveButtonText: getString('enable'),
});

// Once the form has been submitted and successfully processed, reload the page to enable the activity module.
modalForm.addEventListener(modalForm.events.FORM_SUBMITTED, event => {
if (event.detail.result) {
window.location.reload();
} else {
Notification.addNotification({
type: 'error',
message: event.detail.errors.join('<br>')
});
}
});

modalForm.show();
};
104 changes: 104 additions & 0 deletions mod/bigbluebuttonbn/classes/form/accept_dpa.php
@@ -0,0 +1,104 @@
<?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/>.

namespace mod_bigbluebuttonbn\form;

use context;
use moodle_exception;
use moodle_url;
use core_form\dynamic_form;
use mod_bigbluebuttonbn\local\config;

/**
* Accept data processing agreement form presented before enabling the BigBlueButton activity module.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class accept_dpa extends dynamic_form {

/**
* Form definition
*/
protected function definition() {
$this->_form->addElement('html', \html_writer::tag('p',
get_string('enablingbigbluebuttondpainfo', 'mod_bigbluebuttonbn', config::DEFAULT_DPA_URL)));
$this->_form->addElement('checkbox', 'acceptdefaultdpa', false, get_string('acceptdpa', 'mod_bigbluebuttonbn'),
['class' => 'bold']);
$this->_form->addRule('acceptdefaultdpa', get_string('required'), 'required', null, 'client');
}

/**
* Return form context
*
* @return context
*/
protected function get_context_for_dynamic_submission(): context {
return \context_system::instance();
}

/**
* Check if current user has access to this form, otherwise throw exception.
*
* @return void
* @throws moodle_exception
*/
protected function check_access_for_dynamic_submission(): void {
require_capability('moodle/site:config', $this->get_context_for_dynamic_submission());
}

/**
* Process the form submission, used if form was submitted via AJAX.
*
* @return array
*/
public function process_dynamic_submission(): array {
$result = false;
$errors = [];

if ($this->get_data()->acceptdefaultdpa) {
try {
set_config('bigbluebuttonbn_default_dpa_accepted', true);
$result = true;
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
}

return [
'result' => $result,
'errors' => $errors,
];
}

/**
* Load in existing data as form defaults (not applicable).
*
* @return void
*/
public function set_data_for_dynamic_submission(): void {
}

/**
* Returns url to set in $PAGE->set_url() when form is being rendered or submitted via AJAX.
*
* @return moodle_url
*/
protected function get_page_url_for_dynamic_submission(): moodle_url {
return new moodle_url('/admin/modules.php', ['show' => 'bigbluebuttonbn', 'sesskey' => sesskey()]);
}
}
4 changes: 4 additions & 0 deletions mod/bigbluebuttonbn/classes/local/config.php
Expand Up @@ -35,6 +35,9 @@ class config {
/** @var string Default bigbluebutton server shared secret */
public const DEFAULT_SHARED_SECRET = '0b21fcaf34673a8c3ec8ed877d76ae34';

/** @var string Default bigbluebutton data processing agreement url */
public const DEFAULT_DPA_URL = 'https://blindsidenetworks.com/dpa-moodle-free-tier';

/**
* Returns moodle version.
*
Expand Down Expand Up @@ -108,6 +111,7 @@ protected static function defaultvalues() {
'lockonjoin_default' => true,
'lockonjoin_editable' => false,
'welcome_default' => '',
'default_dpa_accepted' => false,
];
}

Expand Down
10 changes: 10 additions & 0 deletions mod/bigbluebuttonbn/classes/settings.php
Expand Up @@ -174,6 +174,16 @@ function() {
$item,
$settingsgeneral
);
$item = new \admin_setting_description(
'bigbluebuttonbn_dpa_info',
'',
get_string('config_dpa_note', 'bigbluebuttonbn', config::DEFAULT_DPA_URL),
);
$this->add_conditional_element(
'dpa_info',
$item,
$settingsgeneral
);
$settingsgeneral->add($item);
$item = new admin_setting_heading(
'bigbluebuttonbn_config_default_messages',
Expand Down
@@ -0,0 +1,58 @@
<?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/>.

declare(strict_types=1);

namespace mod_bigbluebuttonbn\task;

use core\task\adhoc_task;
use core\message\message;
use mod_bigbluebuttonbn\local\config;

/**
* Ad-hoc task to send a notification related to the disabling of the BigBlueButton activity module.
*
* The ad-hoc tasks sends a notification to the administrator informing that the BigBlueButton activity module has
* been disabled and they are required to confirm their acceptance of the data processing agreement prior to
* re-enabling it.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class send_bigbluebutton_module_disabled_notification extends adhoc_task {

/**
* Execute the task.
*/
public function execute(): void {
$message = new message();
$message->component = 'moodle';
$message->name = 'notices';
$message->userfrom = \core_user::get_noreply_user();
$message->userto = get_admin();
$message->notification = 1;
$message->contexturl = (new \moodle_url('/admin/modules.php'))->out(false);
$message->contexturlname = get_string('modsettings', 'admin');
$message->subject = get_string('bigbluebuttondisablednotification_subject', 'mod_bigbluebuttonbn');
$message->fullmessageformat = FORMAT_HTML;
$message->fullmessagehtml = get_string('bigbluebuttondisablednotification', 'mod_bigbluebuttonbn',
config::DEFAULT_DPA_URL);
$message->smallmessage = strip_tags($message->fullmessagehtml);

message_send($message);
}
}
7 changes: 7 additions & 0 deletions mod/bigbluebuttonbn/classes/test/testcase_helper_trait.php
Expand Up @@ -30,6 +30,7 @@
use mod_bigbluebuttonbn\meeting;
use stdClass;
use testing_data_generator;
use core\plugininfo\mod;

trait testcase_helper_trait {
/** @var testing_data_generator|null */
Expand All @@ -47,6 +48,12 @@ trait testcase_helper_trait {
* @return array($context, $cm, $instance) Testable wrapper around the assign class.
*/
protected function create_instance(?stdClass $course = null, array $params = [], array $options = []): array {
// Prior to creating the instance, make sure that the BigBlueButton module is enabled.
$modules = \core_plugin_manager::instance()->get_plugins_of_type('mod');
if (!$modules['bigbluebuttonbn']->is_enabled()) {
mod::enable_plugin('bigbluebuttonbn', true);
}

if (!$course) {
$course = $this->get_course();
}
Expand Down
33 changes: 33 additions & 0 deletions mod/bigbluebuttonbn/db/install.php
@@ -0,0 +1,33 @@
<?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/>.

/**
* Install script for mod_bigbluebuttonbn.
*
* @package mod_bigbluebuttonbn
* @copyright 2022 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

/**
* Perform the post-install procedures.
*/
function xmldb_bigbluebuttonbn_install() {
global $DB;

// Disable the BigBlueButton activity module on new installs by default.
$DB->set_field('modules', 'visible', 0, ['name' => 'bigbluebuttonbn']);
}

0 comments on commit 48cab7f

Please sign in to comment.