Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Totara 17.3+ patchless support. #373

Open
wants to merge 2 commits into
base: TOTARA_12
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ A minimum of PHP7.0 is required to run this plugin.
| Moodle 3.8 -3.9 | master | None |
| Moodle 3.7 | master | MDL-66340 |
| Moodle 3.5-3.6 | master | MDL-66340, MDL-60470 |
| Totara 12-15 | master | MDL-66340, MDL-60470 |
| Totara 12-17 | master | MDL-66340, MDL-60470 |
| Totara 17.3+ | master | None |

## Installation

Expand Down
67 changes: 67 additions & 0 deletions classes/watcher/login_watcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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 tool_mfa\watcher;

defined('MOODLE_INTERNAL') || die();

use core\hook\after_require_login;
use core\hook\after_config;
use totara_core\hook\base;

// Hooks are Totara specific.
if (!class_exists(base::class)) {
return;
}

require_once($CFG->dirroot . '/admin/tool/mfa/lib.php');

/**
* Watches Totara hooks to ensure a user is authenticated.
*
* Forwards on the events until Totara implements:
* `TODO - PLATFORM-117 to create a watcher to enable those functions via this hook`
*
* @package tool_mfa
* @author Liam Kearney <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class login_watcher {
/**
* Forwards calls to tool_mfa_after_require_login.
*
* @param after_require_login $hook
*/
public static function ensure_authenticated(after_require_login $hook) {
tool_mfa_after_require_login(
$hook->courseorid,
$hook->autologinguest,
$hook->cm,
$hook->setwantsurltome,
$hook->preventredirect
);
}

/**
* Forwards calls to tool_mfa_after_config.
*
* @param after_config $hook
*/
public static function check_authenticated(after_config $hook) {
tool_mfa_after_config();
}
}
52 changes: 52 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?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/>.

/**
* Definition of MFA sub-plugins (factors).
*
* @package tool_mfa
* @author Liam Kearney <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

use core\hook\after_require_login;
use core\hook\after_config;
use tool_mfa\watcher\login_watcher;
use totara_core\hook\base;

// Hooks are Totara specific.
if (!class_exists(base::class)) {
return;
}

$watchers = [
[
'hookname' => after_require_login::class,
'callback' => [login_watcher::class, 'ensure_authenticated'],
'includefile' => null,
'priority' => 100,
],
[
'hookname' => after_config::class,
'callback' => [login_watcher::class, 'check_authenticated'],
'includefile' => null,
'priority' => 100,
],
];