mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-11 02:50:29 +00:00
✨ Enhance meetup association and permissions management
- 🔍 Added `resolveInScope` method to `ResolvesEntities` for scoped entity resolution with stricter control. - 👥 Introduced `AddMeetupToMineTool` MCP tool for adding external meetups to "My Meetups." - 🛠️ Updated `ListMyMeetupsTool` and `ShowMyMeetupTool` to include both created and joined meetups. - 📚 Updated `Meetup` model with `associatedWith` scope for querying user-related meetups. - ✅ Expanded feature tests for meetup membership, creator permissions, and scoped tool usage. - 🛡️ Unified access checks across Livewire and APIs to restrict editing meetup details to creators or super-admins. - 🔗 Registered `AddMeetupToMineTool` in `EinundzwanzigServer`.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -67,6 +68,17 @@ class Meetup extends Model implements HasMedia
|
||||
$model->created_by = auth()->id();
|
||||
}
|
||||
});
|
||||
|
||||
// Der Ersteller wird automatisch als Leiter in die meetup_user-Pivot eingetragen,
|
||||
// damit das Meetup einheitlich (MCP, REST-API, Livewire) in „Meine Meetups"
|
||||
// erscheint – egal über welchen Pfad es angelegt wurde.
|
||||
static::created(function (Meetup $model): void {
|
||||
if ($model->created_by !== null) {
|
||||
$model->users()->syncWithoutDetaching([
|
||||
$model->created_by => ['is_leader' => true],
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function getSlugOptions(): SlugOptions
|
||||
@@ -109,6 +121,18 @@ class Meetup extends Model implements HasMedia
|
||||
return $this->belongsToMany(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Meetups, die dem Nutzer zugeordnet sind: selbst erstellt (created_by) ODER
|
||||
* Mitglied über die meetup_user-Pivot. Entspricht „Meine Meetups" im Portal.
|
||||
*/
|
||||
public function scopeAssociatedWith(Builder $query, int $userId): void
|
||||
{
|
||||
$query->where(function (Builder $inner) use ($userId): void {
|
||||
$inner->where('created_by', $userId)
|
||||
->orWhereHas('users', fn (Builder $user) => $user->whereKey($userId));
|
||||
});
|
||||
}
|
||||
|
||||
public function city(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(City::class);
|
||||
|
||||
Reference in New Issue
Block a user