Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions app/src/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
use Cake\ORM\TableRegistry;
use Cake\Routing\Router;
use Cake\Utility\Hash;
use Symfony\Component\HtmlSanitizer\HtmlSanitizer;
use Symfony\Component\HtmlSanitizer\HtmlSanitizerConfig;

/**
* @property \App\Controller\Component\RegistryAuthComponent $RegistryAuth
Expand Down Expand Up @@ -692,8 +694,26 @@ protected function getTheme() {
// because we don't necessarily know what information a model-specific Theme
// is based on.

if(method_exists($this, "getSpecificTheme")) {
$theme = $this->getSpecificTheme();
if(method_exists($this, 'getSpecificTheme')) {
$specificTheme = $this->getSpecificTheme();

// Even if the method exists, be sure it doesn't return null.
if(isset($specificTheme)) {
$theme = $specificTheme;
}
}

if(isset($theme)) {
$htmlSanitizer = new HtmlSanitizer(
// Allow all elements from the W3C Sanitizer API. This is more permissive than "allowSafeElements()".
// See: https://github.com/symfony/symfony/blob/7.2/src/Symfony/Component/HtmlSanitizer/Reference/W3CReference.php
(new HtmlSanitizerConfig())->allowStaticElements()
);

$theme->set([
'sanitized_header' => $htmlSanitizer->sanitize($theme->header),
'sanitized_footer' => $htmlSanitizer->sanitize($theme->footer)
]);
}

$this->set('vv_theme', $theme);
Expand Down
27 changes: 27 additions & 0 deletions app/src/Lib/Traits/ValidationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,33 @@ public function registerClonableValidation(
return $validator;
}

/**
* Register validation rules for the provided field, as HTML.
*
* @since COmanage Registry v5.0.0
* @param Validator $validator Cake Validator
* @param TableSchemaInterface $schema Cake Schema
* @param string $field Field name
* @return Validator Cake Validator
*/

public function registerHtmlValidation(
Validator $validator,
TableSchemaInterface $schema,
string $field
): Validator {
$validator->add($field, [
'filter' => ['rule' => ['validateInput', ['type' => 'html']],
'provider' => 'table'],
'size' => ['rule' => ['validateMaxLength', ['column' => $schema->getColumn($field)]],
'provider' => 'table']
]);

$validator->allowEmptyString($field);

return $validator;
}

