Files
projectsend/tests/Feature/Comments/ModerateCommentsPermissionTest.php
ignacionelson 623ad686da Open user management on the cloud edition
A managed installation's staff accounts were expected to arrive from
outside it, so users.manage was Community-only and /users, /roles and
their API twins answered 404 there. The platform side spent a long
document designing its way around that gate; opening it is cheaper than
routing around it, and more honest about where the knowledge sits.

The division that settles it is the one managed storage already uses. We
do not manage a tenant's files from outside — a bucket is provisioned, a
scoped credential handed over, and what goes in it is the tenant's
business. Seats are the same kind of thing. A platform knows how many
staff accounts it sold; it does not know whether Alice should be an
Account Manager, and it certainly does not know where her files go when
she leaves. Capacity is the platform's, occupancy is the tenant's, and
the cap belongs in an environment variable rather than in a closed
screen.

The capability stays in front of the routes rather than being deleted.
It is currently true in both editions, but it is the seam an edition
difference has to travel through, and removing it would mean inventing
one again later.

Seven test files asserted the old rule, which is the tests doing their
job. Most flip. Two needed a different example instead: EnsureCapability
and AbilityCapability were both using users.manage to stand for
"Community-only", so they now use storage.configure and manage_updates —
keys that still are.

Two rationales half-expired and say so rather than being quietly
rewritten. CommentAuthors gave two reasons for being a setting rather
than a permission; the first was that roles are uneditable on cloud,
which stopped being true here, and the second — that `Everyone` includes
anonymous visitors, who have no role to hold a key — was always the
stronger and is now the whole of it.

The seat cap this makes necessary is the next commit, not this one. On
its own this change lets a managed tenant create staff accounts without
limit, which is why the two belong in the same release.
2026-08-27 02:18:25 -03:00

53 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\User;
use App\Modules\Identity\Models\Role;
use App\Modules\Platform\Capabilities\Edition;
use Inertia\Testing\AssertableInertia;
/**
* The one permission this feature adds, from the screen that grants it to
* the page it gates.
*
* Forced to the community edition when the cloud edition gated the whole
* roles screen behind Capability::UsersManage, which would have made the
* roles half of this feature untestable on a cloud-configured install.
* That gate opened on both editions in 2.2.0, so the forcing is no longer
* load-bearing — it is kept because pinning the edition keeps this test
* about the permission rather than about whichever edition the suite
* happens to be configured for.
*/
beforeEach(function () {
config()->set('projectsend.edition', Edition::Community);
$this->admin = User::factory()->create();
});
test('the roles screen offers the moderation permission, under Files', function () {
$this->actingAs($this->admin)->get('/roles/create')
->assertOk()
->assertInertia(function (AssertableInertia $page) {
$catalog = collect($page->toArray()['props']['catalog']);
$files = $catalog->firstWhere('key', 'files');
expect(collect($files['permissions'])->pluck('key'))->toContain('moderate_comments');
});
});
test('granting it through the roles screen is what opens the queue', function () {
$role = Role::query()->create(['name' => 'Moderator', 'is_system' => false, 'is_administrator' => false]);
$staff = User::factory()->create(['role_id' => $role->id]);
$this->actingAs($staff)->get('/comments')->assertForbidden();
$this->actingAs($this->admin)->patch("/roles/{$role->id}", [
'name' => 'Moderator',
'permissions' => ['upload', 'moderate_comments'],
])->assertRedirect();
forgetRequestState();
$this->actingAs($staff)->get('/comments')->assertOk();
});