users worden nu beter geresolved
linter / quality (push) Failing after 1m5s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m7s
tests / ci (8.5) (push) Failing after 1m6s

This commit is contained in:
Daan Meijer
2026-07-06 16:51:34 +02:00
parent b2a7e2557e
commit 1be49133a0
14 changed files with 112 additions and 235 deletions
@@ -118,7 +118,7 @@ class DynamicInvitationController extends Controller
// Log to Dynamic chat activity log!
$dynamic->chat->messages()->create([
'user_id' => null,
'content' => "<user:{$request->user()->id}> joined the Dynamic as a ".strtoupper($invitation->role),
'content' => "<user:{$request->user()->uuid}> joined the Dynamic as a ".strtoupper($invitation->role),
'subject_id' => $request->user()->id,
'subject_type' => User::class,
]);
+26 -96
View File
@@ -19,30 +19,10 @@ class MutationController extends Controller
{
use AuthorizesRequests;
/**
* Display a listing of the resource.
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(StoreMutationRequest $request, Dynamic $dynamic, Ledger $ledger)
{
$this->authorize('create', [Mutation::class, $ledger]);
// If the user is an owner, default status to 'approved'. Otherwise default to 'pending'.
$status = $request->user()->can('update', $ledger) ? 'approved' : 'pending';
$mutation = DB::transaction(function () use ($request, $ledger, $status) {
@@ -70,7 +50,6 @@ class MutationController extends Controller
}
}
// Only increment score if the status is approved!
if ($status === 'approved') {
$ledger->increment('score', $request->validated('amount'));
}
@@ -78,48 +57,26 @@ class MutationController extends Controller
return $mutation;
});
// Notify all other participants
$recipients = $dynamic->participants()->where('users.id', '!=', $request->user()->id)->get();
$message = $status === 'approved'
? "{$request->user()->name} added a new entry: \"{$mutation->description}\"."
: "{$request->user()->name} suggested a new entry: \"{$mutation->description}\".";
Notification::send($recipients, new NewActivityNotification([
'content' => $message,
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
]));
if ($recipients->isNotEmpty()) {
Notification::send($recipients, new NewActivityNotification([
'content' => $message,
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
]));
}
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
}
/**
* Display the specified resource.
*/
public function show(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
$this->authorize('view', $mutation);
return $mutation;
}
/**
* Show the form for editing the specified resource.
*/
public function edit(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
$this->authorize('update', $mutation);
$request->validate([
'status' => ['required', 'string', 'in:approved,rejected'],
]);
$request->validate(['status' => ['required', 'string', 'in:approved,rejected']]);
$oldStatus = $mutation->status;
$newStatus = $request->input('status');
@@ -127,7 +84,6 @@ class MutationController extends Controller
DB::transaction(function () use ($mutation, $ledger, $oldStatus, $newStatus) {
$mutation->update(['status' => $newStatus]);
// Adjust the ledger score if status transitions to approved or from approved!
if ($oldStatus !== 'approved' && $newStatus === 'approved') {
$ledger->increment('score', $mutation->amount);
} elseif ($oldStatus === 'approved' && $newStatus !== 'approved') {
@@ -135,41 +91,17 @@ class MutationController extends Controller
}
});
// Log to Mutation and Dynamic chats
$user = $request->user();
$statusText = strtoupper($newStatus);
$mutationMsg = $mutation->chat->messages()->create([
'user_id' => null,
'content' => "Suggestion was {$statusText} by <user:{$user->id}>.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
broadcast(new MessageSent($mutationMsg));
if ($newStatus === 'approved') {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => null,
'content' => "<user:{$user->id}> APPROVED the suggestion \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
} else {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => null,
'content' => "<user:{$user->id}> REJECTED the suggestion \"{$mutation->description}\" on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
// Notify the suggester
$suggester = $mutation->user;
if ($suggester && $suggester->id !== $user->id) {
Notification::send($suggester, new NewActivityNotification([
'content' => "Your suggestion \"{$mutation->description}\" was {$statusText} by {$user->name}.",
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
]));
}
broadcast(new MessageSent($dynamicMsg));
// Notify all other participants
$recipients = $dynamic->participants()->where('users.id', '!=', $request->user()->id)->get();
Notification::send($recipients, new NewActivityNotification([
'content' => "{$user->name} {$statusText} the suggestion: \"{$mutation->description}\".",
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
]));
return redirect()->back();
}
@@ -178,23 +110,21 @@ class MutationController extends Controller
{
$this->authorize('void', $mutation);
$mutation->update(['status' => 'voided']);
DB::transaction(function() use ($mutation, $ledger) {
if ($mutation->status === 'approved') {
$ledger->decrement('score', $mutation->amount);
}
$mutation->update(['status' => 'voided']);
});
// Notify all other participants
$recipients = $dynamic->participants()->where('users.id', '!=', $request->user()->id)->get();
Notification::send($recipients, new NewActivityNotification([
'content' => "{$request->user()->name} voided an entry: \"{$mutation->description}\".",
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
]));
if ($recipients->isNotEmpty()) {
Notification::send($recipients, new NewActivityNotification([
'content' => "{$request->user()->name} voided an entry: \"{$mutation->description}\".",
'url' => route('dynamics.ledgers.show', [$dynamic, $ledger]),
]));
}
return redirect()->route('dynamics.ledgers.show', [$dynamic, $ledger]);
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
//
}
}