fix: Preset-Änderungen ohne unfiltered_html ablehnen, wenn Divi HTML/CSS anderer Presets entfernen würde

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-16 18:09:31 +02:00
co-authored by Claude Opus 5.5
parent 048cd9353d
commit 75714429be
10 changed files with 289 additions and 14 deletions
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace LIT\MCP\Integrations\Divi\Design;
use Closure;
use LIT\MCP\Abilities\Ability;
use LIT\MCP\Abilities\Annotations;
use LIT\MCP\Abilities\Errors;
@@ -20,11 +21,17 @@ final class DiviDesignRestoreAbility implements Ability
{
private const ID = '/^(colors|variables|presets|theme_options)-\d{8}T\d{6}Z-[0-9a-f]{6}$/D';
private const MARKUP = 'Der Snapshot oder der aktuelle Bestand enthält Presets mit HTML/CSS, das beim Speichern '
. 'ohne das Recht unfiltered_html verloren ginge; nichts wurde gespeichert.';
/** @param (Closure(): bool)|null $unfiltered Whether the user may save unfiltered HTML (DesignRights). */
public function __construct(
private DesignSystemWriter $writer,
private DesignChange $change,
private SnapshotStore $snapshots
private SnapshotStore $snapshots,
private ?Closure $unfiltered = null
) {
$this->unfiltered ??= DesignRights::unfilteredHtml();
}
public function name(): string
@@ -101,13 +108,23 @@ final class DiviDesignRestoreAbility implements Ability
);
}
$unfiltered = $this->unfiltered;
return $this->change->run(
$this->name(),
new PresetArea($this->writer),
$input,
static function (array $raw) use ($snapshot, $id): DesignPlan {
static function (array $raw) use ($snapshot, $id, $unfiltered): DesignPlan|WP_Error {
$before = PresetBook::fromDivi($raw);
$after = PresetBook::fromDivi($snapshot['data']);
$refusal = DesignRights::markup(
$unfiltered,
array_merge($before->markupOutside([]), $after->markupOutside([])),
self::MARKUP
);
if ($refusal !== null) {
return $refusal;
}
$diff = PresetDiff::between($before, $after);
return new DesignPlan(