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

bugfix: fix token expiry check in admin settings #646

Merged
merged 1 commit into from
Oct 25, 2024
Merged
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
10 changes: 10 additions & 0 deletions classes/check/token_expiry.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class token_expiry extends check {
/**
* Link to ObjectFS settings page.
*
* @return \action_link|null
*/
public function get_action_link(): ?\action_link {
$url = new \moodle_url('/admin/category.php', ['category' => 'tool_objectfs']);
return new \action_link($url, get_string('pluginname', 'tool_objectfs'));
}

/**
* Checks the token expiry time against thresholds
* @return result
Expand Down
11 changes: 0 additions & 11 deletions classes/local/store/azure/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@

namespace tool_objectfs\local\store\azure;

use admin_setting_description;
use SimpleXMLElement;
use stdClass;
use tool_objectfs\check\token_expiry;
use tool_objectfs\local\store\azure\stream_wrapper;
use tool_objectfs\local\store\object_client_base;

Expand Down Expand Up @@ -362,15 +360,6 @@ public function define_client_section($settings, $config) {
new \lang_string('settings:azure:sastoken', 'tool_objectfs'),
new \lang_string('settings:azure:sastoken_help', 'tool_objectfs'), ''));

// Admin_setting_check only exists in 4.5+, in lower versions fallback to a basic description.
if (class_exists('admin_setting_check')) {
$settings->add(new admin_setting_check('tool_objectfs/check_tokenexpiry', new token_expiry(), true));
} else {
$summary = (new token_expiry())->get_result()->get_summary();
$settings->add(new admin_setting_description('tool_objectfs/tokenexpirycheckresult',
get_string('checktoken_expiry', 'tool_objectfs'), $summary));
}

return $settings;
}

Expand Down
4 changes: 3 additions & 1 deletion lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@
$string['settings:testingheader'] = 'Test Settings';
$string['settings:testingdescr'] = 'This setting is mainly for testing purposes and introduces overhead to check the location.';

$string['settings:checksheader'] = 'Checks';

$string['settings:error:numeric'] = 'Please enter a number which is greater than or equal 0.';
$string['settings:notconfigured'] = 'Missing configuration.';
$string['total_deleted_dirs'] = 'Total number of deleted directories: ';
Expand All @@ -273,5 +275,5 @@
$string['checktoken_expiry'] = 'Token expiry';
$string['check:tokenexpiry:expiresin'] = 'Token expires in {$a->dayssince} days on {$a->time}';
$string['check:tokenexpiry:expired'] = 'Token expired for {$a->dayssince} days. Expired on {$a->time}';
$string['check:tokenexpiry:na'] = 'Token expired not implemented for filesystem, or no token is set';
$string['check:tokenexpiry:na'] = 'Token expiry check not implemented for filesystem, or no token is set';
$string['settings:tokenexpirywarnperiod'] = 'Token expiry warn period';
14 changes: 14 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use tool_objectfs\check\token_expiry;

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

require_once(__DIR__ . '/classes/local/manager.php');
Expand Down Expand Up @@ -248,6 +250,18 @@
}
}

$settings->add(new admin_setting_heading('tool_objectfs/checks',
new lang_string('settings:checksheader', 'tool_objectfs'), ''));

// Admin_setting_check only exists in 4.5+, in lower versions fallback to a basic description.
if (class_exists('admin_setting_check')) {
$settings->add(new admin_setting_check('tool_objectfs/check_tokenexpiry', new token_expiry(), true));
} else {
$summary = (new token_expiry())->get_result()->get_summary();
$settings->add(new admin_setting_description('tool_objectfs/tokenexpirycheckresult',
get_string('checktoken_expiry', 'tool_objectfs'), $summary));
}

matthewhilton marked this conversation as resolved.
Show resolved Hide resolved
$settings->add(new admin_setting_heading('tool_objectfs/testsettings',
new lang_string('settings:testingheader', 'tool_objectfs'), ''));

Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

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

$plugin->version = 2024091700; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2024091700; // Same as version.
$plugin->version = 2024102400; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2024102400; // Same as version.
$plugin->requires = 2023042400; // Requires 4.2.
$plugin->component = "tool_objectfs";
$plugin->maturity = MATURITY_STABLE;
Expand Down
Loading