Skip to content

Commit

Permalink
UHF-10191: Merge branch 'main' of https://github.com/City-of-Helsinki…
Browse files Browse the repository at this point in the history
  • Loading branch information
teroelonen committed Aug 30, 2024
2 parents c1a5f3f + ad9ef9d commit c263f04
Show file tree
Hide file tree
Showing 25 changed files with 520 additions and 37 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This repository holds configuration for the Hel.fi platform.
- [Update instructions (2.x to 3.x)](documentation/update.md)
- [Two-factor authentication/TFA/MFA](/modules/helfi_tfa/README.md)
- [JSON:API remote entities](/modules/helfi_etusivu_entities/README.md)
- [Users](/modules/helfi_users/README.md)

## Contact

Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
"drupal/ctools": "<3.11 || ^4.0.1",
"drupal/gin_toolbar": ">1.0.0-rc6",
"drupal/helfi_media_map": "*",
"drupal/default_content": ">2.0.0-alpha2",
"drush/drush": "<12"
},
"extra": {
Expand Down
13 changes: 13 additions & 0 deletions helfi_platform_config.install
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,16 @@ function helfi_platform_config_update_9311(): void {
}
}
}

/**
* UHF-9708: Enable helfi_users module.
*/
function helfi_platform_config_update_9312() : void {
helfi_platform_config_remove_permissions_from_all_roles([
'delete user accounts',
]);

if (!\Drupal::moduleHandler()->moduleExists('helfi_users')) {
\Drupal::service('module_installer')->install(['helfi_users']);
}
}
3 changes: 2 additions & 1 deletion helfi_platform_config.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ clear_localstorage:
- core/drupal

genesys_suunte:
version: 1.0.1
version: 1.0.2
header: true
js:
'https://apps.mypurecloud.ie/widgets/9.0/cxbus.min.js' : {
Expand All @@ -24,6 +24,7 @@ genesys_suunte:
}
assets/js/genesys_suunte.js: {
attributes: {
preprocess: false,
onload: "javascript:var checkExist = setInterval(function() {if(typeof CXBus != 'undefined') {clearInterval(checkExist);Drupal.behaviors.genesys_suunte.attach();console.log('suunte attaching');}}, 100);"
}
}
Expand Down
25 changes: 0 additions & 25 deletions helfi_platform_config.module
Original file line number Diff line number Diff line change
Expand Up @@ -496,31 +496,6 @@ function helfi_platform_config_config_ignore_settings_alter(array &$settings) {
}
}

/**
* Implements hook_user_cancel_methods_alter().
*/
function helfi_platform_config_user_cancel_methods_alter(array &$methods): void {
/** @var \Drupal\Core\Session\AccountInterface $account */
$account = \Drupal::currentUser();

// Only allow user to disable user accounts if the user doesn't have
// a permission to delete user accounts.
$white_listed_methods = [
'user_cancel_block',
'user_cancel_block_unpublish',
];

// Deny access to all non-whitelisted methods if user doesn't have
// the 'delete user accounts' permission.
if (!$account->hasPermission('delete user accounts')) {
foreach ($methods as $name => &$method) {
if (!in_array($name, $white_listed_methods)) {
$method['access'] = FALSE;
}
}
}
}

/**
* Implements hook_config_schema_info_alter().
*/
Expand Down
2 changes: 0 additions & 2 deletions helfi_platform_config.permissions.yml

This file was deleted.

12 changes: 12 additions & 0 deletions modules/hdbt_cookie_banner/assets/hdbt_cookie_banner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(function (Drupal, drupalSettings) {
Drupal.behaviors.hdbt_cookie_banner = {
attach: function (context, settings) {

// Todo initialize hdbt cookie banner.
fetch(drupalSettings.hdbt_cookie_banner.apiUrl)
.then(response => response.json())
.then(console.log)
.catch(console.error)
}
}
})(Drupal, drupalSettings);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
hdbt_cookie_banner.settings:
type: config_object
label: HDBT cookie banner
mapping:
site_settings:
type: string
label: Site settings
nullable: true
6 changes: 6 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: 'HDBT cookie banner'
type: module
description: 'Drupal module for hdbt cookie banner.'
core_version_requirement: ^10 || ^11
dependencies:
- helfi_api_base:helfi_api_base
3 changes: 3 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.libraries.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hdbt_cookie_banner:
js:
assets/hdbt_cookie_banner.js: {}
6 changes: 6 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
hdbt_cookie_banner.form:
title: 'HDBT Cookie Banner'
route_name: hdbt_cookie_banner.form
parent: system.admin_config_system
description: 'Configure HDBT Cookie Banner'
weight: -10
61 changes: 61 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/**
* @file
* Contains module hooks for hdbt cookie banner.
*/

declare(strict_types=1);

use Drupal\Core\Url;
use Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm;
use Drupal\helfi_api_base\Environment\EnvironmentResolverInterface;
use Drupal\helfi_api_base\Environment\Project;

/**
* Implements hook_config_ignore_settings_alter().
*/
function hdbt_cookie_banner_config_ignore_settings_alter(array &$settings): void {
$settings[] = HdbtCookieBannerForm::SETTINGS;
}

/**
* Implements hook_page_attachments().
*/
function hdbt_cookie_banner_page_attachments(array &$attachments) : void {
$attachments['#attached']['library'][] = 'hdbt_cookie_banner/hdbt_cookie_banner';
$attachments['#attached']['drupalSettings']['hdbt_cookie_banner'] = [
'apiUrl' => _hdbt_cookie_banner_get_api_url(),
];

$config = \Drupal::configFactory()->get(HdbtCookieBannerForm::SETTINGS);
$attachments['#cache']['tags'] = array_merge($attachments['#cache']['tags'] ?? [], $config->getCacheTags());
}

/**
* Gets HDBT cookie banner api url.
*/
function _hdbt_cookie_banner_get_api_url(): string {
$config = \Drupal::configFactory()->get(HdbtCookieBannerForm::SETTINGS);
$language = \Drupal::languageManager()->getDefaultLanguage();

// Default to etusivu api url.
if (empty($config->get('site_settings'))) {
/** @var \Drupal\helfi_api_base\Environment\EnvironmentResolverInterface $resolver */
$resolver = \Drupal::service(EnvironmentResolverInterface::class);
try {
$environment = $resolver
->getEnvironment(Project::ETUSIVU, $resolver->getActiveEnvironmentName());

return vsprintf("%s/api/cookie-banner", [
$environment->getUrl($language->getId()),
]);
}
catch (InvalidArgumentException) {
}
}

return Url::fromRoute('hdbt_cookie_banner.site_settings', options: [
'language' => $language,
])->toString();
}
2 changes: 2 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.permissions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
administer hdbt_cookie_banner:
title: 'Administer hdbt cookie banner'
14 changes: 14 additions & 0 deletions modules/hdbt_cookie_banner/hdbt_cookie_banner.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
hdbt_cookie_banner.form:
path: '/admin/structure/hdbt-cookie-banner'
defaults:
_form: '\Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm'
_title: 'Administer hdbt cookie banner'
requirements:
_permission: 'administer hdbt_cookie_banner'

hdbt_cookie_banner.site_settings:
path: '/api/cookie-banner'
defaults:
_controller: '\Drupal\hdbt_cookie_banner\Controller\HdbtCookieBannerController::siteSettings'
requirements:
_access: 'TRUE'
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace Drupal\hdbt_cookie_banner\Controller;

use Drupal\Component\Serialization\Json;
use Drupal\Core\Cache\CacheableJsonResponse;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm;

/**
* HDBT cookie banner controller.
*/
class HdbtCookieBannerController extends ControllerBase {

/**
* Constructs a new instance.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory.
*/
public function __construct(private readonly ConfigFactoryInterface $config) {
}

/**
* Returns site settings.
*/
public function siteSettings(): CacheableJsonResponse {
$config = $this->config->get(HdbtCookieBannerForm::SETTINGS);

$response = new CacheableJsonResponse(Json::decode($config->get('site_settings')));
$response->addCacheableDependency($config);
$response->setMaxAge(600);
$response->setPublic();

return $response;
}

}
80 changes: 80 additions & 0 deletions modules/hdbt_cookie_banner/src/Form/HdbtCookieBannerForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

declare(strict_types=1);

namespace Drupal\hdbt_cookie_banner\Form;

use Drupal\Core\Form\ConfigFormBase;
use Drupal\Core\Form\FormStateInterface;

/**
* HDBT cookie banner form.
*/
final class HdbtCookieBannerForm extends ConfigFormBase {

/**
* Config settings.
*/
public const SETTINGS = 'hdbt_cookie_banner.settings';

/**
* {@inheritdoc}
*/
public function getFormId(): string {
return 'hdbt_cookie_banner';
}

/**
* {@inheritdoc}
*/
protected function getEditableConfigNames(): array {
return [
self::SETTINGS,
];
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state): array {
$form['site_settings'] = [
'#type' => 'textarea',
'#title' => $this->t('Site settings', options: ['context' => 'hdbt cookie banner']),
'#config_target' => self::SETTINGS . ":site_settings",
];

return parent::buildForm($form, $form_state);
}

/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state): void {
parent::validateForm($form, $form_state);

$values = $form_state->getValues();

if (!$this->isValidJson($values['site_settings'])) {
$form_state->setErrorByName('site_settings',
$this->t('Site settings must be valid JSON', options: ['context' => 'hdbt cookie banner'])
);
}
}

/**
* Validates JSON string.
*
* @param string $value
* Input string.
*
* @return bool
* True if input is valid JSON.
*/
private function isValidJson(string $value): bool {
// @todo replace with json_validate in php >= 8.3.
// https://www.php.net/releases/8.3/en.php#json_validate.
json_decode($value);
return json_last_error() === JSON_ERROR_NONE;
}

}
9 changes: 5 additions & 4 deletions modules/helfi_ckeditor/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,9 @@ function helfi_paragraphs_news_list_preprocess_paragraph__news_list(&$variables)
->getUrl($langcode);

$instanceUrl = $instanceUrl . match ($langcode) {
'fi' => '/uutiset',
'sv' => '/nyheter',
default => '/news',
'fi' => '/uutiset/etsi-uutisia',
'sv' => '/nyheter/sok-efter-nyheter',
default => '/news/search-for-news',
};
$archiveUrl = Url::fromUri($instanceUrl, ['query' => $params]);

Expand Down
7 changes: 7 additions & 0 deletions modules/helfi_users/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# HELfi users

Fixes related to deleting or banning users.

Other user account related fixes and features:
- [Expired users](https://github.com/City-of-Helsinki/drupal-module-helfi-api-base/blob/main/documentation/user-expire.md)
- [Infofinland user sanitization](https://github.com/City-of-Helsinki/drupal-infofinland/blob/dev/public/modules/custom/infofinland_user_cancel/README.md)
7 changes: 7 additions & 0 deletions modules/helfi_users/helfi_users.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: HELfi users
description: 'Fixes related to deleting or canceling users.'
package: HELfi
type: module
core_version_requirement: ^10 || ^11
'interface translation project': helfi_users
'interface translation server pattern': modules/contrib/helfi_platform_config/modules/helfi_users/translations/%language.po
Loading

0 comments on commit c263f04

Please sign in to comment.