Commit 4196d19e authored by heddn's avatar heddn Committed by heddn
Browse files

Issue #3046858 by heddn, tatarbj: Add admin / config page to enable/disable PSA

parent 68a786b4
......@@ -23,6 +23,10 @@ class AutomaticUpdatesPsa {
public static function getPublicServiceMessages() {
$messages = array();
if (!variable_get('automatic_updates_enable_psa')) {
return $messages;
}
if ($cache = cache_get('automatic_updates_psa')) {
$response = $cache->data;
}
......@@ -31,7 +35,7 @@ class AutomaticUpdatesPsa {
$response = drupal_http_request($psa_endpoint);
if (isset($response->code) && ($response->code == 200)) {
// Set response in cache for 12 hours.
cache_set('automatic_updates_psa', $response, 'cache', REQUEST_TIME + 3600 * 12);
cache_set('automatic_updates_psa', $response, 'cache', variable_get('automatic_updates_check_frequency', REQUEST_TIME + 3600 * 12));
}
else {
watchdog('automatic_updates', 'Drupal PSA endpoint %url is unreachable.', array('%url' => $psa_endpoint), WATCHDOG_ERROR);
......
<?php
/**
* @file
* Administration functions for Automatic Updates module.
*/
/**
* Form callback for administrator interface.
*/
function automatic_updates_admin_form($form, &$form_state) {
$form['description'] = [
'#markup' => '<p>' . t('Public service announcements are compared against the entire code for the site, not just installed extensions.') . '</p>',
];
$form['automatic_updates_enable_psa'] = [
'#type' => 'checkbox',
'#title' => t('Show public service announcements on administrative pages.'),
'#default_value' => variable_get('automatic_updates_enable_psa', TRUE),
];
return system_settings_form($form);
}
......@@ -9,5 +9,6 @@
* Implements hook_uninstall().
*/
function automatic_updates_uninstall() {
variable_del('psa_endpoint_psa_endpoint');
variable_del('automatic_updates_psa_endpoint');
variable_del('automatic_updates_enable_psa');
}
......@@ -31,3 +31,22 @@ function automatic_updates_init() {
}
}
}
/**
* Implements hook_menu().
*/
function automatic_updates_menu() {
$items = [];
$items['admin/config/system/automatic_updates'] = [
'title' => 'Automatic Updates',
'page callback' => 'drupal_get_form',
'page arguments' => ['automatic_updates_admin_form'],
'file' => 'automatic_updates.admin.inc',
'file path' => drupal_get_path('module', 'automatic_updates'),
'access arguments' => ['administer software updates'],
'tab parent' => 'admin/config/system',
];
return $items;
}
......@@ -27,24 +27,35 @@ class AutomaticUpdatesTestCase extends DrupalWebTestCase {
public function setUp() {
parent::setUp(array('automatic_updates', 'automatic_updates_test'));
// Create a user with permission to view the actions administration pages.
$user = $this->drupalCreateUser(array('administer site configuration', 'access administration pages'));
$user = $this->drupalCreateUser(array(
'access administration pages',
'administer site configuration',
'administer software updates',
));
$this->drupalLogin($user);
$psa_endpoint = $this->getAbsoluteUrl('automatic_updates/test-json');
variable_set('automatic_updates_psa_endpoint', $psa_endpoint);
variable_set('automatic_updates_enable_psa', TRUE);
}
/**
* Test automatic updates.
*/
public function testAutomaticUpdates() {
// Test PSAs.
$this->drupalGet('admin');
$this->assertText('Drupal Core PSA: Critical Release - PSA-2019-02-19');
$this->assertNoText('Drupal Core PSA: Critical Release - PSA-Really Old');
$this->assertNoText('Node - Moderately critical - Access bypass - SA-CONTRIB-2019');
$this->assertText('Drupal Contrib Project PSA: Standard - Moderately critical - Access bypass - SA-CONTRIB-2019');
$this->assertText('Drupal Contrib Project PSA: Seven - Moderately critical - Access bypass - SA-CONTRIB-2019');
// Test disabling PSAs.
variable_set('automatic_updates_enable_psa', FALSE);
$this->drupalGet('admin');
$this->assertNoText('Drupal Core PSA: Critical Release - PSA-2019-02-19');
variable_set('automatic_updates_enable_psa', TRUE);
// Test cache.
$psa_endpoint = $this->getAbsoluteUrl('automatic_updates/test-json-denied');
variable_set('automatic_updates_psa_endpoint', $psa_endpoint);
......@@ -54,7 +65,7 @@ class AutomaticUpdatesTestCase extends DrupalWebTestCase {
// Test transmit errors with JSON endpoint.
drupal_flush_all_caches();
$this->drupalGet('admin');
$this->assertText('Drupal PSA endpoint http://localhost/automatic_updates/test-json-denied is unreachable.');
$this->assertText('automatic_updates/test-json-denied is unreachable.');
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment