-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #214 from dof-dss/D8NID-1518
D8 nid 1518
- Loading branch information
Showing
11 changed files
with
407 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: 'Origins Quality Assurance' | ||
type: module | ||
description: 'Tools for QA/testing teams' | ||
core_version_requirement: ^8 || ^9 | ||
package: 'Origins' | ||
dependencies: | ||
- drupal:user | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function origins_qa_install() { | ||
$qa_role = \Drupal::entityTypeManager()->getStorage('user_role')->load('qa'); | ||
|
||
// Create a new 'qa' role as one wasn't found. | ||
if (empty($qa_role)) { | ||
$qa_role = \Drupal\user\Entity\Role::create([ | ||
'id' => 'qa', | ||
'label' => 'Quality Assurance', | ||
]); | ||
|
||
$qa_role->save(); | ||
} | ||
} | ||
|
||
use Drupal\Core\Link; | ||
|
||
/** | ||
* Implements hook_requirements(). | ||
*/ | ||
function origins_qa_requirements($phase) { | ||
$requirements = []; | ||
|
||
if ($phase == 'runtime') { | ||
$accounts = \Drupal::entityTypeManager() | ||
->getListBuilder('user') | ||
->getStorage() | ||
->loadByProperties([ | ||
'roles' => 'qa' | ||
]); | ||
|
||
if (!empty($accounts)) { | ||
$active = 0; | ||
foreach ($accounts as $account) { | ||
($account->isActive()) ? $active++ : NULL; | ||
} | ||
|
||
$summary = t('@active active of @total QA accounts.', [ | ||
'@active' => $active, | ||
'@total' => count($accounts), | ||
]); | ||
|
||
$description = [ | ||
'#markup' => t('These should be removed or disabled on production sites. @link', [ | ||
'@link' => Link::createFromRoute('QA account list', 'origins_qa.manager.list')->toString() | ||
]) | ||
]; | ||
|
||
$requirements['origins_qa'] = [ | ||
'title' => t('Origins QA accounts'), | ||
'severity' => REQUIREMENT_WARNING, | ||
'value' => $summary, | ||
'description' => $description, | ||
]; | ||
} | ||
} | ||
|
||
return $requirements; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
origins_qa: | ||
js: | ||
js/origins_qa.js: {} | ||
dependencies: | ||
- core/jquery | ||
- core/drupal.dialog.ajax | ||
- core/jquery.form |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
origins_qa.manager.enable_all: | ||
title: 'Enable all' | ||
route_name: origins_qa.manager.toggleAll | ||
route_parameters: | ||
action: 'enable' | ||
appears_on: | ||
- origins_qa.manager.list | ||
origins_qa.manager.disable_all: | ||
title: 'Disable all' | ||
route_name: origins_qa.manager.toggleAll | ||
route_parameters: | ||
action: 'disable' | ||
appears_on: | ||
- origins_qa.manager.list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
origins_qa.manager.list: | ||
title: 'QA accounts' | ||
route_name: origins_qa.manager.list | ||
base_route: entity.user.collection | ||
weight: 15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains origins_qa.module. | ||
*/ | ||
|
||
use Drupal\Core\Routing\RouteMatchInterface; | ||
|
||
/** | ||
* Implements hook_help(). | ||
*/ | ||
function origins_qa_help($route_name, RouteMatchInterface $route_match) { | ||
switch ($route_name) { | ||
case 'help.page.origins_qa': | ||
$output = ''; | ||
$output .= '<h3>' . t('About') . '</h3>'; | ||
$output .= '<p>' . t("This module provides management operations for QA accounts. User accounts must be assigned the role 'qa' (Quality Assurance) to appear on the 'QA Accounts' section under 'People'.") . '</p>'; | ||
return $output; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
manage qa accounts: | ||
description: 'View the QA account list and bulk manage QA accounts.' | ||
title: 'Manage QA accounts' | ||
restrict access: TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
origins_qa.manager.list: | ||
path: '/admin/origins/qa/list' | ||
defaults: | ||
_title: 'Quality Assurance accounts' | ||
_controller: '\Drupal\origins_qa\Controller\QaAccountsManager::list' | ||
requirements: | ||
_permission: 'manage qa accounts' | ||
origins_qa.manager.toggleAll: | ||
path: '/admin/origins/qa/toggle-all/{action}' | ||
defaults: | ||
_title: 'Enable / disable all QA accounts' | ||
_controller: '\Drupal\origins_qa\Controller\QaAccountsManager::toggleAll' | ||
requirements: | ||
_permission: 'manage qa accounts' | ||
options: | ||
parameters: | ||
action: | ||
type: string | ||
origins_qa.manager.password_form_modal: | ||
path: '/admin/origins/qa/password-set-modal' | ||
defaults: | ||
_title: 'Modal Form' | ||
_controller: '\Drupal\origins_qa\Controller\QaAccountsManager::displayPasswordForm' | ||
requirements: | ||
_permission: 'manage qa accounts' | ||
options: | ||
_admin_route: TRUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
<?php | ||
|
||
namespace Drupal\origins_qa\Controller; | ||
|
||
use Drupal\Core\Ajax\AjaxResponse; | ||
use Drupal\Core\Ajax\OpenModalDialogCommand; | ||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\Core\Form\FormBuilder; | ||
use Drupal\Core\Url; | ||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
/** | ||
* Controller for Origins QA. | ||
*/ | ||
class QaAccountsManager extends ControllerBase { | ||
|
||
/** | ||
* The form builder. | ||
* | ||
* @var \Drupal\Core\Form\FormBuilder | ||
*/ | ||
protected $formBuilder; | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param \Drupal\Core\Form\FormBuilder $formBuilder | ||
* The form builder. | ||
*/ | ||
public function __construct(FormBuilder $formBuilder) { | ||
$this->formBuilder = $formBuilder; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container | ||
* The Drupal service container. | ||
* | ||
* @return static | ||
*/ | ||
public static function create(ContainerInterface $container) { | ||
return new static( | ||
$container->get('form_builder') | ||
); | ||
} | ||
|
||
/** | ||
* Returns a list of QA accounts. | ||
*/ | ||
public function list() { | ||
$build = []; | ||
|
||
// Fetch all the accounts belonging to the 'qa' role. | ||
$accounts = $this->entityTypeManager() | ||
->getListBuilder('user') | ||
->getStorage() | ||
->loadByProperties([ | ||
'roles' => 'qa' | ||
]); | ||
|
||
$header = [ | ||
'username' => $this->t('Username'), | ||
'status' => $this->t('Status'), | ||
'last_access' => $this->t('Last access'), | ||
'operations' => $this->t('Operations'), | ||
]; | ||
|
||
$rows = []; | ||
|
||
foreach ($accounts as $account) { | ||
$rows[] = [ | ||
$account->label(), | ||
($account->isActive()) ? 'Enabled' : 'Disabled', | ||
($account->getLastAccessedTime() == 0) ? 'Never' : date('d F Y', $account->getLastAccessedTime()), | ||
[ | ||
'data' => [ | ||
'#type' => 'dropbutton', | ||
'#links' => [ | ||
'edit' => [ | ||
'title' => $this->t('Edit'), | ||
'url' => Url::fromRoute('entity.user.edit_form', ['user' => $account->id()]), | ||
], | ||
|
||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
$build['qa_accounts'] = [ | ||
'#type' => 'table', | ||
'#header' => $header, | ||
'#rows' => $rows, | ||
'#empty' => $this->t("There are no accounts on this site associated with the 'qa' (Quality Assurance) role. You will need to assign test accounts to that role for them to show up in this table."), | ||
]; | ||
|
||
if (!empty($accounts)) { | ||
$build['open_modal'] = [ | ||
'#type' => 'link', | ||
'#title' => $this->t('Set passwords for all QA accounts'), | ||
'#url' => Url::fromRoute('origins_qa.manager.password_form_modal'), | ||
'#attributes' => [ | ||
'class' => [ | ||
'use-ajax', | ||
'button', | ||
'button-action', | ||
'button--primary' | ||
], | ||
], | ||
]; | ||
|
||
$build['#attached']['library'][] = 'core/drupal.dialog.ajax'; | ||
} | ||
|
||
return $build; | ||
} | ||
|
||
/** | ||
* Toggles all QA accounts to either active or blocked. | ||
*/ | ||
public function toggleAll($action) { | ||
$accounts = $this->entityTypeManager() | ||
->getListBuilder('user') | ||
->getStorage() | ||
->loadByProperties([ | ||
'roles' => 'qa' | ||
]); | ||
|
||
foreach ($accounts as $account) { | ||
|
||
if ($action === 'enable') { | ||
if (!$account->isActive()) { | ||
$account->activate(); | ||
$account->save(); | ||
} | ||
} | ||
else { | ||
if ($account->isActive()) { | ||
$account->block(); | ||
$account->save(); | ||
} | ||
} | ||
} | ||
|
||
$this->messenger()->addMessage('Updated all QA accounts.'); | ||
|
||
return $this->redirect('origins_qa.manager.list'); | ||
} | ||
|
||
/** | ||
* Ajax callback for displaying the password form. | ||
*/ | ||
public function displayPasswordForm() { | ||
$response = new AjaxResponse(); | ||
|
||
$modal_form = $this->formBuilder->getForm('Drupal\origins_qa\Form\QaPasswordSetForm'); | ||
$response->addCommand(new OpenModalDialogCommand('QA Password form', $modal_form, ['width' => '300'])); | ||
|
||
return $response; | ||
} | ||
|
||
} |
Oops, something went wrong.