Skip to content
Snippets Groups Projects

Resolve #3226763 "Add separate permission"

Files
8
@@ -9,7 +9,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\flood_control\FloodUnblockManager;
use Drupal\Core\Session\AccountProxy;
use Drupal\Core\Session\AccountProxyInterface;
/**
* Admin form of Flood Unblock.
@@ -47,7 +47,7 @@ class FloodUnblockAdminForm extends FormBase {
/**
* Current user object.
*
* @var \Drupal\Core\Session\AccountProxy
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
@@ -60,10 +60,10 @@ class FloodUnblockAdminForm extends FormBase {
* The database connection.
* @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter
* The date formatter service.
* @param \Drupal\Core\Session\AccountProxy $currentUser
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user service.
*/
public function __construct(FloodUnblockManager $floodUnblockManager, Connection $database, DateFormatterInterface $date_formatter, AccountProxy $currentUser) {
public function __construct(FloodUnblockManager $floodUnblockManager, Connection $database, DateFormatterInterface $date_formatter, AccountProxyInterface $currentUser) {
$this->floodUnblockManager = $floodUnblockManager;
$this->database = $database;
$this->dateFormatter = $date_formatter;
@@ -104,9 +104,10 @@ class FloodUnblockAdminForm extends FormBase {
// Set default markup.
$top_markup = $this->t("List of IP addresses and user ID's that are blocked after multiple failed login attempts. You can remove separate entries.");
// Add link to control settings page if current user haas permission to access it.
if ($this->currentUser->hasPermission('access flood control settings page')) {
$top_markup .= $this->t(" You can configure the login attempt limits and time windows on the <a href=':url'>Flood Control settings page</a>.</p>", [':url' => Url::fromRoute('flood_control.settings')->toString()]);
// Add link to control settings page if current user has permission to
// access it:
if ($this->currentUser->hasPermission('administer flood unblock')) {
$top_markup .= $this->t("You can configure the login attempt limits and time windows on the <a href=':url'>Flood Control settings page</a>.</p>", [':url' => Url::fromRoute('flood_control.settings')->toString()]);
}
// Provides introduction to the table.
@@ -194,6 +195,7 @@ class FloodUnblockAdminForm extends FormBase {
// Defines list of options for tableselect element.
$options[$result->fid] = [
'title' => ['data' => ['#title' => $this->t('Flood id @id', ['@id' => $result->fid])]],
'identifier' => $identifiers[$result->identifier],
'blocked' => $is_blocked ? $this->t('Blocked') : $this->t('Not blocked'),
'event' => $this->floodUnblockManager->getEventLabel($result->event),
@@ -211,14 +213,16 @@ class FloodUnblockAdminForm extends FormBase {
'#empty' => $this->t('There are no failed logins at this time.'),
];
$form['actions'] = ['#type' => 'actions'];
// Provides the remove submit button.
$form['remove'] = [
$form['actions']['remove'] = [
'#type' => 'submit',
'#value' => $this->t('Remove selected items from the flood table'),
'#validate' => ['::validateRemoveItems'],
];
if (count($options) == 0) {
$form['remove']['#disabled'] = TRUE;
$form['actions']['remove']['#disabled'] = TRUE;
}
// Provides the pager element.
Loading