Skip to content

Commit cbda2d6

Browse files
authored
Merge pull request #1932 from acquia/stage
Merge branch `stage` into `main`
2 parents 7eff702 + ca59bb2 commit cbda2d6

File tree

52 files changed

+1741
-904
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1741
-904
lines changed

composer.lock

+338-338
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?php
2+
3+
namespace Drupal\Tests\acquia_cms_common\Functional;
4+
5+
use Drupal\Tests\BrowserTestBase;
6+
7+
/**
8+
* Tests the filter filter_html.
9+
*
10+
* @group acquia_cms
11+
* @group acquia_cms_common
12+
*/
13+
class FilterFormatTest extends BrowserTestBase {
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected $defaultTheme = 'stark';
19+
20+
/**
21+
* {@inheritdoc}
22+
*/
23+
protected static $modules = [
24+
'acquia_cms_common',
25+
];
26+
27+
/**
28+
* {@inheritdoc}
29+
*/
30+
protected function setUp(): void {
31+
parent::setUp();
32+
33+
$account = $this->drupalCreateUser(['administer filters']);
34+
$this->drupalLogin($account);
35+
}
36+
37+
/**
38+
* Tests the filter filter_html.
39+
*
40+
* @param string $filter_format
41+
* The filter format name.
42+
* @param bool $status
43+
* Status of the field.
44+
*
45+
* @dataProvider providerFilterFormat
46+
*/
47+
public function testFilterBlackListHtmlTags(string $filter_format, bool $status) {
48+
$assert_session = $this->assertSession();
49+
50+
// Visit the filter page.
51+
$this->drupalGet('/admin/config/content/formats/manage/' . $filter_format);
52+
$assert_session->statusCodeEquals(200);
53+
$filter_element = $assert_session->elementExists('css', '#edit-filters-filter-html-status');
54+
$this->assertSame($status, $filter_element->isChecked(), 'Expect checked, but found uncheck.');
55+
56+
}
57+
58+
/**
59+
* Defines an array of modules & permissions to roles.
60+
*/
61+
public static function providerFilterFormat(): array {
62+
return [
63+
[
64+
'full_html',
65+
TRUE,
66+
],
67+
[
68+
'filtered_html',
69+
TRUE,
70+
],
71+
];
72+
}
73+
74+
}

modules/acquia_cms_headless/acquia_cms_headless.info.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ type: module
44
description: 'Provides functionality for Progressively Decoupled and Purely Headless sites using Node and Next JS.'
55
core_version_requirement: ^10 || ^11
66
dependencies:
7-
- acquia_cms_common:acquia_cms_common
87
- acquia_cms_tour:acquia_cms_tour
98
- consumers:consumers
9+
- drupal:block
10+
- drupal:node
11+
- drupal:rest
12+
- drupal:taxonomy
13+
- entity_clone:entity_clone
1014
- jsonapi_extras:jsonapi_extras
1115
- jsonapi_menu_items:jsonapi_menu_items
1216
- next:next_jsonapi
1317
- openapi_jsonapi:openapi_jsonapi
1418
- openapi_ui_redoc:openapi_ui_redoc
1519
- openapi_ui_swagger:openapi_ui_swagger
16-
- drupal:rest
1720
- simple_oauth:simple_oauth
21+
test_dependencies:
22+
- acquia_cms_toolbar:acquia_cms_toolbar

modules/acquia_cms_headless/acquia_cms_headless.install

