Skip to content
Snippets Groups Projects
Commit 4e2f9795 authored by Michael Lee's avatar Michael Lee
Browse files

Upgrading drupal/msqrole (1.0.8 => 1.0.10)

parent c0484479
No related branches found
No related tags found
No related merge requests found
Showing
with 191 additions and 66 deletions
......@@ -5838,26 +5838,28 @@
},
{
"name": "drupal/msqrole",
"version": "1.0.8",
"version": "1.0.10",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/msqrole.git",
"reference": "1.0.8"
"reference": "1.0.10"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/msqrole-1.0.8.zip",
"reference": "1.0.8",
"shasum": "7ca4924a0f0d23ad44701c5d9d69fa92d47fb3de"
"url": "https://ftp.drupal.org/files/projects/msqrole-1.0.10.zip",
"reference": "1.0.10",
"shasum": "90867c8709093ffa83f5b06c5a6088e9bc30a30f"
},
"require": {
"drupal/core": "^8.8.4 || ^9 || ^10"
"drupal/core": "^9.4 || ^10",
"drupal/token": "~1",
"php": ">=7.4"
},
"type": "drupal-module",
"extra": {
"drupal": {
"version": "1.0.8",
"datestamp": "1650607669",
"version": "1.0.10",
"datestamp": "1690031508",
"security-coverage": {
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
......@@ -5874,7 +5876,7 @@
"homepage": "https://www.drupal.org/user/3612901"
}
],
"description": "Masquerades a user based on role, and not as another user",
"description": "Allows the user to masquerade as certain roles rather than specific users.",
"homepage": "https://www.drupal.org/project/msqrole",
"support": {
"source": "https://git.drupalcode.org/project/msqrole"
......
......@@ -18,8 +18,8 @@
'7b11c4dc42b3b3023073cb14e519683c' => $vendorDir . '/ralouphie/getallheaders/src/getallheaders.php',
'c964ee0ededf28c96ebd9db5099ef910' => $vendorDir . '/guzzlehttp/promises/src/functions_include.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => $vendorDir . '/guzzlehttp/psr7/src/functions_include.php',
'23c18046f52bef3eea034657bafda50f' => $vendorDir . '/symfony/polyfill-php81/bootstrap.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => $vendorDir . '/guzzlehttp/guzzle/src/functions_include.php',
'23c18046f52bef3eea034657bafda50f' => $vendorDir . '/symfony/polyfill-php81/bootstrap.php',
'c9d07b32a2e02bc0fc582d4f0c1b56cc' => $vendorDir . '/laminas/laminas-servicemanager/src/autoload.php',
'3e41e0554275033aae3e9e7e056c2d14' => $vendorDir . '/longwave/laminas-diactoros/src/functions/create_uploaded_file.php',
'f4ee20bfdee1006b0970e8d951bea11e' => $vendorDir . '/longwave/laminas-diactoros/src/functions/marshal_headers_from_sapi.php',
......
......@@ -19,8 +19,8 @@ class ComposerStaticInit5c689ffcd54b9e495ed983fdce09b530
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
'c964ee0ededf28c96ebd9db5099ef910' => __DIR__ . '/..' . '/guzzlehttp/promises/src/functions_include.php',
'a0edc8309cc5e1d60e3047b5df6b7052' => __DIR__ . '/..' . '/guzzlehttp/psr7/src/functions_include.php',
'23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php',
'37a3dc5111fe8f707ab4c132ef1dbc62' => __DIR__ . '/..' . '/guzzlehttp/guzzle/src/functions_include.php',
'23c18046f52bef3eea034657bafda50f' => __DIR__ . '/..' . '/symfony/polyfill-php81/bootstrap.php',
'c9d07b32a2e02bc0fc582d4f0c1b56cc' => __DIR__ . '/..' . '/laminas/laminas-servicemanager/src/autoload.php',
'3e41e0554275033aae3e9e7e056c2d14' => __DIR__ . '/..' . '/longwave/laminas-diactoros/src/functions/create_uploaded_file.php',
'f4ee20bfdee1006b0970e8d951bea11e' => __DIR__ . '/..' . '/longwave/laminas-diactoros/src/functions/marshal_headers_from_sapi.php',
......
......@@ -6071,30 +6071,32 @@
},
{
"name": "drupal/msqrole",
"version": "1.0.8",
"version_normalized": "1.0.8.0",
"version": "1.0.10",
"version_normalized": "1.0.10.0",
"source": {
"type": "git",
"url": "https://git.drupalcode.org/project/msqrole.git",
"reference": "1.0.8"
"reference": "1.0.10"
},
"dist": {
"type": "zip",
"url": "https://ftp.drupal.org/files/projects/msqrole-1.0.8.zip",
"reference": "1.0.8",
"shasum": "7ca4924a0f0d23ad44701c5d9d69fa92d47fb3de"
"url": "https://ftp.drupal.org/files/projects/msqrole-1.0.10.zip",
"reference": "1.0.10",
"shasum": "90867c8709093ffa83f5b06c5a6088e9bc30a30f"
},
"require": {
"drupal/core": "^8.8.4 || ^9 || ^10"
"drupal/core": "^9.4 || ^10",
"drupal/token": "~1",
"php": ">=7.4"
},
"type": "drupal-module",
"extra": {
"drupal": {
"version": "1.0.8",
"datestamp": "1650607669",
"version": "1.0.10",
"datestamp": "1690031508",
"security-coverage": {
"status": "not-covered",
"message": "Project has not opted into security advisory coverage!"
"status": "covered",
"message": "Covered by Drupal's security advisory policy"
}
}
},
......@@ -6109,7 +6111,7 @@
"homepage": "https://www.drupal.org/user/3612901"
}
],
"description": "Masquerades a user based on role, and not as another user",
"description": "Allows the user to masquerade as certain roles rather than specific users.",
"homepage": "https://www.drupal.org/project/msqrole",
"support": {
"source": "https://git.drupalcode.org/project/msqrole"
......
......@@ -3,7 +3,7 @@
'name' => 'osu-asc-webservices/d8-upstream',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '8e8d09103abc6af07826c501f2e89361a15286f4',
'reference' => 'c04844796ef3d7d8ec36f41e833624e3c88f0ab1',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......@@ -1001,9 +1001,9 @@
'dev_requirement' => false,
),
'drupal/msqrole' => array(
'pretty_version' => '1.0.8',
'version' => '1.0.8.0',
'reference' => '1.0.8',
'pretty_version' => '1.0.10',
'version' => '1.0.10.0',
'reference' => '1.0.10',
'type' => 'drupal-module',
'install_path' => __DIR__ . '/../../web/modules/msqrole',
'aliases' => array(),
......@@ -1564,7 +1564,7 @@
'osu-asc-webservices/d8-upstream' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
'reference' => '8e8d09103abc6af07826c501f2e89361a15286f4',
'reference' => 'c04844796ef3d7d8ec36f41e833624e3c88f0ab1',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
......
.idea/
.DS_Store
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
{
"name": "drupal/msqrole",
"type": "drupal-module",
"description": "Allows the user to masquerade as certain roles rather than specific users.",
"require": {
"php": ">=7.4",
"drupal/core": "^9.4 || ^10",
"drupal/token": "~1"
},
"minimum-stability": "dev"
}
html {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.masquerade-role-status {
opacity: 0.5;
transition: opacity .4s ease-in-out;
transition: .4s ease-in-out;
border-top-right-radius: 10px;
background: #1d5fc3;
position: fixed;
z-index: 2000001;
padding: 10px 20px;
bottom: 0;
bottom: -60px;
left: 0;
-moz-box-shadow: inset -2px 2px 10px 0 #000000;
-webkit-box-shadow: inset -2px 2px 10px 0 #000000;
......@@ -23,6 +17,7 @@ html {
.masquerade-role-status:focus,
.masquerade-role-status:focus-within {
opacity: 1;
bottom: 0;
}
.masquerade-role-status .roles {
......
(function ($, Drupal, drupalSettings) {
$('body').prepend(drupalSettings.msqrole.markup);
$('body').append(drupalSettings.msqrole.markup);
})(jQuery, Drupal, drupalSettings);
......@@ -2,10 +2,12 @@ name: 'Masquerade as Role'
description: 'Masquerades a user based on role, and not as another user'
package: 'Administration'
type: module
core_version_requirement: ^8.8.4 || ^9 || ^10
core_version_requirement: ^9.4 || ^10
configure: msqrole.settings_form
dependencies:
- token:token
# Information added by Drupal.org packaging script on 2022-04-22
version: '1.0.8'
# Information added by Drupal.org packaging script on 2023-07-22
version: '1.0.10'
project: 'msqrole'
datestamp: 1650607671
datestamp: 1690031510
<?php
use Drupal\Core\Render\Renderer;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
use Drupal\user\Entity\Role;
/**
* Implements hook_help().
......@@ -30,12 +30,26 @@ function msqrole_theme() {
];
}
/**
* Implements hook_entity_type_alter().
*/
function msqrole_entity_type_alter(array &$entity_types) {
/**
* @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types
*/
// Set the user class, because we need to override the getRoles method.
$entity_types['user']
->setClass('Drupal\\msqrole\\Entity\\MasqueradeRoleUser');
}
/**
* Implements hook_user_logout().
*/
function msqrole_user_logout($account) {
/** @var RoleManager $roleManager */
if (!$role_manager = Drupal::service('msqrole.manager')) {
/**
* @var \Drupal\msqrole\RoleManagerInterface $roleManager
*/
if (!$role_manager = \Drupal::service('msqrole.manager')) {
return;
}
......@@ -50,7 +64,7 @@ function msqrole_page_attachments(array &$page) {
/**
* @var \Drupal\msqrole\RoleManagerInterface $roleManager
*/
if (!$role_manager = Drupal::service('msqrole.manager')) {
if (!$role_manager = \Drupal::service('msqrole.manager')) {
return;
}
......@@ -60,12 +74,12 @@ function msqrole_page_attachments(array &$page) {
}
$roles = [];
foreach ($current_user->getRoles() as $role) {
if ($role === 'authenticated') {
foreach ($current_user->getRoles() as $role_id) {
if ($role_id === 'authenticated') {
continue;
}
$current = \Drupal\user\Entity\Role::load($role);
$roles[$role] = $current->label();
$role = Role::load($role_id);
$roles[$role_id] = $role->label();
}
$render = [
......@@ -79,12 +93,12 @@ function msqrole_page_attachments(array &$page) {
],
];
/** @var Renderer $renderer */
/**
* @var \Drupal\Core\Render\RendererInterface $renderer
*/
$renderer = \Drupal::service('renderer');
$settings_js = [
$page['#attached']['drupalSettings']['msqrole'] = [
'markup' => $renderer->renderPlain($render),
];
$page['#attached']['drupalSettings']['msqrole'] = $settings_js;
$page['#attached']['library'][] = 'msqrole/msqrole.status';
}
services:
msqrole.manager:
class: Drupal\msqrole\RoleManager
arguments: [ '@user.data', '@entity_type.manager', '@config.factory' ]
arguments: [ '@user.data', '@entity_type.manager', '@config.factory', '@token' ]
current_user:
class: Drupal\msqrole\MasqueradeAccountProxy
arguments: [ '@event_dispatcher', '@msqrole.manager' ]
......@@ -24,14 +24,14 @@ class MasqueradeRoleReset extends ControllerBase {
*
* @var \Drupal\msqrole\RoleManagerInterface
*/
protected $roleManager;
protected RoleManagerInterface $roleManager;
/**
* The redirect destination object.
*
* @var \Drupal\Core\Routing\RedirectDestinationInterface
*/
protected $destination;
protected RedirectDestinationInterface $destination;
/**
* MasqueradeRoleReset constructor.
......@@ -66,10 +66,11 @@ public static function create(ContainerInterface $container) {
public function reset() {
$this->roleManager->removeData($this->currentUser()->id());
// Invalidate cache tags
// Invalidate cache tags.
try {
$this->roleManager->invalidateTags($this->currentUser()->id());
} catch (InvalidPluginDefinitionException | PluginNotFoundException $e) {
// Do nothing if this fails.
}
try {
......@@ -78,7 +79,9 @@ public function reset() {
return $this->redirect($destination->getRouteName(), $destination->getRouteParameters());
}
} catch(\Exception $e) {
// Do nothing, just redirect to the front page.
}
return $this->redirect('<front>');
}
......
......@@ -25,9 +25,6 @@ public static function callback() {
$roles = $role_manager->getConfigurableRoles();
$permissions = [];
/**
* @var \Drupal\user\RoleInterface $role
*/
foreach ($roles as $role) {
$permissions['masquerade as ' . $role->id()] = [
'title' => t('Masquerade as :role', [
......
<?php
namespace Drupal\msqrole\Entity;
use Drupal\msqrole\RoleManagerInterface;
use Drupal\user\Entity\User;
use Drupal\user\RoleInterface;
class MasqueradeRoleUser extends User {
/**
* The role manager.
*
* @var \Drupal\msqrole\RoleManagerInterface
*/
protected RoleManagerInterface $roleManager;
/**
* Returns the role manager.
*
* @return \Drupal\msqrole\RoleManagerInterface
*/
protected function roleManager(): RoleManagerInterface {
if (!isset($this->roleManager)) {
$this->roleManager = \Drupal::service('msqrole.manager');
}
return $this->roleManager;
}
/**
* {@inheritdoc}
*/
public function getRoles($exclude_locked_roles = FALSE) {
if (!$this->roleManager()->isActive($this->id())) {
return parent::getRoles($exclude_locked_roles);
}
$roles = $this->roleManager()->getRoles($this->id());
if ($exclude_locked_roles) {
unset($roles[RoleInterface::ANONYMOUS_ID]);
unset($roles[RoleInterface::AUTHENTICATED_ID]);
}
return $roles;
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class MasqueradeRoleForm extends FormBase implements ContainerInjectionInterface
*
* @var \Drupal\msqrole\RoleManagerInterface
*/
protected $roleManager;
protected RoleManagerInterface $roleManager;
/**
* MasqueradeRoleForm constructor.
......
......@@ -2,9 +2,12 @@
namespace Drupal\msqrole\Form;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Render\RendererInterface;
use Drupal\msqrole\RoleManagerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Class MasqueradeRoleSettings
......@@ -13,6 +16,37 @@
*/
class MasqueradeRoleSettings extends ConfigFormBase {
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface
*/
protected RendererInterface $renderer;
/**
* Constructs the settings form.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
* @param \Drupal\Core\Render\RendererInterface $renderer
* The renderer.
*/
public function __construct(ConfigFactoryInterface $config_factory, RendererInterface $renderer) {
parent::__construct($config_factory);
$this->renderer = $renderer;
}
/**
* {@inheritDoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('config.factory'),
$container->get('renderer')
);
}
/**
* {@inheritdoc}
*/
......@@ -42,11 +76,27 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'inline_template',
'#template' => '<strong>Default/always enabled tags:</strong><pre>{{ tags }}</pre>',
'#context' => [
'tags' => print_r(implode(PHP_EOL,
array_merge(RoleManagerInterface::TAGS_TO_INVALIDATE, ['user:{current_user.id}'])), TRUE)
'tags' => print_r(implode(PHP_EOL, RoleManagerInterface::TAGS_TO_INVALIDATE), TRUE)
],
];
$token_info = [
'#theme' => 'token_tree_link',
'#token_types' => [
'current-date' => 'current-date',
'current-user' => 'current-user',
'current-page' => 'current-page',
'site' => 'site',
'random' => 'random',
'user' => 'user',
],
'#show_restricted' => TRUE,
'#weight' => 90,
];
$form['tags']['#description'] .= '<br />' . $this->t('This field supports tokens. @browse_tokens_link', [
'@browse_tokens_link' => $this->renderer->renderPlain($token_info),
]);
return $form;
}
......
......@@ -21,7 +21,7 @@ class MasqueradeAccountProxy extends AccountProxy implements AccountProxyInterfa
*
* @var \Drupal\msqrole\RoleManagerInterface
*/
protected $roleManager;
protected RoleManagerInterface $roleManager;
/**
* AccountProxy constructor.
......@@ -54,7 +54,7 @@ protected function getRoleStorage(): RoleStorageInterface {
*/
public function getRoles($exclude_locked_roles = FALSE) {
if (!$this->roleManager->isActive($this->getAccount()->id())) {
return $this->getAccount()->getRoles($exclude_locked_roles);
return parent::getRoles($exclude_locked_roles);
}
return $this->roleManager->getRoles($this->getAccount()->id());
}
......@@ -63,7 +63,7 @@ public function getRoles($exclude_locked_roles = FALSE) {
* {@inheritdoc}
*/
public function hasPermission($permission) {
$default = $this->getAccount()->hasPermission($permission);
$default = parent::hasPermission($permission);
if (!$this->roleManager->isActive($this->getAccount()->id())) {
return $default;
}
......
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