Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
4771512
fix(admin): a very wide, low image no longer breaks making its WebP copy
xiregroup Nov 17, 2026
8565105
refactor(admin): drop the catch around the WebP copy of an upload, no…
xiregroup Nov 17, 2026
e65e522
test(admin): a non-administrator account gets every button of a writa…
xiregroup Nov 17, 2026
ae2eafc
refactor(admin): measure page time from the request's start time only…
xiregroup Nov 17, 2026
5b34b2c
fix(admin): an SEO template naming a related record gives its name, n…
xiregroup Nov 17, 2026
9e8a536
test(admin): the image captcha with and without GD, the choice made b…
xiregroup Nov 17, 2026
dd60937
test(admin): a module with only the Administrable contract works in t…
xiregroup Nov 17, 2026
ff9de58
test(admin): pin the exact values of the Support services, rewrite th…
xiregroup Nov 17, 2026
dc24358
test(admin): permission sections, route matching and token modes in e…
xiregroup Nov 17, 2026
c063f41
test(admin): the sign-in throttle key and lock, the recaptcha widget,…
xiregroup Nov 17, 2026
1049e75
test(admin): pin which extension points are public and which are prot…
xiregroup Nov 17, 2026
d6edfe1
refactor(admin): let the File model's own deleting hook remove the fi…
xiregroup Nov 17, 2026
0f64526
refactor(admin): Themes::isChoice takes any value instead of guarding…
xiregroup Nov 17, 2026
19cd5d2
test(admin): pin Site folder, domain and url handling, drop equivalen…
xiregroup Nov 17, 2026
5f053d5
test(admin): pin Language code rules and rename guard
xiregroup Nov 17, 2026
c688aaa
test(admin): pin AdminUser site options and permissions, drop equival…
xiregroup Nov 17, 2026
73a3d7c
test(admin): pin the API documentation structure for every field edge
xiregroup Nov 17, 2026
21deb9a
test(admin): pin ModuleController settings, labels and validation
xiregroup Nov 17, 2026
cd9a527
test(admin): pin the shared Inertia props and asset version
xiregroup Nov 17, 2026
5bb6101
test(admin): pin what ApiGateway hands the router and restores afterw…
xiregroup Nov 17, 2026
2307aa3
test(admin): pin the MCP tool schemas, queries and bodies, drop equiv…
xiregroup Nov 17, 2026
fbcd4bc
test(admin): pin what EnterSiteFolder moves, notes and restores, drop…
xiregroup Nov 17, 2026
3d40113
test(admin): pin PageSpeedStats types, caching and the speed gadgets'…
xiregroup Nov 17, 2026
997aa5d
refactor(admin): PageSpeedStats takes the median as the model's cast …
xiregroup Nov 17, 2026
24f5f63
test(admin): pin the recent-items gadget for a model without timestam…
xiregroup Nov 17, 2026
6ac7480
test(admin): pin how soft relations are named and keyed, let the mode…
xiregroup Nov 17, 2026
a03c26e
test(admin): pin slug uniqueness, regeneration and redirects, drop eq…
xiregroup Nov 17, 2026
ea64266
test(admin): pin extension-point visibility inside the test classes t…
xiregroup Nov 17, 2026
8f3b174
refactor(admin): ImageCaptcha takes its random numbers from a closure…
xiregroup Nov 18, 2026
c3f8fa8
test(admin): pin the image captcha's widget, answers, expiry and the …
xiregroup Nov 18, 2026
2d2ab82
refactor(admin): drop guards and array wrappers in the module control…
xiregroup Nov 18, 2026
449ecf0
test(admin): pin the module controller condition by condition
xiregroup Nov 18, 2026
6044be8
refactor(admin): WebpCopy drops calls and checks that changed nothing
xiregroup Nov 18, 2026
9ab5ecc
test(admin): pin WebpCopy's limits, rounding, placement and transparency
xiregroup Nov 18, 2026
908f6b3
fix(admin): the API list no longer answers 500 to a search or a sort …
xiregroup Nov 18, 2026
9050d2b
refactor(admin): the API controller filters searchable columns withou…
xiregroup Nov 18, 2026
6c475b5
test(admin): pin the API's filters, sort columns, token abilities and…
xiregroup Nov 18, 2026
df29e90
fix(admin): the install and module commands print FAIL for a step tha…
xiregroup Nov 18, 2026
ba90b2f
refactor(admin): drop the redundant newLine, array_filter, early retu…
xiregroup Nov 18, 2026
dfc4e16
test(admin): pin the install, module and media commands' step output,…
xiregroup Nov 18, 2026
bafa3da
refactor(admin): make-module reads its stubs through the filesystem i…
xiregroup Nov 18, 2026
54ec256
test(admin): pin make-module's namespace, table, label escaping and s…
xiregroup Nov 18, 2026
b96cdfa
refactor(admin): make-module takes the label option as a string witho…
xiregroup Nov 18, 2026
c686983
refactor(admin): the file manager reads its query without casts and d…
xiregroup Nov 18, 2026
33e1ec7
test(admin): pin the roles section and the API documentation's notes,…
xiregroup Nov 18, 2026
d83a58d
refactor(admin): the site switch lets Rule::in take the ids as they c…
xiregroup Nov 18, 2026
7ebaf82
refactor(admin): hooks sort on every run and page timings read the cl…
xiregroup Nov 18, 2026
cf6c64b
fix(admin): saving the SEO tab twice no longer fails when the model h…
xiregroup Nov 18, 2026
27f1a4a
refactor(admin): the SEO excerpt looks for a sentence end without anc…
xiregroup Nov 18, 2026
de834b1
refactor(admin): module settings read their key and defaults without …
xiregroup Nov 18, 2026
e62746d
test(admin): pin the router's own permission markers, the API token l…
xiregroup Nov 18, 2026
b808086
refactor(admin): drop the dead middleware default, the null-safe rout…
xiregroup Nov 18, 2026
8d26ba4
test(admin): pin the one-click switches, required theme and language,…
xiregroup Nov 18, 2026
fba9c3e
refactor(admin): the file list's page count and the folder check's re…
xiregroup Nov 18, 2026
824ae49
test(admin): pin the API's excluded modules, the app routes' middlewa…
xiregroup Nov 18, 2026
56de730
test(admin): the gateway forgets what the request facade saw during t…
xiregroup Nov 18, 2026
cc8b9d6
test(admin): compare the role's stored list decoded and put the envir…
xiregroup Nov 18, 2026
6c98d0d
refactor(admin): the upload takes the stored mime type from the conte…
xiregroup Nov 18, 2026
f14be46
ci: raise the admin line coverage baseline to 100%
xiregroup Nov 18, 2026
dbae720
refactor(admin): module settings hand the field labels to the validat…
xiregroup Nov 18, 2026
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
2 changes: 1 addition & 1 deletion .ci/coverage/admin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
99.88% of lines, 7 not covered
100.00% of lines, 0 not covered
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ All notable changes are listed here. The format follows [Keep a Changelog](https
- The demo article's page is drawn by the theme; the app's own article controller, its view and Laravel's welcome page are gone.

### Fixed
- `atrium:install`, `atrium:module:install` and `atrium:module:remove` printed DONE next to a step that failed (publishing, migrating, linking, dropping tables); they print FAIL now.
- Saving the SEO tab of a record twice failed with a unique-constraint error in an application that maps the model to a morph alias (`Relation::morphMap()`); it updates the one SEO record now.
- The API list answered 500 to `?search[]=x` and `?sort[]=name` (a list instead of text); both are ignored now, like any other value the list cannot use.
- An SEO template naming a related record (`{parent}`) printed all of that record's columns as JSON into the page title or description; it gives the record's name now, and a list (`{files}`) leaves its placeholder.
- A very wide, very low image (a banner strip 4000 px wide and 1 px high) made `WebpCopy` stop with an error while scaling it down: its height rounded to zero. It keeps one pixel.
- The Bitrix migrator, found by tests of every branch: `atrium:bitrix:parity` now reports a widget of the wrong type (`TYPE_MISMATCH`; it never did) and no longer stops on a model with array fields or one that throws; `--iblock=2` and `--hlblock=1` on `generate:migrations`, `generate:models`, `migrate:data`, `verify` and `migrate` no longer end in a TypeError; a command run twice in one process (a queue worker, a test) no longer keeps the counts, connection and cache of the first run; `verify` says how many records it compared instead of the sample size and reports a section lost in the new database; `generate:migrations` finds a migration of the same table written by an earlier run under another number; a property or field with unreadable settings no longer stops the analysis; a column named after a Cyrillic property in capitals (`ЦЕНА`) is `tsena`, not `ts_e_n_a`; a multiple directory property is no longer in `$fillable` under its relation name; the `parent()` relation of a generated reference model returns `BelongsTo` instead of a class that does not exist; a file whose name starts with `total` is no longer left out of a plain FTP listing; the summary of `migrate` names the folders the files were really written to. Removed with no caller: `PropertyAnalyzer`, `IBlockElement`, `BitrixConnection::getIBlockTypes()`, `getIBlockEnumValues()`, `getElementSections()`, `getFiles()`, `getElementSeo()` and `getSectionSeo()` (the last two asked for columns Bitrix does not have), `IBlockAnalyzer::analyzeByCode()`, `getLinkedIBlockIds()`, `hasComplexRelations()`, `HighloadBlockAnalyzer::getLinkedHlblockIds()`, `findDirectoryHlblock()`, `hasComplexRelations()`, `FieldTypeMapper::getColumnClassName()` `BitrixListLayout::empty()`, `PropertyTypeMapper::shouldIndex()`, `NamingConvention::toMigrationFileName()` and `toMigrationClassName()`, `SectionMigrationGenerator::getFilename()` and the write/filename helpers of `MigrationGenerator`.
- Saving a record in the panel or the API wrote the record, its relations, its SEO and what `afterAdminSave()` writes one by one, so a failure halfway left half of it saved; deleting was the same. A save, a delete and `reorderFiles()` run in one transaction now, tried again up to three times after a deadlock, and `atrium.record.saved` / `atrium.record.deleted` are heard only after the commit, so their listeners never mail about or queue a record that was rolled back.
- `atrium:install` left an untracked Sanctum migration in every fresh clone: the skeleton carries it now, and on clones installed earlier it does nothing.
Expand Down
75 changes: 47 additions & 28 deletions packages/admin/src/Api/ApiDocumentation.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,32 +48,52 @@ public function modules(array $only = []): array
continue;
}

$fields = array_filter(
AdminController::fieldsOf($model),
static fn (Field $field): bool => $field->shouldShowOnCreate() || $field->shouldShowOnEdit()
);

$instance = new $model;
$translatable = Hook::apply(
'atrium.module.translatable',
method_exists($instance, 'getTranslatableAttributes') ? $instance->getTranslatableAttributes() : [],
$model,
);

$modules[$key] = [
'label' => $this->resources->label($key),
'fields' => array_values(array_map(
fn (Field $field): array => in_array($field->getName(), $translatable, true)
? $this->translatable($this->describe($field))
: $this->describe($field),
$fields
)),
];
$modules[$key] = $this->describeModule($key, $model);
}

return $modules;
}

/**
* One module of the API by its key; the key must be one of the API's.
*
* @return array{label:string,fields:array<int,array<string,mixed>>}
*/
public function module(string $key): array
{
return $this->describeModule($key, $this->resources->all()[$key]);
}

/**
* @param class-string $model
* @return array{label:string,fields:array<int,array<string,mixed>>}
*/
private function describeModule(string $key, string $model): array
{
$instance = new $model;
$translatable = Hook::apply(
'atrium.module.translatable',
method_exists($instance, 'getTranslatableAttributes') ? $instance->getTranslatableAttributes() : [],
$model,
);

$fields = [];

foreach (AdminController::fieldsOf($model) as $field) {
if (! $field->shouldShowOnCreate() && ! $field->shouldShowOnEdit()) {
continue;
}

$doc = $this->describe($field);
$fields[] = in_array($field->getName(), $translatable, true) ? $this->translatable($doc) : $doc;
}

return [
'label' => $this->resources->label($key),
'fields' => $fields,
];
}

/**
* A field as an API client sees it: what JSON to send and what it means.
*
Expand Down Expand Up @@ -119,7 +139,7 @@ private function describe(Field $field): array
'repeatable' => $this->set($doc, ['type' => 'array', 'items' => $this->repeatableItem($props['itemType'] ?? 'text')], $this->repeatableNote($props['itemType'] ?? 'text')),
'select' => $this->optionsSchema($doc, $props['options'] ?? [], false),
'multiSelect' => $this->optionsSchema($doc, $props['options'] ?? [], true),
'treeSelect' => $this->relationSchema($doc, $this->flattenTree($props['options'] ?? []), (bool) ($props['multiple'] ?? false), $props['modelClass'] ?? null),
'treeSelect' => $this->relationSchema($doc, $this->flattenTree($props['options'] ?? []), $props['multiple'], $props['modelClass'] ?? null),
'belongsTo' => $this->relationSchema($doc, $props['options'] ?? [], false, $props['modelClass'] ?? null),
'belongsToMany' => $this->relationSchema($doc, $props['options'] ?? [], true, $props['model'] ?? null),
default => $doc,
Expand Down Expand Up @@ -149,10 +169,9 @@ private function translatable(array $doc): array
$properties[$code] = $doc['schema'];
}

$doc['schema'] = ['oneOf' => [$doc['schema'], ['type' => 'object', 'properties' => $properties, 'additionalProperties' => false]]];
$doc['note'] = trim(($doc['note'] ?? '').' Translatable: a plain value sets the default language ('.$languages->default().'), an object {"'.implode('": …, "', $languages->codes()).'": …} sets several. Read back as that object.');
$schema = ['oneOf' => [$doc['schema'], ['type' => 'object', 'properties' => $properties, 'additionalProperties' => false]]];

return $doc;
return $this->set($doc, $schema, 'Translatable: a plain value sets the default language ('.$languages->default().'), an object {"'.implode('": …, "', $languages->codes()).'": …} sets several. Read back as that object.');
}

/**
Expand Down Expand Up @@ -245,14 +264,14 @@ private function relationSchema(array $doc, array $options, bool $multiple, ?str
* A section tree as a flat list with the full path in the label:
* "Europe / Day trips", otherwise sections with the same name are indistinguishable.
*
* @return array<int,array{value:mixed,label:string}>
* @return array<int,array{value:mixed,label:mixed}>
*/
private function flattenTree(array $nodes, string $prefix = ''): array
{
$flat = [];

foreach ($nodes as $node) {
$label = $prefix === '' ? (string) $node['label'] : $prefix.' / '.$node['label'];
$label = $prefix === '' ? $node['label'] : $prefix.' / '.$node['label'];
$flat[] = ['value' => $node['value'], 'label' => $label];

if (! empty($node['children'])) {
Expand Down Expand Up @@ -520,7 +539,7 @@ private function siteName(): string

private function typeName(array $schema): string
{
if (isset($schema['oneOf'][0])) {
if (isset($schema['oneOf'])) {
return $this->typeName($schema['oneOf'][0]).' per language';
}

Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/AtriumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private function registerRoutes(): void
if (is_file($custom)) {
$this->app['router']
->prefix(config('atrium.prefix', 'admin'))
->middleware([...config('atrium.middleware', ['web']), 'atrium.inertia', 'admin.auth', 'admin.can'])
->middleware([...config()->array('atrium.middleware'), 'atrium.inertia', 'admin.auth', 'admin.can'])
->group($custom);
}
}
Expand Down
7 changes: 3 additions & 4 deletions packages/admin/src/Auth/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,20 @@ public function sections(): array
}

foreach ($module->declaredPermissions as $name => $permission) {
[$section, $action] = explode('.', $name, 2);
[$section, $action] = explode('.', $name);
$sections[$section] ??= ['key' => $section, 'label' => $section === $key ? $module->label() : Str::headline($section), 'actions' => []];

if (! in_array($action, $sections[$section]['actions'], true)) {
$sections[$section]['actions'][] = $action;
}

if ($permission['label'] !== '') {
$sections[$section]['labels'][$action] = (string) __($permission['label']);
$line = __($permission['label']);
$sections[$section]['labels'][$action] = is_string($line) ? $line : $permission['label'];
}
}
}

$sections = array_values($sections);

usort($sections, static fn (array $a, array $b): int => strnatcasecmp($a['label'], $b['label']));

$sections[] = ['key' => 'api-tokens', 'label' => __('atrium::menu.api_tokens'), 'actions' => ['use']];
Expand Down
61 changes: 45 additions & 16 deletions packages/admin/src/Captcha/ImageCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@ final class ImageCaptcha implements CaptchaDriver

private const HEIGHT = 50;

public function __construct(private readonly Encrypter $encrypter, private readonly Cache $cache) {}
/** The largest of the built-in fonts of GD: 9 by 15 pixels a sign. */
private const FONT = 5;

/**
* @param bool|null $gd Whether the picture can be drawn; null asks PHP whether GD is there.
* @param (\Closure(int,int):int)|null $random Where the numbers of the sum and of the drawing come from; null is random_int().
*/
public function __construct(
private readonly Encrypter $encrypter,
private readonly Cache $cache,
private readonly ?bool $gd = null,
private readonly ?\Closure $random = null,
) {}

public function widget(): HtmlString
{
// A question is used up on the first answer: a kept page would give
// every visitor the same one.
app(RecordCache::class)->dontKeepPage();
[$a, $b] = [random_int(1, 9), random_int(1, 9)];
[$a, $b] = [$this->random(1, 9), $this->random(1, 9)];
$token = $this->encrypter->encrypt([
'q' => "$a + $b",
'a' => $a + $b,
Expand All @@ -49,7 +61,7 @@ public function widget(): HtmlString
]);

$id = 'atrium-captcha-'.Str::random(6);
$question = extension_loaded('gd')
$question = $this->draws()
? '<img src="'.e(route('atrium.captcha.image', ['t' => $token])).'" width="'.self::WIDTH.'" height="'.self::HEIGHT.'" alt="'.e(__('atrium::captcha.image')).'">'
: '<span>'.e("$a + $b = ?").'</span>';

Expand Down Expand Up @@ -87,7 +99,12 @@ public function image(mixed $token): ?string
{
$question = $this->question($token);

return $question === null || ! extension_loaded('gd') ? null : $this->draw($question['q'].' = ?');
return $question === null || ! $this->draws() ? null : $this->draw($question['q'].' = ?');
}

private function draws(): bool
{
return $this->gd ?? extension_loaded('gd');
}

/**
Expand Down Expand Up @@ -115,11 +132,11 @@ private function question(mixed $token): ?array
private function draw(string $text): string
{
$image = imagecreatetruecolor(self::WIDTH, self::HEIGHT);
imagefill($image, 0, 0, $this->color($image, 225, 250));
imagefilter($image, IMG_FILTER_COLORIZE, ...$this->rgb(225, 250));

for ($i = 0; $i < 6; $i++) {
imagesetthickness($image, random_int(1, 2));
imageline($image, random_int(0, self::WIDTH), random_int(0, self::HEIGHT), random_int(0, self::WIDTH), random_int(0, self::HEIGHT), $this->color($image, 120, 190));
imagesetthickness($image, $this->random(1, 2));
imageline($image, $this->random(0, self::WIDTH), $this->random(0, self::HEIGHT), $this->random(0, self::WIDTH), $this->random(0, self::HEIGHT), $this->color($image, 120, 190));
}

// Each sign drawn small with the built-in font, then enlarged, tilted
Expand All @@ -134,20 +151,19 @@ private function draw(string $text): string
}

$glyph = imagecreatetruecolor(9, 15);
imagefilter($glyph, IMG_FILTER_NEGATE);
$background = imagecolorallocate($glyph, 255, 255, 255);
imagefill($glyph, 0, 0, $background);
imagecolortransparent($glyph, $background);
imagestring($glyph, 5, 0, 0, $char, $this->color($glyph, 20, 90));
imagestring($glyph, self::FONT, 0, 0, $char, $this->color($glyph, 20, 90));

$glyph = imagerotate($glyph, random_int(-20, 20), $background);
$glyph = imagerotate($glyph, $this->random(-20, 20), $background);
imagecolortransparent($glyph, $background);
$size = random_int(24, 30);
imagecopyresized($image, $glyph, $x, random_int(2, self::HEIGHT - $size - 2), 0, 0, (int) ($size * .6), $size, imagesx($glyph), imagesy($glyph));
$x += (int) ($size * .6) + random_int(1, 4);
$size = $this->random(24, 30);
imagecopyresized($image, $glyph, $x, $this->random(2, self::HEIGHT - $size - 2), 0, 0, (int) ($size * .6), $size, imagesx($glyph), imagesy($glyph));
$x += (int) ($size * .6) + $this->random(1, 4);
}

for ($i = 0; $i < 250; $i++) {
imagesetpixel($image, random_int(0, self::WIDTH - 1), random_int(0, self::HEIGHT - 1), $this->color($image, 60, 200));
imagesetpixel($image, $this->random(0, self::WIDTH - 1), $this->random(0, self::HEIGHT - 1), $this->color($image, 60, 200));
}

ob_start();
Expand All @@ -158,7 +174,20 @@ private function draw(string $text): string

private function color(\GdImage $image, int $from, int $to): int
{
return (int) imagecolorallocate($image, random_int($from, $to), random_int($from, $to), random_int($from, $to));
return (int) imagecolorallocate($image, ...$this->rgb($from, $to));
}

/**
* @return array{int,int,int}
*/
private function rgb(int $from, int $to): array
{
return [$this->random($from, $to), $this->random($from, $to), $this->random($from, $to)];
}

private function random(int $min, int $max): int
{
return ($this->random ?? random_int(...))($min, $max);
}

private function ttl(): int
Expand Down
14 changes: 5 additions & 9 deletions packages/admin/src/Console/Commands/IndexMediaCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class IndexMediaCommand extends Command

public function handle(): int
{
$dryRun = (bool) $this->option('dry-run');
$dryRun = $this->option('dry-run');
$relative = trim((string) ($this->option('path') ?? ''), '/');

if ($relative === '') {
Expand All @@ -61,7 +61,7 @@ public function handle(): int
$added = 0;

foreach ($files as $file) {
$url = $prefix.'/'.ltrim($file['relative'], '/');
$url = $prefix.'/'.$file['relative'];

if (isset($known[$url])) {
continue;
Expand Down Expand Up @@ -101,14 +101,10 @@ public function handle(): int
*/
private function storageFiles(): array
{
$disk = (string) config('atrium.uploads.disk', 'public');
$directory = (string) config('atrium.uploads.directory', 'uploads');
$disk = config()->string('atrium.uploads.disk', 'public');
$directory = config()->string('atrium.uploads.directory', 'uploads');
$storage = Storage::disk($disk);

if (! $storage->exists($directory)) {
return [[], '/storage'];
}

$files = [];

foreach ($storage->allFiles($directory) as $path) {
Expand Down Expand Up @@ -156,7 +152,7 @@ private function publicFiles(string $relative): array

private function collection(): ?MediaCollection
{
$name = (string) ($this->option('collection') ?? '');
$name = $this->option('collection') ?? '';

return $name === '' ? null : MediaCollection::firstOrCreate(['name' => $name]);
}
Expand Down
Loading
Loading