+13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ function acquia_cms_headless_install($is_syncing) {
1919

2020
// Programmatically create a new "headless" user.
2121
$headless_user->createHeadlessUser();
22+
// Add roles to headless user.
23+
$roles = \Drupal::entityTypeManager()->getStorage('user_role')->loadMultiple([
24+
'content_administrator',
25+
'content_author',
26+
'content_editor',
27+
]);
28+
if ($roles) {
29+
$user = user_load_by_name('headless');
30+
foreach ($roles as $role) {
31+
$user->addRole($role->id());
32+
}
33+
$user->save();
34+
}
2235

2336
// Adds the necessary permissions to roles.
2437
add_next_site_permissions();

modules/acquia_cms_headless/acquia_cms_headless.module

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
use Drupal\user\RoleInterface;
99

1010
/**
11-
* Implements hook_content_model_role_presave_alter().
11+
* Implements hook_entity_insert().
1212
*/
13-
function acquia_cms_headless_content_model_role_presave_alter(RoleInterface &$role) {
13+
function acquia_cms_headless_user_role_insert(RoleInterface $role) {
1414
$role_id = $role->id();
1515
switch ($role->id()) {
1616
case 'content_administrator':

modules/acquia_cms_headless/composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"license": "GPL-2.0-or-later",
55
"type": "drupal-module",
66
"require": {
7-
"drupal/acquia_cms_common": "^1.9 || ^2.1 || ^3.1",
8-
"drupal/acquia_cms_tour": "^2.1.8",
7+
"drupal/acquia_cms_tour": "2.x-dev",
8+
"drupal/entity_clone": "^2.0",
99
"drupal/jsonapi_extras": "^3.26",
1010
"drupal/jsonapi_menu_items": "^1.2",
1111
"drupal/next": "^2.0",
@@ -15,7 +15,8 @@
1515
"drupal/restui": "^1.21"
1616
},
1717
"require-dev": {
18-
"drupal/acquia_claro": "^1.3"
18+
"drupal/acquia_claro": "^1.3",
19+
"drupal/acquia_cms_toolbar": "1.x-dev"
1920
},
2021
"conflict": {
2122
"drupal/consumers": "<1.16",

modules/acquia_cms_headless/config/install/user.role.headless.yml

-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,3 @@ permissions:
1818
- 'bypass node access'
1919
- 'issue subrequests'
2020
- 'view all revisions'
21-
- 'view any unpublished content'
22-
- 'view latest version'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
langcode: en
2+
status: true
3+
dependencies: { }
4+
id: administrator
5+
label: Administrator
6+
weight: -10
7+
is_admin: true
8+
permissions: { }

modules/acquia_cms_headless/modules/acquia_cms_headless_ui/acquia_cms_headless_ui.info.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ type: module
44
core_version_requirement: ^10 || ^11
55
description: 'Implements Pure Headless mode, disabling the Drupal Front-End and updating the admin experience.'
66
dependencies:
7-
- drupal:acquia_cms_headless
7+
- acquia_cms_headless:acquia_cms_headless
8+
- drupal:content_moderation
89
- drupal:path_alias

modules/acquia_cms_headless/modules/acquia_cms_headless_ui/acquia_cms_headless_ui.install

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function acquia_cms_headless_ui_install($is_syncing) {
1919
// Update configurations for the Headless UI.
2020
$headlessUi->updateHeadlessUiConfig(TRUE);
2121

22+
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load('headless');
23+
$role->grantPermission('view any unpublished content');
24+
$role->grantPermission('view latest version');
25+
$role->save();
26+
2227
// Clear caches to make sure updates are reflected.
2328
drupal_flush_all_caches();
2429
}

modules/acquia_cms_headless/modules/acquia_cms_headless_ui/acquia_cms_headless_ui.services.yml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ services:
33
class: 'Drupal\acquia_cms_headless_ui\EventSubscriber\ConfigSubscriber'
44
arguments:
55
- '@plugin.manager.menu.local_task'
6+
- '@config.factory'
67
tags:
78
- { name: event_subscriber }
89

modules/acquia_cms_headless/modules/acquia_cms_headless_ui/src/EventSubscriber/ConfigSubscriber.php

+40-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Drupal\Core\Config\ConfigCrudEvent;
66
use Drupal\Core\Config\ConfigEvents;
7+
use Drupal\Core\Config\ConfigFactoryInterface;
78
use Drupal\Core\Menu\LocalTaskManager;
89
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
910

@@ -24,14 +25,24 @@ final class ConfigSubscriber implements EventSubscriberInterface {
2425
*/
2526
private $localTaskManager;
2627

28+
/**
29+
* The config factory.
30+
*
31+
* @var \Drupal\Core\Config\ConfigFactoryInterface
32+
*/
33+
protected $configFactory;
34+
2735
/**
2836
* ConfigSubscriber constructor.
2937
*
3038
* @param \Drupal\Core\Menu\LocalTaskManager $local_task_manager
3139
* The local task plugin manager.
40+
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
41+
* The config factory.
3242
*/
33-
public function __construct(LocalTaskManager $local_task_manager) {
43+
public function __construct(LocalTaskManager $local_task_manager, ConfigFactoryInterface $config_factory) {
3444
$this->localTaskManager = $local_task_manager;
45+
$this->configFactory = $config_factory;
3546
}
3647

3748
/**
@@ -49,7 +60,7 @@ public function onSave(ConfigCrudEvent $event) {
4960
// Prevent system front page to get overridden
5061
// if pure headless mode is on.
5162
if ($name === 'system.site') {
52-
_acquia_cms_common_update_page_configurations('system.site', [
63+
$this->updatePageConfigurations('system.site', [
5364
'page.front' => '/frontpage',
5465
]);
5566
}
@@ -64,4 +75,31 @@ public static function getSubscribedEvents(): array {
6475
];
6576
}
6677

78+
/**
79+
* Helper function to update configuration for specified key.
80+
*
81+
* This is being used for updating page CT configurations.
82+
*
83+
* @param string $config_name
84+
* The configuration name which needs to be updated.
85+
* @param array $configurations
86+
* An array of drupal configurations.
87+
*/
88+
public function updatePageConfigurations(string $config_name, array $configurations) {
89+
$config = $this->configFactory->getEditable($config_name);
90+
$need_save = FALSE;
91+
if ($config) {
92+
foreach ($configurations as $key => $value) {
93+
if ($config->get($key) != $value) {
94+
$config->set($key, $value);
95+
$need_save = TRUE;
96+
}
97+
}
98+
// Only save if there's changes in value.
99+
if ($need_save) {
100+
$config->save();
101+
}
102+
}
103+
}
104+
67105
}

modules/acquia_cms_headless/src/Service/StarterkitNextjsService.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace Drupal\acquia_cms_headless\Service;
44

55
use Acquia\DrupalEnvironmentDetector\AcquiaDrupalEnvironmentDetector;
6-
use Drupal\acquia_cms_common\Traits\PasswordGeneratorTrait;
6+
use Drupal\acquia_cms_headless\Traits\PasswordGeneratorTrait;
77
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
88
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
99
use Drupal\Component\Utility\Crypt;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Drupal\acquia_cms_headless\Traits;
4+
5+
/**
6+
* Provides helpers to generate random password.
7+
*/
8+
trait PasswordGeneratorTrait {
9+
10+
/**
11+
* Generates the password based upon certain required conditions.
12+
*
13+
* @param int $length
14+
* Parameter that accepts the length of the password.
15+
*
16+
* @return string
17+
* Returns the shuffled string password.
18+
*/
19+
public static function generateRandomPassword(int $length = 12): string {
20+
// Define the character libraries.
21+
$sets = [];
22+
$sets[] = 'ABCDEFGHJKLMNPQRSTUVWXYZ';
23+
$sets[] = 'abcdefghjkmnpqrstuvwxyz';
24+
$sets[] = '0123456789';
25+
$sets[] = '~!@#$%^&*(){}[],./?';
26+
$password = '';
27+
28+
// Enforce the minimum length of the password to be 12.
29+
if ($length < 12) {
30+
$length = 12;
31+
}
32+
33+
// Append a character from each set - gets first 4 characters.
34+
foreach ($sets as $set) {
35+
$password .= $set[array_rand(str_split($set))];
36+
}
37+
38+
// Use all characters to fill up to $length.
39+
while (strlen($password) < $length) {
40+
// Get a random set.
41+
$randomSet = $sets[array_rand($sets)];
42+
// Add a random char from the random set.
43+
$password .= $randomSet[array_rand(str_split($randomSet))];
44+
}
45+
46+
// Shuffle the password string before returning.
47+
return str_shuffle($password);
48+
}
49+
50+
}

modules/acquia_cms_headless/tests/src/Functional/HeadlessDrushCommandsTest.php

-15
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,6 @@ class HeadlessDrushCommandsTest extends BrowserTestBase {
2929
*/
3030
protected $defaultTheme = 'stark';
3131

32-
/**
33-
* Disable strict config schema checks in this test.
34-
*
35-
* Scheduler has a config schema errors, and until it's fixed,
36-
* this test cannot pass unless we disable strict config schema checking
37-
* altogether. Since strict config schema isn't critically important in
38-
* testing this functionality, it's okay to disable it for now, but it should
39-
* be re-enabled (i.e., this property should be removed) as soon as possible.
40-
*
41-
* @var bool
42-
*/
43-
// @codingStandardsIgnoreStart
44-
protected $strictConfigSchema = FALSE;
45-
// @codingStandardsIgnoreEnd
46-
4732
/**
4833
* {@inheritdoc}
4934
*/

modules/acquia_cms_headless/tests/src/Functional/HeadlessFrontpageTest.php

+1-15
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,9 @@ class HeadlessFrontpageTest extends BrowserTestBase {
2222
*/
2323
protected static $modules = [
2424
'acquia_cms_headless_ui',
25+
'views',
2526
];
2627

27-
/**
28-
* Disable strict config schema checks in this test.
29-
*
30-
* Scheduler has a config schema errors, and until it's fixed,
31-
* this test cannot pass unless we disable strict config schema checking
32-
* altogether. Since strict config schema isn't critically important in
33-
* testing this functionality, it's okay to disable it for now, but it should
34-
* be re-enabled (i.e., this property should be removed) as soon as possible.
35-
*
36-
* @var bool
37-
*/
38-
// @codingStandardsIgnoreStart
39-
protected $strictConfigSchema = FALSE;
40-
// @codingStandardsIgnoreEnd
41-
4228
/**
4329
* Assert that frontpage for non logged-in user is login page.
4430
*/

0 commit comments

Comments
 (0)