mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-23 06:30:22 +00:00
✨ Implement leadership-based permissions for Meetup management
- 🔒 Restrict event creation, editing, and deletion to Meetup leaders (`is_leader`) and creators for consistency across APIs, frontend, and MCP. - ➕ Add new APIs for leader delegation: assign/remove Meetup leaders via `meetup_user.is_leader`. - 🛠️ Replace loose member checks with specific leadership checks in policies, controllers, and views. - 🧪 Add exhaustive tests to ensure only eligible leaders execute critical actions (e.g., event creation/edit, Meetup updates). - 🔄 Refactor pivot relationships and models (`leadByMe`, `isLeader`) for explicit leadership handling. - ✨ Introduce artisan command `meetups:promote-existing-leaders` to transition legacy data.
This commit is contained in:
@@ -6,8 +6,8 @@ use App\Models\MeetupEvent;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('creates a weekly series via the web editor using the shared action', function () {
|
||||
actingAsUser();
|
||||
$meetup = Meetup::factory()->create();
|
||||
// Termin-Verwaltung erfordert Leaderschaft; Ersteller ist per Hook Leader.
|
||||
$meetup = Meetup::factory()->create(['created_by' => actingAsUser()->id]);
|
||||
|
||||
Livewire::test('meetups.create-edit-events', ['meetup' => $meetup])
|
||||
->set('seriesMode', true)
|
||||
@@ -22,15 +22,15 @@ it('creates a weekly series via the web editor using the shared action', functio
|
||||
->assertHasNoErrors()
|
||||
->assertRedirect();
|
||||
|
||||
// The web editor parses the end date at midnight, so the occurrence on the end
|
||||
// date's evening falls outside the range: 2026-07-01, 07-08, 07-15, 07-22 = 4.
|
||||
// The shared action yields the identical result for the same inputs.
|
||||
expect(MeetupEvent::where('meetup_id', $meetup->id)->count())->toBe(4);
|
||||
// Das Enddatum aus dem Datums-Picker gilt inklusiv bis zum Tagesende
|
||||
// (endOfDay), daher ist das Vorkommen am Enddatum-Abend dabei:
|
||||
// 2026-07-01, 07-08, 07-15, 07-22, 07-29 = 5. Deterministisch, unabhängig
|
||||
// von der Laufzeit-Uhrzeit.
|
||||
expect(MeetupEvent::where('meetup_id', $meetup->id)->count())->toBe(5);
|
||||
});
|
||||
|
||||
it('previews the same dates it will create', function () {
|
||||
actingAsUser();
|
||||
$meetup = Meetup::factory()->create();
|
||||
$meetup = Meetup::factory()->create(['created_by' => actingAsUser()->id]);
|
||||
|
||||
Livewire::test('meetups.create-edit-events', ['meetup' => $meetup])
|
||||
->set('seriesMode', true)
|
||||
@@ -38,5 +38,5 @@ it('previews the same dates it will create', function () {
|
||||
->set('startTime', '18:00')
|
||||
->set('endDate', '2026-07-29')
|
||||
->set('recurrenceType', RecurrenceType::Weekly->value)
|
||||
->assertSet('previewDates', fn ($dates) => count($dates) === 4);
|
||||
->assertSet('previewDates', fn ($dates) => count($dates) === 5);
|
||||
});
|
||||
|
||||
@@ -63,23 +63,38 @@ it('allows update when name is unchanged (Rule::unique ignores own id)', functio
|
||||
->assertHasNoErrors();
|
||||
});
|
||||
|
||||
it('allows updateMeetup for a member of the meetup_user pivot who is not the creator', function () {
|
||||
it('allows updateMeetup for a delegated leader who is not the creator', function () {
|
||||
$leader = actingAsUser();
|
||||
$meetup = Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'name' => 'Original Name',
|
||||
'created_by' => User::factory()->create()->id,
|
||||
]);
|
||||
$meetup->users()->attach($leader, ['is_leader' => true]);
|
||||
|
||||
Livewire::test('meetups.edit', ['meetup' => $meetup])
|
||||
->set('name', 'Updated By Leader')
|
||||
->set('city_id', $this->city->id)
|
||||
->set('community', 'einundzwanzig')
|
||||
->call('updateMeetup')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($meetup->refresh()->name)->toBe('Updated By Leader');
|
||||
});
|
||||
|
||||
it('blocks updateMeetup for a plain member (is_leader = false) who is not the creator', function () {
|
||||
$member = actingAsUser();
|
||||
$meetup = Meetup::factory()->create([
|
||||
'city_id' => $this->city->id,
|
||||
'name' => 'Original Name',
|
||||
'created_by' => User::factory()->create()->id,
|
||||
]);
|
||||
$meetup->users()->attach($member);
|
||||
$meetup->users()->attach($member, ['is_leader' => false]);
|
||||
|
||||
Livewire::test('meetups.edit', ['meetup' => $meetup])
|
||||
->set('name', 'Updated By Member')
|
||||
->set('city_id', $this->city->id)
|
||||
->set('community', 'einundzwanzig')
|
||||
->call('updateMeetup')
|
||||
->assertHasNoErrors();
|
||||
->assertStatus(403);
|
||||
|
||||
expect($meetup->refresh()->name)->toBe('Updated By Member');
|
||||
expect($meetup->refresh()->name)->toBe('Original Name');
|
||||
});
|
||||
|
||||
it('blocks updateMeetup when the user is neither creator nor pivot member', function () {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Meetup;
|
||||
use App\Models\User;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('lets a leader open the event editor', function () {
|
||||
$meetup = Meetup::factory()->create(['created_by' => actingAsUser()->id]);
|
||||
|
||||
Livewire::test('meetups.create-edit-events', ['meetup' => $meetup])
|
||||
->assertOk();
|
||||
});
|
||||
|
||||
it('blocks a non-leader member from the event editor', function () {
|
||||
$member = actingAsUser();
|
||||
$meetup = Meetup::factory()->create(['created_by' => User::factory()->create()->id]);
|
||||
$meetup->addMember($member); // is_leader = false
|
||||
|
||||
Livewire::test('meetups.create-edit-events', ['meetup' => $meetup])
|
||||
->assertStatus(403);
|
||||
});
|
||||
|
||||
it('blocks a stranger from the event editor', function () {
|
||||
actingAsUser();
|
||||
$meetup = Meetup::factory()->create(['created_by' => User::factory()->create()->id]);
|
||||
|
||||
Livewire::test('meetups.create-edit-events', ['meetup' => $meetup])
|
||||
->assertStatus(403);
|
||||
});
|
||||
Reference in New Issue
Block a user