Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb1f4e1292 | ||
|
|
41d82a969a | ||
|
|
541d1ee690 | ||
|
|
a921f14d85 | ||
|
|
69ed8c742a | ||
|
|
258c25efe1 |
No files matched your search
@@ -1,13 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Installs Trivy at a fixed version, checked against a fixed checksum, so a changed download fails the
|
||||
# job instead of running. To update: take the version and the checksum of the Linux-64bit tarball from
|
||||
# https://github.com/aquasecurity/trivy/releases (the checksums file of that release).
|
||||
set -eu
|
||||
|
||||
VERSION=0.77.0
|
||||
SHA256=c9504e6ff8184b91e8e7266c84ad8538f76347f1e5488e07cb083855883cd9a6
|
||||
|
||||
curl -fsSL -o /tmp/trivy.tar.gz "https://github.com/aquasecurity/trivy/releases/download/v${VERSION}/trivy_${VERSION}_Linux-64bit.tar.gz"
|
||||
echo "${SHA256} /tmp/trivy.tar.gz" | sha256sum -c -
|
||||
tar -xzf /tmp/trivy.tar.gz -C /usr/local/bin trivy
|
||||
trivy --version
|
||||
@@ -151,15 +151,6 @@ jobs:
|
||||
- name: composer audit
|
||||
run: composer audit
|
||||
|
||||
- name: install trivy
|
||||
run: .gitea/scripts/install-trivy.sh
|
||||
|
||||
# Fails on HIGH and CRITICAL. vendor/ is left out of the secret and settings scan (it is other
|
||||
# people's code); the lock file made above is what the vulnerability scan reads.
|
||||
- name: trivy
|
||||
run: |
|
||||
trivy fs --no-progress --scanners vuln,secret,misconfig --severity HIGH,CRITICAL --exit-code 1 --skip-dirs vendor .
|
||||
|
||||
# Pull requests to a release branch merge by themselves when the check below is green.
|
||||
# Every job that checks out runs in an image with git: without git the checkout is the archive of the
|
||||
# repository, which leaves out what .gitattributes export-ignores (.gitea/ with these scripts).
|
||||
|
||||
@@ -40,9 +40,3 @@ jobs:
|
||||
- name: composer audit
|
||||
run: composer audit
|
||||
|
||||
- name: install trivy
|
||||
run: .gitea/scripts/install-trivy.sh
|
||||
|
||||
- name: trivy
|
||||
run: |
|
||||
trivy fs --no-progress --scanners vuln,secret,misconfig --severity HIGH,CRITICAL --exit-code 1 --skip-dirs vendor .
|
||||
@@ -20,5 +20,5 @@ between lil-koneko.com, CarsHub, iriks-it.nl and bouwbedrijf.iriks-it.nl, as one
|
||||
## Open decisions
|
||||
|
||||
1. Frontend: decided and built: the screens are in the package (`ui/`, built into `resources/dist`, committed; PR CI checks it is up to date). Still open: a theme editor in the manager, and a `host` mode that publishes the sources for a site to build itself.
|
||||
2. Moving the rest from bouwbedrijf.iriks-it.nl: real pages and reviews (now skeletons) and revisions. Users, media, posts, audit log and statistics are done, with their screens. Leave out what is site-specific (the IriksIT API disk, the owner's simple screens, client names): this repo is public.
|
||||
3. How the host's own `User` and a package `Group` relate when the host has its own roles.
|
||||
2. Moving the rest from bouwbedrijf.iriks-it.nl: reviews (still a read-only list). Users, media, posts, pages with fields, resources, revisions, audit log and statistics are done, with their screens. Leave out what is site-specific (the IriksIT API disk, client names): this repo is public. Still open: two-factor login, cropping pictures, automated tests of the screens in CI.
|
||||
3. Decided in 0.5.0: groups stay the default and the host's roles are added next to them (`manager.permissions`: `mode` groups, host or merge; `roles` or a `PermissionResolver`). A host that wants to replace the groups screens entirely is not planned.
|
||||
@@ -33,6 +33,10 @@ the section is the text of the release in Gitea.
|
||||
- Statistics: `<x-manager::pulse />` puts the counting script (`/pulse/pulse.js`, no cookies, honours Do Not Track) in the public pages of a site.
|
||||
- Login checks: `manager.login.checks` (contract `LoginCheck`, base class `BaseLoginCheck`) adds fields and checks before and after the password;
|
||||
Cloudflare Turnstile is built in (two env keys). No two-factor login in the package itself.
|
||||
- Roles of the host: `manager.permissions` (`mode` groups/host/merge, `roles` map or a `resolver` implementing `PermissionResolver`) lets a site
|
||||
with its own roles say what an account may do; groups stay the default.
|
||||
- CI: Trivy no longer runs in the jobs (the runner disk filled up with its database). `composer audit` stays in every pull request; Trivy scans production from the homelab (nightly, and after a deploy).
|
||||
- `manager:doctor` has a `names` check: it warns when the site uses a route name or an address of the manager and says to set `route_name` or `path`.
|
||||
|
||||
## v0.4.0 - 2026-12-04
|
||||
|
||||
|
||||
@@ -47,9 +47,11 @@ on the JSON routes. A browser that opens a manager address gets the page; anythi
|
||||
| `reviews` | Reviews | off |
|
||||
| `audit` | Audit log and address bans | off |
|
||||
| `statistics` | Visitor statistics | off |
|
||||
| `resources` | Lists defined in config (`manager.resources`) | on (nothing without definitions) |
|
||||
| `revisions` | History of posts and pages, with restore | on |
|
||||
|
||||
Switch a part in `config/manager.php` (`modules`) or with `MANAGER_PAGES`, `MANAGER_POSTS`,
|
||||
`MANAGER_REVIEWS`, `MANAGER_AUDIT`, `MANAGER_STATISTICS`. A module that is off has **no routes, no tables, no menu item and no permissions**:
|
||||
`MANAGER_REVIEWS`, `MANAGER_AUDIT`, `MANAGER_STATISTICS`, `MANAGER_REVISIONS`. A module that is off has **no routes, no tables, no menu item and no permissions**:
|
||||
its migrations are not loaded at all. A module that needs another one (`requires()`) fails at boot when
|
||||
that one is off.
|
||||
|
||||
@@ -112,6 +114,12 @@ php artisan manager:create-user # the only way to make a super admin
|
||||
- `groups.manage` is a gate for super admins only, not a permission of a group.
|
||||
- The package defines one gate per permission and **no `Gate::before`**: it never answers for the
|
||||
abilities of your own app.
|
||||
- **A site with roles of its own** (decided in 0.5.0: groups stay the default, the site's roles are added next to them).
|
||||
`manager.permissions.mode` is `groups` (default), `host` (the groups are ignored) or `merge` (both). The site says what a role may do
|
||||
with `roles` (`['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]`, read from the attribute `role_attribute`: a string, a
|
||||
list or a relation with a `name`) or with a `resolver` class that implements `IriksIT\Manager\Contracts\PermissionResolver`. Values
|
||||
that are no permission of an active module are ignored and what a permission needs is added. A super admin may always do everything.
|
||||
The group screens still work in `host` mode but give nothing.
|
||||
- The migration adds `is_super_admin` to your users table (the table of `manager.user_model`). It
|
||||
promotes nobody.
|
||||
|
||||
@@ -222,12 +230,14 @@ scheduled daily), so a code cannot be traced back afterwards. A browser that sen
|
||||
|
||||
## State of this version
|
||||
|
||||
Done: module registry and switches, permissions per module, users (accounts, groups, command), media (library and public file
|
||||
route), posts (with categories and tags), the audit log with bans, the statistics, the built-in screens for all of these (with a
|
||||
login and profile), themes, and the install and doctor commands for AI agents. `composer test` runs the tests.
|
||||
Done: module registry and switches, permissions per module, users (accounts, groups, command, roles of the host), media (library and
|
||||
public file route, focus point), posts (with categories and tags), pages with fields, lists defined in config, the history with restore,
|
||||
the audit log with bans, the statistics (with the counting script), the built-in screens for all of these (with a login, checks on the
|
||||
login, a profile and the simple view), an editor, themes, translations, a site's own bundle of screens, the import of existing data, and
|
||||
the install and doctor commands for AI agents. `composer test` runs the tests.
|
||||
|
||||
Pages and reviews are still skeletons (a read-only list), and revisions are not ported yet. The answers of every action are JSON
|
||||
in the shape the screens use, so an app can build its own screens with `MANAGER_UI=none`.
|
||||
Reviews are still a read-only list. The answers of every action are JSON in the shape the screens use, so an app can build its own screens
|
||||
with `MANAGER_UI=none`. Not in the package: two-factor login (the login checks are the place for it), cropping or rotating pictures, a theme editor.
|
||||
|
||||
## Development cycle
|
||||
|
||||
@@ -250,9 +260,9 @@ Nobody opens a pull request to `develop`, and `production` and the release branc
|
||||
|
||||
| When | What runs |
|
||||
|---|---|
|
||||
| Pull request to a release branch or to production | *flow* (right branches, version above the latest tag, changelog section, tests of these scripts), *ledger* (`TOKENS.md`), *test* (Pint, Pest with the newest and the oldest dependencies, `composer validate`), *security* (`composer audit`, Trivy on the dependencies, secrets and settings). The check `PR CI / pr-ci` is green when all are. |
|
||||
| Pull request to a release branch or to production | *flow* (right branches, version above the latest tag, changelog section, tests of these scripts), *ledger* (`TOKENS.md`), *test* (Pint, Pest with the newest and the oldest dependencies, `composer validate`), *security* (`composer audit`: the job fails on any advisory). The check `PR CI / pr-ci` is green when all are. |
|
||||
| Push to production | verify (Pest, audit), tag and release, Packagist, sync develop |
|
||||
| Every Monday | `composer audit` and Trivy on production |
|
||||
| Every Monday | `composer audit` on production |
|
||||
| Every Monday | *Dependency updates*: a direct dependency with a release outside its constraint (a new major) gets its constraint widened in a pull request `renovate/deps-DATE` to the open release branch; the npm packages of the screens (`ui/`) move to their newest release that has been public for 48 hours, with a rebuilt `resources/dist`, in `renovate/ui-deps-DATE`. PR CI tests them and they merge when green. Nothing happens while no release is open. The central Trivy (every night 03:00 UTC) and Renovate (04:00 UTC) of the homelab also pass over this repo, but read a `composer.lock` and a package has none, so they find little here. |
|
||||
| Every night | *Prune branches*: removes `feature/*` and `fix/*` branches whose last commit is over 30 days old and that have no open pull request (a branch of a pull request can be restored from it in Gitea) |
|
||||
|
||||
|
||||
@@ -42,3 +42,6 @@ Per stuk werk een rij; zie `dev/token-usage.py`.
|
||||
| 2026-12-04 | De editor: opmaakknoppen, foto's in de tekst, voorbeeld en een scherpstelpunt in de bibliotheek | - | claude-sonnet-5-5 | 15 | 18.397 | 30 | 28.742 | 3.931.230 | 0,07 |
|
||||
| 2026-12-04 | Het telscript en de Blade-component voor de publieke pagina's van de statistieken | - | claude-sonnet-5-5 | 8 | 9.037 | 16 | 15.948 | 2.254.948 | 0,04 |
|
||||
| 2026-12-04 | Loginhaken: eigen velden en controles, en Turnstile | - | claude-sonnet-5-5 | 4 | 9.009 | 8 | 9.515 | 1.178.544 | 0,02 |
|
||||
| 2026-12-04 | Rollen van de site naast de groepen van het pakket | - | claude-sonnet-5-5 | 3 | 5.308 | 6 | 8.235 | 921.246 | 0,01 |
|
||||
| 2026-12-04 | Controle op namen die de site al gebruikt, en de documenten van 0.5.0 rechtgezet | - | claude-sonnet-5-5 | 9 | 7.281 | 18 | 12.115 | 2.881.457 | 0,03 |
|
||||
| 2026-12-04 | Trivy uit de PR-jobs (schijf van de runners vol), opruimen en wekelijkse prune | - | claude-sonnet-5-5 | 20 | 9.723 | 44 | 94.863 | 1.460.150 | 0,15 |
|
||||
@@ -195,6 +195,15 @@ return [
|
||||
'turnstile' => ['site_key' => env('MANAGER_TURNSTILE_SITE_KEY'), 'secret' => env('MANAGER_TURNSTILE_SECRET')],
|
||||
],
|
||||
|
||||
/*
|
||||
| Who may do what. `groups` (default): the groups of the package. A site that has roles of its own can say it itself:
|
||||
| `host` takes the permissions only from the site, `merge` adds them to what the groups give. The site's side is a
|
||||
| `resolver` class (IriksIT\Manager\Contracts\PermissionResolver), or, simpler, `roles` per role name (`*` is
|
||||
| everything) read from the attribute `role_attribute` of the account (a string, a list or a relation with a `name`).
|
||||
| 'roles' => ['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]. A super admin may always do everything.
|
||||
*/
|
||||
'permissions' => ['mode' => env('MANAGER_PERMISSIONS', 'groups'), 'resolver' => null, 'roles' => [], 'role_attribute' => 'role'],
|
||||
|
||||
/*
|
||||
| The menu. `items` changes what a module gives, by the route name without the prefix:
|
||||
| 'posts.index' => ['order' => 10, 'section' => 'Content', 'icon' => 'file', 'simple' => true, 'hidden' => false].
|
||||
|
||||
@@ -17,6 +17,14 @@ order and never edit files inside `vendor/`.
|
||||
Repeat until `"ok": true`.
|
||||
|
||||
Facts that matter:
|
||||
- A site that already has `manager.*` route names, `manager_*` tables or its own posts and pages: `manager:doctor` has a `names` check that says
|
||||
so. Set `route_name`, `table_prefix` or `tables` in `config/manager.php` before the first `migrate`, then copy what exists with
|
||||
`php artisan manager:import posts|pages|reviews --table=<table> --map=<package_column>=<column> --dry-run` (the source is only read).
|
||||
- What the site's own content looks like is configuration, not code: `manager.pages.definitions` (texts with keys, read with `Page::contentFor('slug')`),
|
||||
`manager.resources` (lists such as services or testimonials, in a model of the site or the package's table) and `manager.menu` (order, sections,
|
||||
icons, own links). A screen that needs code is a JavaScript module in `manager.extensions`; it registers with `IriksManager.register`.
|
||||
- Who may do what: the groups of the package, or the roles of the site (`manager.permissions`); more on the login: `manager.login.checks`, Turnstile
|
||||
with two env keys. The public pages count visits with `<x-manager::pulse />` when `statistics` is on.
|
||||
- The screens are part of the package (`MANAGER_UI=package`, the default): open `/manager` in a browser. The app does not need a
|
||||
login of its own: when it has no route named `login`, the manager's own login at `/manager/login` is used. With
|
||||
`MANAGER_UI=none` there are only the JSON routes.
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
## iriks-it/laravel-manager
|
||||
|
||||
A modular backend (users, media, pages, posts, reviews, audit, statistics) installed as a package.
|
||||
A modular backend (users, media, pages, posts, reviews, audit, statistics, resources, revisions) installed as a package.
|
||||
|
||||
- To integrate it, follow `vendor/iriks-it/laravel-manager/resources/ai/INTEGRATION.md` step by step.
|
||||
- Set it up with `php artisan manager:install --modules=... --user-model=...`, then `config:clear`, `migrate`, `storage:link`; verify in a new process with `php artisan manager:doctor --json` (non-zero exit on failure, every problem has a `fix`).
|
||||
- The screens come with the package (`MANAGER_UI`), including a login when the app has none; themes: `php artisan manager:make-theme`, `MANAGER_THEME`.
|
||||
- The user model needs the `HasManagerAccess` trait; `is_super_admin` is never mass assignable. The first super admin comes from `php artisan manager:create-user`.
|
||||
- The site's content is configuration: `manager.pages.definitions`, `manager.resources`, `manager.menu`, `manager.permissions`, `manager.login.checks`; code only as a JavaScript module in `manager.extensions`. Existing data comes in with `php artisan manager:import`.
|
||||
- Switch parts with `MANAGER_<MODULE>=true|false`; never edit `vendor/`. Site-specific parts are your own `Module` class.
|
||||
@@ -6,12 +6,13 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use IriksIT\Manager\Models\Group;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
use IriksIT\Manager\Support\Names;
|
||||
use IriksIT\Manager\Support\Permissions\Sources;
|
||||
|
||||
/**
|
||||
* Put this on the User model of the host app (needs the Users module).
|
||||
*
|
||||
* A super admin may do everything of the manager. Everyone else may do what any of their
|
||||
* groups allows. `is_super_admin` is never fillable and no form sets it: only
|
||||
* groups allows, or (config `manager.permissions`) what the roles of the site say. `is_super_admin` is never fillable and no form sets it: only
|
||||
* `manager:create-user` makes one. Keep it out of `$fillable` in the host model.
|
||||
*/
|
||||
trait HasManagerAccess
|
||||
@@ -40,7 +41,9 @@ trait HasManagerAccess
|
||||
return $registry->permissionValues();
|
||||
}
|
||||
|
||||
return $registry->complete($this->managerGroups->flatMap(fn (Group $group) => $group->allowed())->all());
|
||||
$fromGroups = Sources::usesGroups() ? $this->managerGroups->flatMap(fn (Group $group) => $group->allowed())->all() : [];
|
||||
|
||||
return $registry->complete([...$fromGroups, ...Sources::fromHost($this)]);
|
||||
}
|
||||
|
||||
public function hasManagerPermission(string $permission): bool
|
||||
|
||||
@@ -31,6 +31,7 @@ class DoctorCommand extends Command
|
||||
$this->checkUserModel($modules);
|
||||
$this->checkTables($modules);
|
||||
$this->checkRoutes();
|
||||
$this->checkNames();
|
||||
$this->checkModules($modules);
|
||||
|
||||
$failed = collect($this->checks)->contains('status', 'fail');
|
||||
@@ -127,6 +128,38 @@ class DoctorCommand extends Command
|
||||
}
|
||||
}
|
||||
|
||||
/** Route names or addresses of the site that the package would share with its own. */
|
||||
private function checkNames(): void
|
||||
{
|
||||
$prefix = Names::routePrefix();
|
||||
$path = trim((string) config('manager.path'), '/');
|
||||
$names = [];
|
||||
$foreign = [];
|
||||
|
||||
foreach (Route::getRoutes()->getRoutes() as $route) {
|
||||
$name = (string) $route->getName();
|
||||
$mine = $route->isFallback || ($route->getActionName() === 'Closure' && str_starts_with($name, $prefix)) || str_starts_with(ltrim($route->getActionName(), '\\'), 'IriksIT\\Manager\\');
|
||||
|
||||
if ($prefix !== '' && str_starts_with($name, $prefix) && $name !== $prefix) {
|
||||
$names[$name] = ($names[$name] ?? 0) + 1;
|
||||
}
|
||||
|
||||
if (! $mine && ($route->uri() === $path || str_starts_with($route->uri(), $path.'/'))) {
|
||||
$foreign[] = $route->uri();
|
||||
}
|
||||
}
|
||||
|
||||
$twice = array_keys(array_filter($names, fn (int $count) => $count > 1));
|
||||
|
||||
if ($twice !== []) {
|
||||
$this->add('names', 'warn', 'Route names used twice: '.implode(', ', array_slice($twice, 0, 5)).'. The site and the manager share them, and one of the two stops working.', "Set 'route_name' in config/manager.php to something the site does not use, for example 'cms'.");
|
||||
} elseif ($foreign !== []) {
|
||||
$this->add('names', 'warn', 'The site has routes under the address of the manager: '.implode(', ', array_slice($foreign, 0, 5)).'.', "Move them, or set 'path' in config/manager.php (MANAGER_PATH) to another address.");
|
||||
} else {
|
||||
$this->add('names', 'ok', 'No route name or address is shared with the site.');
|
||||
}
|
||||
}
|
||||
|
||||
private function checkModules(ModuleRegistry $modules): void
|
||||
{
|
||||
$active = array_keys($modules->active());
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Contracts;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
|
||||
/**
|
||||
* Where a site that has roles of its own says what an account may do in the manager (config `manager.permissions.resolver`).
|
||||
* Values that are no permission of an active module are ignored, and what a permission needs is added.
|
||||
*/
|
||||
interface PermissionResolver
|
||||
{
|
||||
/** @return list<string> permission values such as `posts.write` */
|
||||
public function permissions(Authenticatable $user): array;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support\Permissions;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use Illuminate\Support\Collection;
|
||||
use IriksIT\Manager\Contracts\PermissionResolver;
|
||||
|
||||
/**
|
||||
* For a site whose accounts have a role (a `role` column, or a `roles` list or relation): config `manager.permissions.roles` says
|
||||
* what each role may do, e.g. `['editor' => ['posts.view', 'posts.write'], 'owner' => ['*']]` (`*` is everything). The attribute is
|
||||
* `manager.permissions.role_attribute`.
|
||||
*/
|
||||
final class RoleMap implements PermissionResolver
|
||||
{
|
||||
public function permissions(Authenticatable $user): array
|
||||
{
|
||||
$roles = $user->{(string) config('manager.permissions.role_attribute', 'role')} ?? [];
|
||||
$roles = $roles instanceof Collection ? $roles->all() : (array) $roles;
|
||||
$map = (array) config('manager.permissions.roles', []);
|
||||
$out = [];
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$name = is_object($role) ? (string) ($role->name ?? '') : (string) (is_scalar($role) ? $role : '');
|
||||
|
||||
foreach ((array) ($map[$name] ?? []) as $permission) {
|
||||
$out[] = (string) $permission;
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_unique($out));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Support\Permissions;
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use IriksIT\Manager\Contracts\PermissionResolver;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
|
||||
/**
|
||||
* What an account may do comes from the groups of the package (the default), from the roles of the site, or from both:
|
||||
* `manager.permissions.mode` is `groups`, `host` or `merge`. A site's side is its own `resolver` class, or the built-in `RoleMap`
|
||||
* when `roles` is filled. A super admin always may everything.
|
||||
*/
|
||||
final class Sources
|
||||
{
|
||||
public static function usesGroups(): bool
|
||||
{
|
||||
return self::mode() !== 'host';
|
||||
}
|
||||
|
||||
/** @return list<string> what the roles of the site allow (empty in `groups` mode) */
|
||||
public static function fromHost(Authenticatable $user): array
|
||||
{
|
||||
if (self::mode() === 'groups') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$class = config('manager.permissions.resolver');
|
||||
$resolver = is_string($class) && is_subclass_of($class, PermissionResolver::class) ? app($class) : (config('manager.permissions.roles') ? new RoleMap : null);
|
||||
|
||||
if ($resolver === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$known = app(ModuleRegistry::class)->permissionValues();
|
||||
$given = $resolver->permissions($user);
|
||||
|
||||
return in_array('*', $given, true) ? $known : array_values(array_filter($given, fn ($value) => is_string($value) && in_array($value, $known, true)));
|
||||
}
|
||||
|
||||
private static function mode(): string
|
||||
{
|
||||
return in_array(config('manager.permissions.mode'), ['groups', 'host', 'merge'], true) ? config('manager.permissions.mode') : 'groups';
|
||||
}
|
||||
}
|
||||
@@ -73,3 +73,24 @@ it('leaves the check to a new process after it changed the switches', function (
|
||||
|
||||
expect(Artisan::output())->toContain('manager:doctor')->not->toContain('[OK]');
|
||||
});
|
||||
|
||||
it('finds no shared names in a clean setup', function () {
|
||||
$check = collect(doctorReport()['checks'])->firstWhere('check', 'names');
|
||||
expect($check['message'])->toBe('No route name or address is shared with the site.');
|
||||
});
|
||||
|
||||
it('warns when the site uses a route name of the manager, and says what to set', function () {
|
||||
Route::get('/home', fn () => 'x')->name('manager.dashboard');
|
||||
|
||||
$check = collect(doctorReport()['checks'])->firstWhere('check', 'names');
|
||||
|
||||
expect($check['status'])->toBe('warn')->and($check['message'])->toContain('manager.dashboard')->and($check['fix'])->toContain('route_name');
|
||||
});
|
||||
|
||||
it('warns when the site has routes under the address of the manager', function () {
|
||||
Route::get('/manager/reports', fn () => 'x');
|
||||
|
||||
$check = collect(doctorReport()['checks'])->firstWhere('check', 'names');
|
||||
|
||||
expect($check['status'])->toBe('warn')->and($check['message'])->toContain('manager/reports');
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Contracts\Auth\Authenticatable;
|
||||
use IriksIT\Manager\Contracts\PermissionResolver;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
use IriksIT\Manager\Tests\Fixtures\User;
|
||||
use IriksIT\Manager\Tests\TestCase;
|
||||
|
||||
uses(TestCase::class);
|
||||
|
||||
class FromTheSite implements PermissionResolver
|
||||
{
|
||||
public function permissions(Authenticatable $user): array
|
||||
{
|
||||
return str_starts_with($user->email, 'editor') ? ['posts.write', 'posts.view', 'nonsense.thing'] : [];
|
||||
}
|
||||
}
|
||||
|
||||
function editor(string $role = 'editor', array $groups = []): User
|
||||
{
|
||||
$user = makeUser($groups);
|
||||
$user->setAttribute('role', $role);
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
it('uses the groups only, as before', function () {
|
||||
config(['manager.permissions.roles' => ['editor' => ['posts.view']]]);
|
||||
|
||||
expect(editor('editor', ['media.view'])->managerPermissions())->toBe(['media.view']);
|
||||
});
|
||||
|
||||
it('takes the permissions from the roles of the site in host mode, and not from the groups', function () {
|
||||
config(['manager.permissions' => ['mode' => 'host', 'roles' => ['editor' => ['posts.write', 'unknown.thing'], 'owner' => ['*']]] + config('manager.permissions')]);
|
||||
|
||||
expect(editor('editor', ['media.view'])->managerPermissions())->toBe(['posts.view', 'posts.write'])
|
||||
->and(editor('owner')->managerPermissions())->toBe(app(ModuleRegistry::class)->permissionValues())
|
||||
->and(editor('nobody')->managerPermissions())->toBe([]);
|
||||
|
||||
$this->actingAs(editor('editor'));
|
||||
$this->getJson('/manager/posts')->assertOk();
|
||||
$this->getJson('/manager/media/items')->assertForbidden();
|
||||
});
|
||||
|
||||
it('adds the roles to the groups in merge mode, and reads a list of roles', function () {
|
||||
config(['manager.permissions' => ['mode' => 'merge', 'roles' => ['editor' => ['posts.view'], 'writer' => ['posts.write']]] + config('manager.permissions')]);
|
||||
|
||||
$user = editor('editor', ['media.view']);
|
||||
$user->setAttribute('role', ['editor', 'writer']);
|
||||
|
||||
expect($user->managerPermissions())->toEqualCanonicalizing(['posts.view', 'posts.write', 'media.view']);
|
||||
});
|
||||
|
||||
it('asks a resolver of the site, which can only give permissions that exist', function () {
|
||||
config(['manager.permissions' => ['mode' => 'host', 'resolver' => FromTheSite::class] + config('manager.permissions')]);
|
||||
|
||||
$user = makeUser();
|
||||
$user->forceFill(['email' => '[email protected]'])->save();
|
||||
|
||||
expect($user->managerPermissions())->toBe(['posts.view', 'posts.write'])
|
||||
->and(makeUser()->managerPermissions())->toBe([]);
|
||||
});
|
||||
|
||||
it('keeps a super admin all-powerful in every mode', function () {
|
||||
config(['manager.permissions.mode' => 'host']);
|
||||
|
||||
expect(makeUser(superAdmin: true)->managerPermissions())->toContain('posts.view', 'media.view');
|
||||
});
|
||||
Reference in new issue
Block a user