/**
* Register validation rules for the primary link key(s) associated with this table.
*
Expand Down
6 changes: 1 addition & 5 deletions app/src/Model/Table/MessageTemplatesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,7 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->allowEmptyString('body_text');

$validator->add('body_html', [
'filter' => ['rule' => ['validateInput',['type' => 'html']],
'provider' => 'table']
]);
$validator->allowEmptyString('body_html');
$this->registerHtmlValidation($validator, $schema, 'body_html');

$this->registerStringValidation($validator, $schema, 'cc', false);

Expand Down
6 changes: 1 addition & 5 deletions app/src/Model/Table/MostlyStaticPagesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,7 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->notEmptyString('context');

$validator->add('body', [
'filter' => ['rule' => ['validateInput', ['type' => 'html']],
'provider' => 'table']
]);
$validator->allowEmptyString('body');
$this->registerHtmlValidation($validator, $schema, 'body');

$validator->add('theme_id', [
'content' => ['rule' => 'isInteger']
Expand Down
6 changes: 4 additions & 2 deletions app/src/Model/Table/ThemesTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function initialize(array $config): void {

$this->setPrimaryLink('co_id');
$this->setRequiresCO(true);
// Return to the form on save to make theme development easier.
$this->setRedirectGoal('self');

$this->setPermissions([
// Actions that operate over an entity (ie: require an $id)
Expand Down Expand Up @@ -114,9 +116,9 @@ public function validationDefault(Validator $validator): Validator {

$this->registerStringValidation($validator, $schema, 'css', false);

$this->registerStringValidation($validator, $schema, 'header', false);
$this->registerHtmlValidation($validator, $schema, 'header');

$this->registerStringValidation($validator, $schema, 'footer', false);
$this->registerHtmlValidation($validator, $schema, 'footer');

return $validator;
}
Expand Down
2 changes: 1 addition & 1 deletion app/templates/MessageTemplates/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $fields = [
],
'body_html' => [
'afterField' =>
'<div class="alert alert-info small p-2 d-flex gap-1" role="alert">' .
'<div class="alert alert-info small p-2 d-flex gap-1 big-text-area-message" role="alert">' .
' <em class="material-symbols-outlined" aria-hidden="true">info</em>' .
' <span class="alert-text">' . __d('information','html.sanitization') . '</span>' .
'</div>',
Expand Down
2 changes: 1 addition & 1 deletion app/templates/MostlyStaticPages/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $fields = [
'body' => [
'class' => 'big-textarea',
'afterField' =>
'<div class="alert alert-info small p-2 d-flex gap-1" role="alert">' .
'<div class="alert alert-info small p-2 d-flex gap-1 big-text-area-message" role="alert">' .
' <em class="material-symbols-outlined" aria-hidden="true">info</em>' .
' <span class="alert-text">' . __d('information','html.sanitization') . '</span>' .
'</div>'
Expand Down
14 changes: 12 additions & 2 deletions app/templates/Themes/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,19 @@ $fields = [
'class' => 'big-textarea'
],
'header' => [
'class' => 'big-textarea'
'class' => 'big-textarea',
'afterField' =>
'<div class="alert alert-info small p-2 d-flex gap-1 big-text-area-message" role="alert">' .
' <em class="material-symbols-outlined" aria-hidden="true">info</em>' .
' <span class="alert-text">' . __d('information','html.sanitization') . '</span>' .
'</div>'
],
'footer' => [
'class' => 'big-textarea'
'class' => 'big-textarea',
'afterField' =>
'<div class="alert alert-info small p-2 d-flex gap-1 big-text-area-message" role="alert">' .
' <em class="material-symbols-outlined" aria-hidden="true">info</em>' .
' <span class="alert-text">' . __d('information','html.sanitization') . '</span>' .
'</div>'
]
];
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* COmanage Registry Footer
* COmanage Registry Logo (for bottom of content area)
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
Expand All @@ -26,7 +26,7 @@
*/
?>

<div class="footer">
<div id="comanage-logo">
<div class="poweredByComanage">
<span class="poweredText"><?= __('registry.meta.powered'); ?></span>
<?= $this->Html->image('COmanage-Logo-LG-onWhite.png', array('alt' => 'COmanage', 'height' => 30)); ?>
Expand Down
2 changes: 1 addition & 1 deletion app/templates/element/javascript.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
false
);
}
$('#navigation-drawer').toggleClass('closed');
$('#navigation-drawer').toggleClass('closed open');
});

$('#co-hamburger').click(function() {
Expand Down
19 changes: 18 additions & 1 deletion app/templates/element/menuPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,8 @@
<em class="material-symbols-outlined" aria-hidden="true">email</em>
<span class="menu-panel-link-text"><?= __d('controller', 'MessageTemplates', [99]) ?></span>
</a>
</li>
<li>
<?php
$menuUrl = $this->Url->build(
['plugin' => null,
Expand All @@ -620,9 +622,24 @@
<span class="menu-panel-link-text"><?= __d('controller', 'MostlyStaticPages', [99]) ?></span>
</a>
</li>
<li>
<?php
$menuUrl = $this->Url->build(
['plugin' => null,
'controller' => 'themes',
'action' => 'index',
'?' => [
'co_id' => $vv_cur_co->id
]]
);
?>
<a href="<?= $menuUrl ?>">
<em class="material-symbols" aria-hidden="true">colors</em>
<span class="menu-panel-link-text"><?= __d('controller', 'Themes', [99]) ?></span>
</a>
</li>
<?php /* More placeholders:
<li><a href="#"><em class="material-symbols" aria-hidden="true">room_service</em> Self Service Permissions</a></li>
<li><a href="#"><em class="material-symbols" aria-hidden="true">wallpaper</em> Themes</a></li>
* / ? >
</ul>
</li>
Expand Down
Loading