Skip to content

Commit

Permalink
bugfix: fix token expiry check in admin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhilton committed Oct 24, 2024
1 parent 83b2053 commit bb4e600
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
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
2 changes: 1 addition & 1 deletion lang/en/tool_objectfs.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,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';
11 changes: 11 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,15 @@
}
}

// 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));
}

$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

0 comments on commit bb4e600

Please sign in to comment.