-
Notifications
You must be signed in to change notification settings - Fork 8
Implement Mason package integration with 17 bricks, authorization, and security fixes #423
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nielsdrost7
merged 17 commits into
feature/98-report-builder-only
from
copilot/sub-pr-349
Mar 30, 2026
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
7cab98f
Initial plan
Copilot 48fddd9
Add comprehensive Mason package integration plan
Copilot fd3f048
Update Mason refactor plan with status and next steps
Copilot c322383
Implement Mason package integration for ReportBuilder
Copilot 94bbec6
Wire Mason into ReportBuilder and add comprehensive tests
Copilot 1022f7e
Add 5 new Mason bricks and simplify storage (remove BlockDTO)
Copilot 57a9616
Refactor brick actions to use Mason's standard fillForm pattern
Copilot 43e6bb6
Add 6 new Mason bricks for enhanced reporting capabilities
Copilot ca19238
Update Modules/Core/Filament/Admin/Resources/ReportTemplates/Pages/Re…
nielsdrost7 440602d
Apply suggestions from code review
nielsdrost7 d1e271d
Add authorization and fix XSS vulnerabilities in Mason bricks
Copilot ac2f4f9
Update resources/lang/en/ip.php
nielsdrost7 a0261e5
Apply suggestions from code review
nielsdrost7 a9afb6b
Update Modules/Core/Services/MasonStorageAdapter.php
nielsdrost7 9b64f6f
Fix test assertions, Blade syntax, and unused imports per code review
Copilot 25c2e69
Add test for MasonTemplateStorage save/load flow
Copilot 7058324
Update Modules/Core/Tests/Feature/ReportBuilderMasonIntegrationTest.php
nielsdrost7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,177 @@ | ||
| <?php | ||
|
|
||
| namespace Modules\Core\Services; | ||
|
|
||
| use Modules\Core\DTOs\BlockDTO; | ||
| use Modules\Core\DTOs\GridPositionDTO; | ||
|
|
||
| /** | ||
| * Adapter to convert between Mason JSON format and InvoicePlane Block structure. | ||
| * | ||
| * Mason stores its editor state as JSON with a specific structure. This adapter | ||
| * translates that format to/from our BlockDTO structure for filesystem persistence. | ||
| */ | ||
| class MasonStorageAdapter | ||
| { | ||
| /** | ||
| * Convert Mason JSON to Block DTOs for filesystem storage. | ||
| * | ||
| * @param string $masonJson Mason editor JSON state | ||
| * @return array<string, BlockDTO> Array of BlockDTOs keyed by block ID | ||
| */ | ||
| public function masonToBlocks(string $masonJson): array | ||
| { | ||
| $masonData = json_decode($masonJson, true); | ||
| $blocks = []; | ||
|
|
||
| if (!isset($masonData['content']) || !is_array($masonData['content'])) { | ||
| return $blocks; | ||
| } | ||
|
|
||
| foreach ($masonData['content'] as $item) { | ||
| if (($item['type'] ?? null) === 'masonBrick') { | ||
| $attrs = $item['attrs'] ?? []; | ||
| $block = $this->createBlockFromMasonBrick($attrs); | ||
|
|
||
| if ($block) { | ||
| $blocks[$block->getId()] = $block; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return $blocks; | ||
| } | ||
|
|
||
| /** | ||
| * Convert Block DTOs to Mason JSON for editor. | ||
| * | ||
| * @param array<BlockDTO> $blockDTOs Array of BlockDTOs | ||
| * @return string Mason-compatible JSON | ||
| */ | ||
| public function blocksToMason(array $blockDTOs): string | ||
| { | ||
| $content = []; | ||
|
|
||
| foreach ($blockDTOs as $blockDTO) { | ||
| $content[] = [ | ||
| 'type' => 'masonBrick', | ||
| 'attrs' => [ | ||
| 'id' => $blockDTO->getId(), | ||
| 'config' => $blockDTO->getConfig() ?? [], | ||
| 'label' => $blockDTO->getLabel() ?? $this->getLabelForType($blockDTO->getType()), | ||
| 'preview' => base64_encode($this->generatePreview($blockDTO)), | ||
| ], | ||
| ]; | ||
| } | ||
|
|
||
| return json_encode([ | ||
| 'type' => 'doc', | ||
| 'content' => $content, | ||
| ], JSON_PRETTY_PRINT); | ||
| } | ||
|
|
||
| /** | ||
| * Create BlockDTO from Mason brick attributes. | ||
| * | ||
| * @param array $attrs Mason brick attributes | ||
| * @return BlockDTO|null | ||
| */ | ||
| protected function createBlockFromMasonBrick(array $attrs): ?BlockDTO | ||
| { | ||
| $id = $attrs['id'] ?? null; | ||
| $config = $attrs['config'] ?? []; | ||
| $label = $attrs['label'] ?? ''; | ||
|
|
||
| if (!$id) { | ||
| return null; | ||
| } | ||
|
|
||
| // Extract type from brick ID (e.g., "header_company_xyz123" -> "header_company") | ||
| $type = $this->extractTypeFromId($id); | ||
|
|
||
| // Create position DTO with defaults | ||
| $position = GridPositionDTO::create(0, 0, 12, 4); | ||
|
|
||
| $block = new BlockDTO(); | ||
|
nielsdrost7 marked this conversation as resolved.
|
||
| $block->setId($id) | ||
| ->setType($type) | ||
| ->setSlug(null) | ||
| ->setPosition($position) | ||
| ->setConfig($config) | ||
| ->setLabel($label) | ||
| ->setIsCloneable(false) | ||
|
nielsdrost7 marked this conversation as resolved.
|
||
| ->setDataSource($this->getDataSourceForType($type)) | ||
| ->setIsCloned(false) | ||
| ->setClonedFrom(null); | ||
|
|
||
| return $block; | ||
| } | ||
|
|
||
| /** | ||
| * Extract block type from Mason brick ID. | ||
| * | ||
| * @param string $brickId Mason brick ID (e.g., "header_company_abc123") | ||
| * @return string Block type (e.g., "header_company") | ||
| */ | ||
| protected function extractTypeFromId(string $brickId): string | ||
| { | ||
| // Remove trailing random suffix if present | ||
| return preg_replace('/_[a-z0-9]+$/i', '', $brickId); | ||
| } | ||
|
|
||
| /** | ||
| * Get human-readable label for a block type. | ||
| * | ||
| * @param string $type Block type | ||
| * @return string Label | ||
| */ | ||
| protected function getLabelForType(string $type): string | ||
| { | ||
| return match($type) { | ||
| 'header_company' => trans('ip.company_header'), | ||
| 'header_client' => trans('ip.client_header'), | ||
| 'header_invoice_meta' => trans('ip.invoice_metadata'), | ||
| 'detail_items' => trans('ip.line_items_table'), | ||
| 'footer_totals' => trans('ip.totals_section'), | ||
| 'footer_notes' => trans('ip.footer_notes'), | ||
| default => ucfirst(str_replace('_', ' ', $type)), | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Get data source for a block type. | ||
| * | ||
| * @param string $type Block type | ||
| * @return string Data source | ||
| */ | ||
| protected function getDataSourceForType(string $type): string | ||
| { | ||
| return match(true) { | ||
| str_starts_with($type, 'header_company') => 'company', | ||
| str_starts_with($type, 'header_client') => 'client', | ||
| str_starts_with($type, 'header_invoice') => 'invoice', | ||
| str_starts_with($type, 'detail_') => 'items', | ||
| str_starts_with($type, 'footer_') => 'invoice', | ||
| default => 'custom', | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Generate preview HTML for a block (placeholder implementation). | ||
| * | ||
| * @param BlockDTO $block Block DTO | ||
| * @return string Preview HTML | ||
| */ | ||
| protected function generatePreview(BlockDTO $block): string | ||
| { | ||
| // This would render the appropriate preview view for the block type | ||
| $type = $block->getType(); | ||
| $config = $block->getConfig() ?? []; | ||
|
|
||
| // Simplified preview generation | ||
| return sprintf( | ||
| '<div class="block-preview"><strong>%s</strong></div>', | ||
| htmlspecialchars($block->getLabel() ?? 'Block', ENT_QUOTES) | ||
| ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.