Skip to content
Snippets Groups Projects
Commit 3b477434 authored by Lucas Hedding's avatar Lucas Hedding Committed by Lucas Hedding
Browse files

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

parent fec4d81a
No related branches found
No related tags found
No related merge requests found
......@@ -3,3 +3,4 @@ type: module
description: 'Drupal Automatic Updates'
core: 8.x
package: 'Security'
configure: automatic_updates.admin_form
automatic_updates.admin_form:
title: 'Automatic Updates'
route_name: automatic_updates.admin_form
description: 'Configure automatic updates'
parent: system.admin_config_system
automatic_updates.admin_form:
path: '/admin/config/automatic_updates'
defaults:
_form: '\Drupal\automatic_updates\Form\AdminForm'
_title: 'Automatic Updates'
requirements:
_permission: 'administer software updates'
options:
_admin_route: TRUE
......@@ -2,3 +2,4 @@
# TODO: Update to correct end point once it is available. See
# https://www.drupal.org/project/automatic_updates/issues/3045273
psa_endpoint: 'http://localhost/automatic_updates/test-json'
enable_psa: true
......@@ -5,3 +5,6 @@ automatic_updates.settings:
psa_endpoint:
type: string
label: 'Endpoint URI for PSAs'
enable_psa:
type: boolean
label: 'Enable PSA notices'
<?php
namespace Drupal\automatic_updates\Form;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Administration form for automatic updates.
*/
class AdminForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'automatic_updates.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'automatic_updates_admin_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('automatic_updates.settings');
$form['enable_psa'] = [
'#type' => 'checkbox',
'#title' => $this->t('Enable messaging of public service alerts (PSAs)'),
'#default_value' => $config->get('enable_psa'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$form_state->cleanValues();
$config = $this->config('automatic_updates.settings');
foreach ($form_state->getValues() as $key => $value) {
$config->set($key, $value);
}
$config->save();
}
}
......@@ -114,6 +114,10 @@ class AutomaticUpdatesPsa implements AutomaticUpdatesPsaInterface {
public function getPublicServiceMessages() {
$messages = [];
if (!$this->config->get('enable_psa')) {
return $messages;
}
if ($cache = $this->cache->get('automatic_updates_psa')) {
$response = $cache->data;
}
......
......@@ -68,6 +68,16 @@ class AutomaticUpdatesTest extends BrowserTestBase {
drupal_flush_all_caches();
$this->drupalGet(Url::fromRoute('system.admin'));
$this->assertSession()->pageTextContains('Drupal PSA endpoint http://localhost/automatic_updates/test-json-denied is unreachable.');
// Test disabling PSAs.
$end_point = $this->buildUrl(Url::fromRoute('test_automatic_updates.json_test_controller'));
$this->config('automatic_updates.settings')
->set('psa_endpoint', $end_point)
->set('enable_psa', FALSE)
->save();
drupal_flush_all_caches();
$this->drupalGet(Url::fromRoute('system.admin'));
$this->assertSession()->pageTextNotContains('Drupal Core PSA: Critical Release - PSA-2019-02-19');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment