Users module: accounts, groups, permissions with needs, manager:create-user

This commit is contained in:
Matthijs Iriks committed 2026-12-04 01:25:29 +01:00
1 parent 08289db744
commit f86f5aea28
25 files changed
+744 -58

No files matched your search

+16 -10
View File
@@ -1,9 +1,9 @@
<?php
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Schema;
use IriksIT\Manager\Facades\Manager;
use IriksIT\Manager\Models\Group;
use IriksIT\Manager\Tests\Fixtures\User;
use IriksIT\Manager\Tests\TestCase;
uses(TestCase::class);
@@ -28,18 +28,24 @@ it('adds all of it for a module that is on', function () {
});
it('lets a super admin in and keeps others out without the permission', function () {
$admin = User::create(['name' => 'a', 'email' => '[email protected]', 'password' => 'x', 'manager_super_admin' => true]);
$other = User::create(['name' => 'b', 'email' => '[email protected]', 'password' => 'x']);
$this->actingAs($admin)->getJson('/manager/posts')->assertOk();
$this->actingAs($other)->getJson('/manager/posts')->assertForbidden();
$this->actingAs(makeUser(superAdmin: true))->getJson('/manager/posts')->assertOk();
$this->actingAs(makeUser())->getJson('/manager/posts')->assertForbidden();
});
it('gives a group member the permissions of the group', function () {
$user = User::create(['name' => 'c', 'email' => '[email protected]', 'password' => 'x']);
$group = Group::create(['name' => 'Editors', 'permissions' => ['posts.view']]);
$user->managerGroups()->attach($group);
it('gives a group member the permissions of the group, with what they need', function () {
$user = makeUser(['posts.publish']);
expect($user->managerPermissions())->toBe(['posts.view', 'posts.write', 'posts.publish']);
$this->actingAs($user)->getJson('/manager/posts')->assertOk();
$this->actingAs($user)->getJson('/manager/pages')->assertForbidden();
});
it('forgets what a switched-off module allowed', function () {
$group = Group::create(['name' => 'Old', 'permissions' => ['posts.view', 'reviews.manage']]);
expect($group->allowed())->toBe(['posts.view']);
});
it('does not answer for abilities of the host app', function () {
expect(Gate::forUser(makeUser(superAdmin: true))->allows('host.something'))->toBeFalse();
});