17 Commits
Author SHA1 Message Date
Daan Meijer 64d771e34c added actions back to mutation single
linter / quality (push) Failing after 1m5s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m8s
2026-07-06 17:55:31 +02:00
Daan Meijer 2ab1acf040 mutations hebben single
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 50s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m6s
2026-07-06 17:47:14 +02:00
Daan Meijer 3d6a5362e6 notificationtest gerepareerd
linter / quality (push) Failing after 1m4s
tests / ci (8.3) (push) Failing after 51s
tests / ci (8.4) (push) Failing after 1m7s
tests / ci (8.5) (push) Failing after 1m6s
2026-07-06 17:31:47 +02:00
Daan Meijer dc94c2252c juiste view policy voor een mutation
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m8s
2026-07-06 17:11:43 +02:00
Daan Meijer 1be49133a0 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
2026-07-06 16:51:34 +02:00
Daan Meijer b2a7e2557e dashboard gereparerd
linter / quality (push) Failing after 1m5s
tests / ci (8.3) (push) Failing after 51s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m7s
2026-07-06 15:53:30 +02:00
Daan Meijer ccb3598da0 notificationtest in progress 2026-07-06 13:27:52 +02:00
Daan Meijer 371b75193a notificaties bij activiteit
linter / quality (push) Failing after 1m5s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m7s
2026-07-06 11:50:24 +02:00
Daan Meijer 57be9168e5 edit ledger mogelijk gemaakt
linter / quality (push) Failing after 1m7s
tests / ci (8.3) (push) Failing after 50s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m12s
2026-07-06 11:44:09 +02:00
Daan Meijer 800cb7a819 installed debugbar 2026-07-06 11:31:53 +02:00
Daan Meijer 89a48fae16 work in progress: predefinedmutations
linter / quality (push) Failing after 1m5s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m5s
2026-06-26 10:22:55 +02:00
Daan Meijer 806d17842f show the chat again
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m6s
tests / ci (8.5) (push) Failing after 1m4s
2026-06-24 09:59:39 +02:00
Daan Meijer d0b173fe76 chat messages showing again
linter / quality (push) Failing after 1m3s
tests / ci (8.3) (push) Failing after 48s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m5s
2026-06-24 08:50:05 +02:00
Daan Meijer 8d95e4ee53 resources er uit gesloopt
linter / quality (push) Failing after 1m4s
tests / ci (8.3) (push) Failing after 49s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m5s
2026-06-23 17:56:40 +02:00
Daan Meijer ae925c7173 fill id with uuid everywhere 2026-06-23 17:17:47 +02:00
Daan Meijer e7481eac95 fix voor wijziging aan migratie
linter / quality (push) Failing after 1m6s
tests / ci (8.3) (push) Failing after 50s
tests / ci (8.4) (push) Failing after 1m5s
tests / ci (8.5) (push) Failing after 1m6s
2026-06-23 17:07:24 +02:00
Daan Meijer 0c6bab4a04 polishing 2026-06-23 15:22:14 +02:00
58 changed files with 1331 additions and 598 deletions
+2 -1
View File
@@ -31,4 +31,5 @@ yarn-error.log
/public/workbox-*.js
/tests/Browser/console
/tests/Browser/screenshots
/tests/Browser/source
/tests/Browser/source
/storage/debugbar/
+9
View File
@@ -30,3 +30,12 @@ Welcome to the Ledgerrz codebase! This file defines the persistent guidelines, a
})
});
```
---
## 3. Advanced Browser Testing & Architectural Guidelines (Laravel Dusk)
* **Dusk Database Locks on SQLite:** Never use the `DatabaseTransactions` trait in Laravel Dusk tests if the project is backed by a SQLite database file. Since Dusk runs in concurrent, separate processes (the CLI runner and the web server), an active uncommitted database transaction in the CLI will hold a SQLite write lock. This causes the web server to fail with `SQLSTATE[HY000]: General error: 5 database is locked`. Instead, dynamically create and clean up models during test execution or use sequential DB seeds.
* **Inertia/Vue SPA Testing:** Browser tests targeting asynchronously rendered Single Page Applications must **always** use explicit `waitForText()` or `waitFor()` selectors before executing assertions. Direct assertions like `assertSee()` are immediate and will fail if the JavaScript has not finished compiling and mounting the DOM.
* **Synchronous Queue for WebSockets:** Running real-time WebSocket / Echo Dusk tests locally requires setting `QUEUE_CONNECTION=sync` and `BROADCAST_CONNECTION=reverb` in your `.env` file. This ensures broadcast jobs execute immediately on the web server rather than buffering in the database (which fails without a running background queue worker).
* **Automatic ID-to-UUID Serialization:** All models carrying a `uuid` column (such as `User`, `Dynamic`, `Ledger`, `Mutation`, and `PredefinedMutation`) must use the `App\Concerns\SerializesIdToUuid` trait. This guarantees that any raw model or relationship array/JSON conversion automatically replaces the integer `id` with the secure `uuid` under the `'id'` key.
* **UUID Controller Inputs:** When the frontend submits relationship parameters (such as `predefined_mutation_id` in requests), it only knows and passes the secure UUID. The receiving backend controller must explicitly resolve this UUID to its internal database integer ID before inserting the record (e.g. `PredefinedMutation::where('uuid', $uuid)->value('id')`), maintaining column type safety and foreign key constraints without exposing integer IDs to the client.
+2 -2
View File
@@ -50,7 +50,7 @@ During this session, we successfully built out and verified several core archite
* Created a dynamic user detail page (`dynamics.users.show`) scoped to each dynamic. It displays a participant's role, custom display name, fallback real name, and a clean chronological listing of their 10 most recent mutations (activities) in that dynamic.
8. **Polymorphic System Message placeholders & Dynamic Client-Side Linking**:
* Refactored system log activity messages to use native `<user:userId>` placeholders and associated them with polymorphic `subject_id` and `subject_type` objects.
* Refactored system log activity messages to use native `<user:userUuid>` placeholders and associated them with polymorphic `subject_id` and `subject_type` objects.
* On the client-side, the chat component parses these placeholders into rich, clickable links to User Profiles, and dynamically matches and wraps referenced ledger names into links pointing directly to the ledger show page.
* Added backend-side placeholder resolution inside `ActivityService` for the dashboard, ensuring unread system logs translate cleanly to real names across multiple dynamics.
@@ -64,4 +64,4 @@ During this session, we successfully built out and verified several core archite
11. **Standardized Policy-Driven UI Capabilities**:
* Eliminated unstandardized client-side role checks and boolean flags, replacing them with structured `can` capability objects returned directly from Laravel policies.
* Combined permission validation with state-based business constraints in `MutationPolicy` (e.g., suggestions can be approved/rejected only if `'pending'`; and voided only if not `'voided'`), securing both the frontend action buttons and backend controllers simultaneously.
* Achieved **65/65 passing Pest PHP tests with 333 assertions**.
* Achieved **65/65 passing Pest PHP tests with 333 assertions**.
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Concerns;
trait SerializesIdToUuid
{
/**
* Convert the model's attributes to an array.
* Overrides the default model toArray method to replace 'id' with 'uuid'.
*
* @return array<string, mixed>
*/
public function toArray(): array
{
$array = parent::toArray();
if (isset($this->uuid)) {
$array['id'] = $this->uuid;
}
return $array;
}
}
+2 -2
View File
@@ -11,10 +11,10 @@ class DashboardController extends Controller
public function index(Request $request, ActivityService $activityService)
{
$user = $request->user();
$unreadEntities = $activityService->getUnreadEntitiesGrouped($user);
$unreadDynamics = $activityService->getUnreadEntitiesGrouped($user);
return Inertia::render('Dashboard', [
'unreadEntities' => $unreadEntities,
'unreadDynamics' => $unreadDynamics,
]);
}
}
+7 -11
View File
@@ -3,10 +3,6 @@
namespace App\Http\Controllers;
use App\Http\Requests\UpdateDynamicRequest;
use App\Http\Resources\DynamicResource;
use App\Http\Resources\LedgerResource;
use App\Http\Resources\MessageResource;
use App\Http\Resources\UserResource;
use App\Models\Dynamic;
use App\Services\ActivityService;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
@@ -23,7 +19,7 @@ class DynamicController extends Controller
public function index(Request $request)
{
return Inertia::render('Dynamics/Index', [
'dynamics' => DynamicResource::collection($request->user()->dynamics()->get()),
'dynamics' => $request->user()->dynamics()->get(),
]);
}
@@ -59,10 +55,10 @@ class DynamicController extends Controller
$dynamic->load(['ledgers.media', 'participants', 'chat']);
return Inertia::render('Dynamics/Show', [
'dynamic' => new DynamicResource($dynamic),
'ledgers' => LedgerResource::collection($dynamic->ledgers),
'participants' => UserResource::collection($dynamic->participants),
'messages' => MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)),
'dynamic' => $dynamic,
'ledgers' => $dynamic->ledgers,
'participants' => $dynamic->participants,
'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
'can' => [
'update' => $request->user()->can('update', $dynamic),
],
@@ -73,7 +69,7 @@ class DynamicController extends Controller
{
$this->authorize('view', $dynamic);
return MessageResource::collection($dynamic->chat->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT));
return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
}
/**
@@ -84,7 +80,7 @@ class DynamicController extends Controller
$this->authorize('update', $dynamic);
return Inertia::render('Dynamics/Settings', [
'dynamic' => new DynamicResource($dynamic),
'dynamic' => $dynamic,
]);
}
@@ -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,
]);
+8 -12
View File
@@ -3,11 +3,6 @@
namespace App\Http\Controllers;
use App\Http\Requests\StoreLedgerRequest;
use App\Http\Resources\DynamicResource;
use App\Http\Resources\LedgerResource;
use App\Http\Resources\MessageResource;
use App\Http\Resources\MutationResource;
use App\Http\Resources\UserResource;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Services\ActivityService;
@@ -35,7 +30,7 @@ class LedgerController extends Controller
$this->authorize('update', $dynamic);
return Inertia::render('Ledgers/Create', [
'dynamic' => new DynamicResource($dynamic),
'dynamic' => $dynamic,
]);
}
@@ -74,6 +69,7 @@ class LedgerController extends Controller
$ledger->load([
'media',
'predefinedMutations',
'mutations' => function ($query) {
$query->latest();
},
@@ -83,9 +79,9 @@ class LedgerController extends Controller
]);
return Inertia::render('Ledgers/Show', [
'dynamic' => new DynamicResource($dynamic),
'ledger' => new LedgerResource($ledger),
'messages' => MessageResource::collection($dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT)),
'dynamic' => $dynamic,
'ledger' => $ledger,
'messages' => $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT),
'can' => [
'update' => $request->user()->can('update', $ledger),
'close' => $request->user()->can('close', $ledger),
@@ -97,7 +93,7 @@ class LedgerController extends Controller
{
$this->authorize('view', $ledger);
return MessageResource::collection($dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT));
return $dynamic->getOrCreateChat()->messages()->with(['user', 'media'])->latest()->paginate(\App\Models\Message::PAGINATION_COUNT);
}
/**
@@ -108,8 +104,8 @@ class LedgerController extends Controller
$this->authorize('update', $ledger);
return Inertia::render('Ledgers/Edit', [
'dynamic' => new DynamicResource($dynamic),
'ledger' => new LedgerResource($ledger),
'dynamic' => $dynamic,
'ledger' => $ledger,
]);
}
+58 -76
View File
@@ -6,47 +6,34 @@ use App\Events\MessageSent;
use App\Events\MutationCreated;
use App\Events\MutationUpdated;
use App\Http\Requests\StoreMutationRequest;
use App\Http\Resources\MutationResource;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\Mutation;
use App\Notifications\NewActivityNotification;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Notification;
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) {
$predefinedId = null;
if ($request->filled('predefined_mutation_id')) {
$predefinedId = \App\Models\PredefinedMutation::where('uuid', $request->input('predefined_mutation_id'))->value('id');
}
$mutation = $ledger->mutations()->create([
...$request->except(['media', 'type', 'status']),
...$request->except(['media', 'type', 'status', 'predefined_mutation_id']),
'predefined_mutation_id' => $predefinedId,
'user_id' => $request->user()->id,
'type' => $request->input('type', $request->input('amount') >= 0 ? 'addition' : 'subtraction'),
'status' => $status,
@@ -63,7 +50,6 @@ class MutationController extends Controller
}
}
// Only increment score if the status is approved!
if ($status === 'approved') {
$ledger->increment('score', $request->validated('amount'));
}
@@ -71,37 +57,46 @@ class MutationController extends Controller
return $mutation;
});
$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}\".";
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)
public function show(Request $request, Dynamic $dynamic, Ledger $ledger, Mutation $mutation)
{
$this->authorize('view', $mutation);
return new MutationResource($mutation);
$mutation->load('user', 'ledger', 'media', 'chat.messages.user');
$dynamic = $mutation->ledger->dynamic;
$dynamic->load('participants');
$user = $request->user();
return inertia('Mutations/Show', [
'mutation' => $mutation,
'dynamic' => $dynamic,
'can' => [
'update' => $user->can('update', $dynamic),
],
]);
}
/**
* 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');
@@ -109,7 +104,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') {
@@ -117,34 +111,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));
return redirect()->back();
}
@@ -153,16 +130,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']);
});
$recipients = $dynamic->participants()->where('users.id', '!=', $request->user()->id)->get();
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)
{
//
}
}
@@ -46,7 +46,7 @@ class ParticipantController extends Controller
return Inertia::render('Dynamics/Participants/Show', [
'dynamic' => $dynamic,
'participant' => [
'id' => $user->id,
'id' => $user->uuid,
'name' => $user->name,
'display_name' => $participant->pivot->display_name,
'role' => $participant->pivot->role,
@@ -29,6 +29,7 @@ class StoreMutationRequest extends FormRequest
'description' => ['required', 'string'],
'type' => ['nullable', 'string'],
'status' => ['nullable', 'string'],
'predefined_mutation_id' => ['nullable', 'exists:predefined_mutations,uuid'],
'media' => ['nullable', 'array'],
'media.*' => ['file', 'mimes:jpg,jpeg,png,gif,mp4,mov,avi,webm', 'max:20480'],
];
-25
View File
@@ -1,25 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class BaseResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
if (isset($data['id']) && isset($this->uuid)) {
$data['id'] = $this->uuid;
}
return $data;
}
}
-24
View File
@@ -1,24 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class ChatResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
if ($this->whenLoaded('messages')) {
$data['messages'] = MessageResource::collection($this->messages);
}
return $data;
}
}
-28
View File
@@ -1,28 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class DynamicResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$result = parent::toArray($request);
if ($this->ledgers) {
$result['ledgers'] = LedgerResource::collection($this->ledgers);
}
if ($this->whenLoaded('participants')) {
$result['participants'] = ParticipantResource::collection($this->participants);
}
if ($this->whenLoaded('chat')) {
$result['chat'] = new ChatResource($this->chat);
}
return $result;
}
}
-22
View File
@@ -1,22 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class LedgerResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
$data['mutations'] = MutationResource::collection($this->whenLoaded('mutations'));
return $data;
}
}
-18
View File
@@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class MessageResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
-25
View File
@@ -1,25 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class MutationResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
$data = parent::toArray($request);
$data['can'] = [
'update' => $request->user()?->can('update', $this->resource) ?? false,
'void' => $request->user()?->can('void', $this->resource) ?? false,
];
return $data;
}
}
@@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class ParticipantResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
@@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class PredefinedMutationResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
-18
View File
@@ -1,18 +0,0 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
class UserResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return parent::toArray($request);
}
}
+2 -1
View File
@@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str;
use App\Models\Chat;
use App\Concerns\SerializesIdToUuid;
class Dynamic extends Model
{
/** @use HasFactory<DynamicFactory> */
use HasFactory;
use HasFactory, SerializesIdToUuid;
protected $fillable = [
'name',
+2 -1
View File
@@ -9,11 +9,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class Ledger extends Model
{
/** @use HasFactory<LedgerFactory> */
use HasFactory;
use HasFactory, SerializesIdToUuid;
protected $fillable = [
'dynamic_id',
+37 -5
View File
@@ -10,11 +10,12 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphOne;
use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class Mutation extends Model
{
/** @use HasFactory<MutationFactory> */
use HasFactory;
use HasFactory, SerializesIdToUuid;
protected $fillable = [
'ledger_id',
@@ -69,8 +70,8 @@ class Mutation extends Model
$mutationMsg = $mutation->chat->messages()->create([
'user_id' => null,
'content' => $status === 'approved'
? "Entry was created by <user:{$user->id}>."
: "Suggestion was created by <user:{$user->id}>.",
? "Entry was created by <user:{$user->uuid}>."
: "Suggestion was created by <user:{$user->uuid}>.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
@@ -79,14 +80,14 @@ class Mutation extends Model
if ($status === 'approved') {
$dynamicMsg = $dynamic->chat->messages()->create([
'user_id' => null,
'content' => "<user:{$user->id}> added entry \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'content' => "<user:{$user->uuid}> added entry \"{$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}> suggested \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'content' => "<user:{$user->uuid}> suggested \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
@@ -99,11 +100,42 @@ class Mutation extends Model
static::updated(function (Mutation $mutation) {
if ($mutation->wasChanged('status')) {
$status = $mutation->getAttribute('status');
$user = request()->user();
$ledger = $mutation->ledger;
$mutationMsg = $mutation->chat->messages()->create([
'user_id' => null,
'content' => $status === 'approved'
? "<user:{$user->uuid}> APPROVED the suggestion \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger."
: "<user:{$user->uuid}> DENIED the suggestion \"{$mutation->description}\" for ".($mutation->amount >= 0 ? '+' : '')."{$mutation->amount} points on \"{$ledger->name}\" ledger.",
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
$dynamic = $ledger->dynamic;
$dynamic->chat->messages()->create([
'user_id' => null,
'content' => $mutationMsg->content,
'subject_id' => $mutation->id,
'subject_type' => Mutation::class,
]);
broadcast(new \App\Events\MutationUpdated($mutation));
}
});
}
protected $appends = ['can'];
public function getCanAttribute(): array
{
return [
'update' => auth()->user()?->can('update', $this) ?? false,
'void' => auth()->user()?->can('void', $this) ?? false,
];
}
public function getRouteKeyName()
{
return 'uuid';
+2 -1
View File
@@ -6,10 +6,11 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Str;
use App\Concerns\SerializesIdToUuid;
class PredefinedMutation extends Model
{
use HasFactory;
use HasFactory, SerializesIdToUuid;
protected $fillable = [
'ledger_id',
+2 -1
View File
@@ -15,6 +15,7 @@ use Laravel\Fortify\Contracts\PasskeyUser;
use Laravel\Fortify\PasskeyAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use NotificationChannels\WebPush\HasPushSubscriptions;
use App\Concerns\SerializesIdToUuid;
/**
* @property int $id
@@ -34,7 +35,7 @@ use NotificationChannels\WebPush\HasPushSubscriptions;
class User extends Authenticatable implements PasskeyUser
{
/** @use HasFactory<UserFactory> */
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
use HasFactory, HasPushSubscriptions, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable, SerializesIdToUuid;
public function dynamics()
{
+6 -35
View File
@@ -2,8 +2,6 @@
namespace App\Notifications;
use App\Models\Chat;
use App\Models\Message;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use NotificationChannels\WebPush\WebPushChannel;
@@ -13,60 +11,33 @@ class NewActivityNotification extends Notification
{
use Queueable;
public $activity;
public array $activity;
/**
* Create a new notification instance.
*/
public function __construct($activity)
public function __construct(array $activity)
{
$this->activity = $activity;
}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return [WebPushChannel::class];
return [WebPushChannel::class, 'database'];
}
/**
* Get the web push representation of the notification.
*/
public function toWebPush(object $notifiable): WebPushMessage
{
$result = (new WebPushMessage)
return (new WebPushMessage)
->title('New Activity')
->icon('/apple-touch-icon.png')
->body($this->activity['content'])
->action('View', 'view')
->data(['url' => $this->activity['url']]);
switch (get_class($this->activity)) {
case Message::class:
/** @var Chat $chat */
$chat = $this->activity->chat;
$result->data(['url' => $chat->subjectUrl]);
break;
}
return $result;
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
return [
//
'content' => $this->activity['content'],
'url' => $this->activity['url'],
];
}
}
+67
View File
@@ -0,0 +1,67 @@
<?php
namespace App\Policies;
use App\Models\Chat;
use App\Models\User;
use Illuminate\Auth\Access\Response;
class ChatPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return false;
}
/**
* Determine whether the user can view the model.
*/
public function view(User $user, Chat $chat): bool
{
$chatable = $chat->chatable;
return $user->can('view', $chatable);
}
/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return false;
}
/**
* Determine whether the user can update the model.
*/
public function update(User $user, Chat $chat): bool
{
return $this->view($user, $chat);
}
/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Chat $chat): bool
{
return false;
}
/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Chat $chat): bool
{
return false;
}
/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Chat $chat): bool
{
return false;
}
}
+8
View File
@@ -8,6 +8,14 @@ use App\Models\User;
class MutationPolicy
{
/**
* Determine whether the user can view the mutation.
*/
public function view(User $user, Mutation $mutation): bool
{
return $user->can('view', $mutation->ledger);
}
/**
* Determine whether the user can create mutations.
*/
+2 -2
View File
@@ -100,7 +100,7 @@ class ActivityService
$participants = $dynamic->participants()->withPivot('display_name')->get();
$participantsMap = $participants->reduce(function ($acc, $p) {
$acc[$p->id] = $p->pivot->display_name ?? $p->name;
$acc[$p->uuid] = $p->pivot->display_name ?? $p->name;
return $acc;
}, []);
@@ -115,7 +115,7 @@ class ActivityService
$messageData['url'] = $this->getUrlForMessage($message);
// Resolve <user:id> placeholders to actual names/display names
$messageData['content'] = preg_replace_callback('/<user:(\d+)>/', function ($matches) use ($participantsMap) {
$messageData['content'] = preg_replace_callback('/<user:([0-9a-f-]+)>/', function ($matches) use ($participantsMap) {
$userId = $matches[1];
return $participantsMap[$userId] ?? "User #{$userId}";
+1
View File
@@ -22,6 +22,7 @@
},
"require-dev": {
"fakerphp/faker": "^1.24",
"fruitcake/laravel-debugbar": "^4.4",
"larastan/larastan": "^3.9",
"laravel/boost": "^2.2",
"laravel/dusk": "^8.6",
Generated
+272 -1
View File
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "26618424deaf53a19e8fe992032eef9c",
"content-hash": "349232eb2e405a447b06a60c3c01fe4c",
"packages": [
{
"name": "bacon/bacon-qr-code",
@@ -9344,6 +9344,109 @@
],
"time": "2025-08-08T12:00:00+00:00"
},
{
"name": "fruitcake/laravel-debugbar",
"version": "v4.4.0",
"source": {
"type": "git",
"url": "https://github.com/fruitcake/laravel-debugbar.git",
"reference": "80ef956bda9e1a5824037d6f2cd06e73092e5634"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fruitcake/laravel-debugbar/zipball/80ef956bda9e1a5824037d6f2cd06e73092e5634",
"reference": "80ef956bda9e1a5824037d6f2cd06e73092e5634",
"shasum": ""
},
"require": {
"illuminate/routing": "^11|^12|^13.0",
"illuminate/session": "^11|^12|^13.0",
"illuminate/support": "^11|^12|^13.0",
"php": "^8.2",
"php-debugbar/php-debugbar": "^3.8.0",
"php-debugbar/symfony-bridge": "^1.1"
},
"replace": {
"barryvdh/laravel-debugbar": "self.version"
},
"require-dev": {
"larastan/larastan": "^3",
"laravel/ai": "^0.8",
"laravel/octane": "^2",
"laravel/pennant": "^1",
"laravel/pint": "^1",
"laravel/telescope": "^5.16",
"livewire/livewire": "^3.7|^4",
"mockery/mockery": "^1.3.3",
"orchestra/testbench-dusk": "^9|^10|^11",
"php-debugbar/twig-bridge": "^2.0",
"phpstan/phpstan-phpunit": "^2",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^11",
"shipmonk/phpstan-rules": "^4.3"
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"Debugbar": "Fruitcake\\LaravelDebugbar\\Facades\\Debugbar"
},
"providers": [
"Fruitcake\\LaravelDebugbar\\ServiceProvider"
]
},
"branch-alias": {
"dev-master": "4.2-dev"
}
},
"autoload": {
"files": [
"src/helpers.php"
],
"psr-4": {
"Fruitcake\\LaravelDebugbar\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fruitcake",
"homepage": "https://fruitcake.nl"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "PHP Debugbar integration for Laravel",
"keywords": [
"barryvdh",
"debug",
"debugbar",
"dev",
"laravel",
"profiler",
"webprofiler"
],
"support": {
"issues": "https://github.com/fruitcake/laravel-debugbar/issues",
"source": "https://github.com/fruitcake/laravel-debugbar/tree/v4.4.0"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2026-07-04T08:30:57+00:00"
},
{
"name": "hamcrest/hamcrest-php",
"version": "v2.1.1",
@@ -11041,6 +11144,174 @@
},
"time": "2022-02-21T01:04:05+00:00"
},
{
"name": "php-debugbar/php-debugbar",
"version": "v3.8.0",
"source": {
"type": "git",
"url": "https://github.com/php-debugbar/php-debugbar.git",
"reference": "18ced90d4b882ed449b2278fea8692f8f7d1c13c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-debugbar/php-debugbar/zipball/18ced90d4b882ed449b2278fea8692f8f7d1c13c",
"reference": "18ced90d4b882ed449b2278fea8692f8f7d1c13c",
"shasum": ""
},
"require": {
"php": "^8.2",
"psr/log": "^1|^2|^3",
"symfony/var-dumper": "^5.4|^6|^7|^8"
},
"replace": {
"maximebf/debugbar": "self.version"
},
"require-dev": {
"dbrekelmans/bdi": "^1.4",
"friendsofphp/php-cs-fixer": "^3.92",
"monolog/monolog": "^3.9",
"php-debugbar/doctrine-bridge": "^3@dev",
"php-debugbar/monolog-bridge": "^1@dev",
"php-debugbar/symfony-bridge": "^1@dev",
"php-debugbar/twig-bridge": "^2@dev",
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^10",
"predis/predis": "^3.3",
"shipmonk/phpstan-rules": "^4.3",
"symfony/browser-kit": "^6.4|7.0",
"symfony/dom-crawler": "^6.4|^7",
"symfony/event-dispatcher": "^5.4|^6.4|^7.3|^8.0",
"symfony/http-foundation": "^5.4|^6.4|^7.3|^8.0",
"symfony/mailer": "^5.4|^6.4|^7.3|^8.0",
"symfony/panther": "^1|^2.1",
"twig/twig": "^3.11.2"
},
"suggest": {
"php-debugbar/doctrine-bridge": "To integrate Doctrine with php-debugbar.",
"php-debugbar/monolog-bridge": "To integrate Monolog with php-debugbar.",
"php-debugbar/symfony-bridge": "To integrate Symfony with php-debugbar.",
"php-debugbar/twig-bridge": "To integrate Twig with php-debugbar."
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.8-dev"
}
},
"autoload": {
"psr-4": {
"DebugBar\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maxime Bouroumeau-Fuseau",
"email": "maxime.bouroumeau@gmail.com",
"homepage": "http://maximebf.com"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Debug bar in the browser for php application",
"homepage": "https://github.com/php-debugbar/php-debugbar",
"keywords": [
"debug",
"debug bar",
"debugbar",
"dev",
"profiler",
"toolbar"
],
"support": {
"issues": "https://github.com/php-debugbar/php-debugbar/issues",
"source": "https://github.com/php-debugbar/php-debugbar/tree/v3.8.0"
},
"funding": [
{
"url": "https://fruitcake.nl",
"type": "custom"
},
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
"time": "2026-07-02T12:38:20+00:00"
},
{
"name": "php-debugbar/symfony-bridge",
"version": "v1.1.0",
"source": {
"type": "git",
"url": "https://github.com/php-debugbar/symfony-bridge.git",
"reference": "e37d2debe5d316408b00d0ab2688d9c2cf59b5ad"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-debugbar/symfony-bridge/zipball/e37d2debe5d316408b00d0ab2688d9c2cf59b5ad",
"reference": "e37d2debe5d316408b00d0ab2688d9c2cf59b5ad",
"shasum": ""
},
"require": {
"php": "^8.2",
"php-debugbar/php-debugbar": "^3.1",
"symfony/http-foundation": "^5.4|^6.4|^7.3|^8.0"
},
"require-dev": {
"dbrekelmans/bdi": "^1.4",
"phpunit/phpunit": "^10",
"symfony/browser-kit": "^6|^7",
"symfony/dom-crawler": "^6|^7",
"symfony/mailer": "^5.4|^6.4|^7.3|^8.0",
"symfony/panther": "^1|^2.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"DebugBar\\Bridge\\Symfony\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Maxime Bouroumeau-Fuseau",
"email": "maxime.bouroumeau@gmail.com",
"homepage": "http://maximebf.com"
},
{
"name": "Barry vd. Heuvel",
"email": "barryvdh@gmail.com"
}
],
"description": "Symfony bridge for PHP Debugbar",
"homepage": "https://github.com/php-debugbar/php-debugbar",
"keywords": [
"debugbar",
"dev",
"symfony"
],
"support": {
"issues": "https://github.com/php-debugbar/symfony-bridge/issues",
"source": "https://github.com/php-debugbar/symfony-bridge/tree/v1.1.0"
},
"time": "2026-01-15T14:47:34+00:00"
},
{
"name": "php-webdriver/webdriver",
"version": "1.16.0",
@@ -13,10 +13,11 @@ return new class extends Migration
{
Schema::create('predefined_mutations', function (Blueprint $table) {
$table->id();
$table->foreignId('ledger_id')->constrained()->cascadeOnDelete();
$table->foreignId('dynamic_id')->constrained()->cascadeOnDelete();
$table->string('name');
$table->text('description')->nullable();
$table->integer('amount');
$table->string('type')->default('reward');
$table->timestamps();
});
}
@@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('predefined_mutations', function (Blueprint $table) {
// Drop old foreign key constraint first
$table->dropForeign(['dynamic_id']);
// Drop old columns
$table->dropColumn(['dynamic_id', 'type']);
// Add new ledger relationship (nullable to support pre-existing entries gracefully)
$table->foreignId('ledger_id')
->after('id')
->nullable()
->constrained()
->cascadeOnDelete();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('predefined_mutations', function (Blueprint $table) {
$table->dropConstrainedForeignId('ledger_id');
$table->foreignId('dynamic_id')->after('id')->constrained()->cascadeOnDelete();
$table->string('type')->default('reward');
});
}
};
@@ -0,0 +1,34 @@
<?php
use App\Models\Chat;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Chat::unguard();
\App\Models\Chat::all()->each(function (Chat $chat) {
$newType = match($chat->chatable_type) {
\App\Models\Mutation::class => 'mutation',
\App\Models\Ledger::class => 'ledger',
\App\Models\Dynamic::class => 'dynamic',
default => $chat->chatable_type,
};
$chat->update(['chatable_type' => $newType]);
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
//
}
};
@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('notifications', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type');
$table->morphs('notifiable');
$table->text('data');
$table->timestamp('read_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('notifications');
}
};
@@ -0,0 +1,42 @@
<?php
use App\Models\Message;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
\App\Models\Message::all()->each(function (Message $message) {
$msg = $message->content;
$msg = preg_replace_callback('/<user:([0-9]+)>/', function ($matches) {
$userId = $matches[1];
$user = \App\Models\User::find($userId);
if($user){
$userId = $user->uuid;
}
return "<user:$userId>";
}, $msg);
if($msg != $message->content) {
$message->update(['content' => $msg]);
}
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('uuid_base', function (Blueprint $table) {
//
});
}
};
+15
View File
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="Browser Test Suite">
<directory suffix="Test.php">./tests/Browser</directory>
</testsuite>
</testsuites>
</phpunit>
+1 -1
View File
@@ -23,7 +23,7 @@
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="BROADCAST_CONNECTION" value="null"/>
<env name="CACHE_STORE" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_CONNECTION" value="sqlite" />
<env name="DB_DATABASE" value=":memory:"/>
<env name="DB_URL" value=""/>
<env name="MAIL_MAILER" value="array"/>
+1 -1
View File
@@ -24,7 +24,7 @@
}
.c-chat__message {
@apply overflow-hidden p-4 shadow-sm sm:rounded-lg;
@apply p-4 shadow-sm sm:rounded-lg;
border: 1px solid var(--border);
&.c-chat__message--system {
+62 -4
View File
@@ -2,17 +2,46 @@
import { useForm } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
const props = defineProps<{
dynamicId: string;
ledgerId: string;
}>();
const props = withDefaults(
defineProps<{
dynamicId: string;
ledgerId: string;
predefinedMutations?: Array<{
id: string;
name: string;
description: string | null;
amount: number;
}>;
}>(),
{
predefinedMutations: () => [],
}
);
const form = useForm({
amount: 0,
description: '',
predefined_mutation_id: null as string | null,
media: [] as File[],
});
function selectPredefinedMutation(event: Event) {
const select = event.target as HTMLSelectElement;
const selectedId = select.value;
if (!selectedId) {
form.predefined_mutation_id = null;
form.amount = 0;
form.description = '';
return;
}
const mutation = props.predefinedMutations.find(m => m.id === selectedId);
if (mutation) {
form.predefined_mutation_id = mutation.id;
form.amount = mutation.amount;
form.description = mutation.description || mutation.name;
}
}
function handleMutationFileChange(event: Event) {
const files = (event.target as HTMLInputElement).files;
@@ -44,6 +73,28 @@ function submit() {
<div class="c-add-mutation-form">
<h4 class="c-add-mutation-form__title">Add Mutation</h4>
<form @submit.prevent="submit" class="c-add-mutation-form__form">
<!-- Predefined Templates Selection -->
<div v-if="predefinedMutations && predefinedMutations.length > 0" class="c-add-mutation-form__field">
<label for="predefined_mutation" class="c-add-mutation-form__label"
>Apply Predefined Template</label
>
<select
id="predefined_mutation"
class="c-add-mutation-form__select"
@change="selectPredefinedMutation"
>
<option value="">-- Choose a predefined template (optional) --</option>
<option
v-for="item in predefinedMutations"
:key="item.id"
:value="item.id"
>
{{ item.name }} ({{ item.amount >= 0 ? '+' : '' }}{{ item.amount }} points)
</option>
</select>
</div>
<div class="c-add-mutation-form__field">
<label for="amount" class="c-add-mutation-form__label"
>Amount</label
@@ -53,6 +104,7 @@ function submit() {
id="amount"
type="number"
class="c-add-mutation-form__input"
data-test="amount-input"
/>
<div
v-if="form.errors.amount"
@@ -71,6 +123,7 @@ function submit() {
id="description"
rows="4"
class="c-add-mutation-form__textarea"
data-test="description-input"
></textarea>
<div
v-if="form.errors.description"
@@ -120,6 +173,7 @@ function submit() {
type="submit"
:disabled="form.processing"
class="c-add-mutation-form__submit-btn"
data-test="add-mutation-button"
>
Add Mutation
</button>
@@ -151,6 +205,10 @@ function submit() {
@apply block text-sm font-medium text-gray-700 dark:text-gray-300;
}
.c-add-mutation-form__select {
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
}
.c-add-mutation-form__input {
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
}
+1 -1
View File
@@ -149,7 +149,7 @@ const participantsById = computed(() => {
{} as Record<
number,
{
id: number;
id: string;
name: string;
pivot?: { display_name: string | null } | null;
}
+7 -4
View File
@@ -19,10 +19,13 @@ const props = defineProps<{
}>();
const processedContent = computed(() => {
return props.message.content.replace(/<user:(\d+)>/g, (match, userId) => {
// This is a placeholder for a more robust user lookup
return `<a href="${route('users.show', userId)}" class="text-blue-500 hover:underline">@user${userId}</a>`;
});
return props.message.content.replace(
/<user:([0-9a-f-]+)>/g,
(match, userId) => {
// This is a placeholder for a more robust user lookup
return `<a href="${route('users.show', userId)}" class="text-blue-500 hover:underline">@user${userId}</a>`;
},
);
});
</script>
+23 -190
View File
@@ -1,64 +1,22 @@
<script setup lang="ts">
import { useForm } from '@inertiajs/vue3';
import { Link } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
import Chat from '@/components/Chat.vue';
const props = defineProps<{
dynamicId: string;
ledgerId: string;
ledgerAlignment?: string;
mutations: Array<{
id: number;
id: string; // Now a UUID
user_id: number;
user: { name: string };
amount: number;
description: string;
status: string;
created_at: string;
chat: any;
media?: Array<{ id: number; url: string; mime_type: string }>;
can: {
update: boolean;
void: boolean;
};
}>;
participants?: Array<{
id: number;
name: string;
pivot?: { role: string };
}>;
}>();
const emit = defineEmits<{
(e: 'open-lightbox', url: string, mimeType: string): void;
}>();
function updateStatus(mutationId: number, status: 'approved' | 'rejected') {
useForm({ status }).put(
route('dynamics.ledgers.mutations.update', {
dynamic: props.dynamicId,
ledger: props.ledgerId,
mutation: mutationId,
}),
);
}
function voidMutation(mutationId: number) {
useForm({}).put(
route('dynamics.ledgers.mutations.void', {
dynamic: props.dynamicId,
ledger: props.ledgerId,
mutation: mutationId,
}),
);
}
function isOwnerUser(userId: number): boolean {
const participant = props.participants?.find((p) => p.id === userId);
return participant?.pivot?.role === 'owner';
}
function getAmountClass(amount: number): string {
const alignment = props.ledgerAlignment || 'neutral';
@@ -87,18 +45,15 @@ function getAmountClass(amount: number): string {
<li
v-for="mutation in mutations"
:key="mutation.id"
class="c-mutation-list__item"
>
<div class="c-mutation-list__item-header">
<div>
<span class="c-mutation-list__item-author">
{{
isOwnerUser(mutation.user_id)
? 'Added by'
: 'Suggested by'
}}
{{ mutation.user.name }}
</span>
<Link
:href="route('dynamics.ledgers.mutations.show', { dynamic: dynamicId, ledger: ledgerId, mutation: mutation.id })"
class="c-mutation-list__item-link"
>
<div class="c-mutation-list__item-content">
<p class="c-mutation-list__item-desc">
{{ mutation.description }}
</p>
<div class="c-mutation-list__item-meta">
<span
:class="getAmountClass(mutation.amount)"
@@ -107,10 +62,8 @@ function getAmountClass(amount: number): string {
{{ mutation.amount > 0 ? '+' : ''
}}{{ mutation.amount }}
</span>
<!-- Only show status badge if mutation was NOT auto-approved by an owner -->
<span
v-if="!isOwnerUser(mutation.user_id)"
:class="{
<span
:class="{
'c-mutation-list__item-status--pending':
mutation.status === 'pending',
'c-mutation-list__item-status--approved':
@@ -118,85 +71,13 @@ function getAmountClass(amount: number): string {
'c-mutation-list__item-status--rejected':
mutation.status === 'rejected',
}"
class="c-mutation-list__item-status"
>
class="c-mutation-list__item-status"
>
{{ mutation.status }}
</span>
</div>
</div>
<div class="c-mutation-list__item-time">
{{ new Date(mutation.created_at).toLocaleString() }}
</div>
</div>
<p class="c-mutation-list__item-desc">
{{ mutation.description }}
</p>
<!-- Attached Mutation Proof Media -->
<div
v-if="mutation.media && mutation.media.length > 0"
class="c-mutation-list__media-list"
>
<div
v-for="item in mutation.media"
:key="item.id"
class="c-mutation-list__media-item"
>
<img
v-if="item.mime_type.startsWith('image/')"
:src="item.url"
class="c-mutation-list__media-img"
@click="
emit('open-lightbox', item.url, item.mime_type)
"
/>
<div
v-else-if="item.mime_type.startsWith('video/')"
class="c-mutation-list__media-video-wrapper"
@click="
emit('open-lightbox', item.url, item.mime_type)
"
>
<video
:src="item.url"
class="c-mutation-list__media-video"
></video>
<div class="c-mutation-list__media-video-overlay">
</div>
</div>
</div>
</div>
<!-- Owner Approve/Reject Actions -->
<div
v-if="mutation.can?.update || mutation.can?.void"
class="c-mutation-list__actions"
>
<button
v-if="mutation.can?.update"
@click="updateStatus(mutation.id, 'approved')"
class="c-mutation-list__approve-btn"
>
Approve
</button>
<button
v-if="mutation.can?.update"
@click="updateStatus(mutation.id, 'rejected')"
class="c-mutation-list__reject-btn"
>
Reject
</button>
<button
v-if="mutation.can?.void"
@click="voidMutation(mutation.id)"
class="c-mutation-list__void-btn"
>
Void
</button>
</div>
<Chat :chat="mutation.chat" :dynamic-id="dynamicId" :participants="participants" />
</Link>
</li>
</ul>
<div v-if="mutations.length === 0" class="c-mutation-list__empty">
@@ -217,23 +98,23 @@ function getAmountClass(amount: number): string {
}
.c-mutation-list__list {
@apply mt-4 space-y-4;
@apply mt-4 space-y-2;
}
.c-mutation-list__item {
@apply overflow-hidden bg-white p-4 shadow-sm sm:rounded-lg dark:bg-gray-800;
.c-mutation-list__item-link {
@apply block overflow-hidden bg-white p-4 shadow-sm sm:rounded-lg dark:bg-gray-800 transition-all duration-200 hover:shadow-md hover:bg-gray-50 dark:hover:bg-gray-700;
}
.c-mutation-list__item-header {
@apply flex items-start justify-between;
.c-mutation-list__item-content {
@apply flex items-center justify-between;
}
.c-mutation-list__item-author {
@apply font-semibold;
.c-mutation-list__item-desc {
@apply text-sm text-gray-600 dark:text-gray-400;
}
.c-mutation-list__item-meta {
@apply mt-1 flex items-center gap-2;
@apply flex items-center gap-2;
}
.c-mutation-list__item-amount {
@@ -268,54 +149,6 @@ function getAmountClass(amount: number): string {
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
}
.c-mutation-list__item-time {
@apply text-xs text-gray-500;
}
.c-mutation-list__item-desc {
@apply mt-3 text-sm text-gray-600 dark:text-gray-400;
}
.c-mutation-list__media-list {
@apply mt-3 flex flex-wrap gap-2;
}
.c-mutation-list__media-item {
@apply max-w-[200px] overflow-hidden rounded-md border border-neutral-200 bg-black dark:border-neutral-700;
}
.c-mutation-list__media-img {
@apply h-auto max-h-[150px] w-full cursor-pointer object-cover transition-opacity hover:opacity-90;
}
.c-mutation-list__media-video-wrapper {
@apply relative cursor-pointer transition-opacity hover:opacity-90;
}
.c-mutation-list__media-video {
@apply h-auto max-h-[150px] w-full;
}
.c-mutation-list__media-video-overlay {
@apply absolute inset-0 flex items-center justify-center bg-black/40 text-2xl font-bold text-white;
}
.c-mutation-list__actions {
@apply mt-3 flex gap-2 border-t border-neutral-100 pt-3 dark:border-neutral-700;
}
.c-mutation-list__approve-btn {
@apply inline-flex cursor-pointer items-center rounded bg-green-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-green-500;
}
.c-mutation-list__reject-btn {
@apply inline-flex cursor-pointer items-center rounded bg-red-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-red-500;
}
.c-mutation-list__void-btn {
@apply inline-flex cursor-pointer items-center rounded bg-gray-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-gray-500;
}
.c-mutation-list__empty {
@apply mt-4 text-gray-500;
}
@@ -39,11 +39,11 @@ const parsedContent = computed(() => {
let content = props.message.content;
// 1. Replace <user:id> placeholders with links to their dynamic profile
const userRegex = /<user:(\d+)>/g;
const userRegex = /<user:([0-9a-f-]+)>/g;
content = content.replace(userRegex, (match, userId) => {
const user = props.participantsById[Number(userId)];
const user = props.participantsById[(userId)];
if (user) {
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
const url = route('dynamics.users.show', [props.dynamicId, (userId)]);
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
user.pivot?.display_name ?? user.name
}</a>`;
@@ -77,7 +77,7 @@ const parsedContent = computed(() => {
/[-\/\\^$*+?.()|[\]{}]/g,
'\\$&',
);
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
content = content.replace(
nameRegex,
@@ -49,15 +49,21 @@ const parsedContent = computed(() => {
let content = props.message.content;
// 1. Replace <user:id> placeholders with links to their dynamic profile
const userRegex = /<user:(\d+)>/g;
const userRegex = /<user:([0-9a-f-]+)>/g;
content = content.replace(userRegex, (match, userId) => {
const user = props.participantsById[Number(userId)];
const user = props.participantsById[(userId)];
if (user) {
const url = route('dynamics.users.show', [props.dynamicId, Number(userId)]);
const url = route('dynamics.users.show', [
props.dynamicId,
(userId),
]);
return `<a href="${url}" class="c-chat__user-link font-semibold text-blue-500 hover:underline">${
user.pivot?.display_name ?? user.name
}</a>`;
}
return `User #${userId}`;
});
@@ -87,7 +93,7 @@ const parsedContent = computed(() => {
/[-\/\\^$*+?.()|[\]{}]/g,
'\\$&',
);
const nameRegex = new RegExp(`"${escapedName}"`, 'g');
content = content.replace(
nameRegex,
@@ -104,9 +110,7 @@ const parsedContent = computed(() => {
<template>
<div>
<div class="c-chat__message-header">
<span class="c-chat__message-author">{{
message.user?.name
}}</span>
<span class="c-chat__message-author">{{ message.user?.name }}</span>
<span
class="c-chat__message-time"
:title="formatTimestamp(message.created_at).full"
@@ -138,10 +142,7 @@ const parsedContent = computed(() => {
class="relative cursor-pointer transition-opacity hover:opacity-90"
@click="emit('open-lightbox', item.url, item.mime_type)"
>
<video
:src="item.url"
class="c-chat__video"
></video>
<video :src="item.url" class="c-chat__video"></video>
<div class="c-chat__play-overlay"></div>
</div>
</div>
+8 -8
View File
@@ -14,7 +14,7 @@ defineOptions({
});
defineProps<{
unreadEntities: Array<{
unreadDynamics: Array<{
id: number;
name: string;
url: string;
@@ -50,15 +50,17 @@ function formatTime(isoString: string): string {
<div class="c-dashboard__container">
<h2 class="c-dashboard__title">Recent Activity</h2>
<div v-if="unreadEntities.length > 0" class="c-dashboard__grid">
<div v-if="unreadDynamics.length > 0" class="c-dashboard__grid">
<div
v-for="entity in unreadEntities"
:key="entity.id"
v-for="dynamic in unreadDynamics"
:key="dynamic.id"
class="c-dashboard__card"
>
<div class="c-dashboard__card-header">
<div class="c-dashboard__entity-meta">
<span class="c-dashboard__badge-type c-dashboard__badge-type--dynamic">
<span
class="c-dashboard__badge-type c-dashboard__badge-type--dynamic"
>
Dynamic
</span>
<span class="c-dashboard__unread-count">
@@ -102,9 +104,7 @@ function formatTime(isoString: string): string {
v-if="dynamic.new_activities.length > 0"
class="c-dashboard__divider"
>
<span class="c-dashboard__divider-text"
>NEW</span
>
<span class="c-dashboard__divider-text">NEW</span>
</div>
<!-- New / Unread Activities -->
+28 -2
View File
@@ -34,12 +34,14 @@ const props = defineProps<{
id: number;
name: string;
rules: string;
alignment: 'positive' | 'neutral' | 'negative';
};
}>();
const form = useForm({
name: props.ledger.name,
rules: props.ledger.rules,
alignment: props.ledger.alignment,
});
function submit() {
@@ -69,6 +71,25 @@ function submit() {
<textarea v-model="form.rules" id="rules" rows="4" class="c-ledger-edit__textarea"></textarea>
</div>
<div class="c-ledger-edit__field">
<label for="alignment" class="c-ledger-edit__label">Alignment</label>
<select
v-model="form.alignment"
id="alignment"
class="c-ledger-edit__select"
>
<option value="positive">
Positive (Higher Score is Better)
</option>
<option value="neutral">
Neutral (Frictionless / Standard)
</option>
<option value="negative">
Negative (Lower Score is Better / Demerits)
</option>
</select>
</div>
<div class="c-ledger-edit__actions">
<button type="submit" :disabled="form.processing" class="c-ledger-edit__submit-btn">
Save
@@ -129,13 +150,18 @@ function submit() {
}
.c-ledger-edit__textarea {
@apply mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
}
.c-ledger-edit__select {
@apply mt-1 block w-full rounded-md border border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:border-gray-700 dark:bg-gray-900 dark:text-gray-300 dark:focus:border-indigo-600 dark:focus:ring-indigo-600;
}
.c-ledger-edit__actions {
@apply flex items-center gap-4;
@apply mt-6 flex items-center justify-end gap-4;
}
.c-ledger-edit__submit-btn {
@apply inline-flex items-center rounded-md border border-transparent bg-gray-800 px-4 py-2 text-xs font-semibold tracking-widest text-white uppercase transition duration-150 ease-in-out hover:bg-gray-700 focus:bg-gray-700 focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 focus:outline-none active:bg-gray-900 dark:bg-gray-200 dark:text-gray-800 dark:hover:bg-white dark:focus:bg-white dark:focus:ring-offset-gray-800 dark:active:bg-gray-300;
}
+7 -1
View File
@@ -45,6 +45,12 @@ const props = defineProps<{
alignment: string;
status: string;
media?: Array<{ id: number; url: string; mime_type: string }>;
predefined_mutations?: Array<{
id: string;
name: string;
description: string | null;
amount: number;
}>;
mutations: Array<{
id: number;
user_id: number;
@@ -262,7 +268,7 @@ function isOwnerUser(userId: number): boolean {
</div>
<!-- Add Mutation Form Component -->
<AddMutationForm :dynamic-id="dynamic.id" :ledger-id="ledger.id" />
<AddMutationForm :dynamic-id="dynamic.id" :ledger-id="ledger.id" :predefined-mutations="ledger.predefined_mutations" />
<!-- Mutation List Component -->
<MutationList
+308
View File
@@ -0,0 +1,308 @@
<script setup lang="ts">
import Chat from '@/components/Chat.vue';
import { defineOptions } from 'vue';
import { useForm } from '@inertiajs/vue3';
import { route } from 'ziggy-js';
const props = defineProps<{
mutation: {
id: string; // Updated to match serialization
user_id: number;
user: { name: string };
amount: number;
description: string;
status: string;
created_at: string;
chat: any;
media?: Array<{ id: number; url: string; mime_type: string }>;
can: {
update: boolean;
void: boolean;
};
ledger: {
id: string;
name: string;
dynamic_id: string;
alignment?: string;
dynamic: {
id: string;
name: string;
}
}
};
dynamic: {
id: string;
participants: any[];
};
can: {
update: boolean;
};
}>();
const dynamicId = props.dynamic.id;
function updateStatus(mutationId: string, status: 'approved' | 'rejected') {
useForm({ status }).put(
route('dynamics.ledgers.mutations.update', {
dynamic: props.dynamic.id,
ledger: props.mutation.ledger.id,
mutation: mutationId,
}),
);
}
function voidMutation(mutationId: string) {
useForm({}).put(
route('dynamics.ledgers.mutations.void', {
dynamic: props.dynamic.id,
ledger: props.mutation.ledger.id,
mutation: mutationId,
}),
);
}
function isOwnerUser(userId: number): boolean {
const participant = props.dynamic.participants?.find((p) => p.id === userId);
return participant?.pivot?.role === 'owner';
}
function getAmountClass(amount: number): string {
const alignment = props.mutation.ledger.alignment || 'neutral';
if (alignment === 'positive') {
return amount > 0
? 'c-mutation-list__item-amount--positive'
: 'c-mutation-list__item-amount--negative';
}
if (alignment === 'negative') {
return amount < 0
? 'c-mutation-list__item-amount--positive'
: 'c-mutation-list__item-amount--negative';
}
return 'c-mutation-list__item-amount--neutral';
}
defineOptions({
layout: (props: any) => ({
breadcrumbs: [
{ title: 'Dynamics', href: route('dynamics.index') },
{ title: props.mutation.ledger.dynamic.name, href: route('dynamics.show', props.mutation.ledger.dynamic.id) },
{ title: props.mutation.ledger.name, href: route('dynamics.ledgers.show', [props.mutation.ledger.dynamic.id, props.mutation.ledger.id]) },
{ title: 'Mutation Details', href: '' },
]
})
});
</script>
<template>
<div class="c-mutation-list__item">
<div class="c-mutation-list__item-header">
<div>
<span class="c-mutation-list__item-author">
{{
isOwnerUser(mutation.user_id)
? 'Added by'
: 'Suggested by'
}}
{{ mutation.user.name }}
</span>
<div class="c-mutation-list__item-meta">
<span
:class="getAmountClass(mutation.amount)"
class="c-mutation-list__item-amount"
>
{{ mutation.amount > 0 ? '+' : ''
}}{{ mutation.amount }}
</span>
<span
v-if="!isOwnerUser(mutation.user_id)"
:class="{
'c-mutation-list__item-status--pending':
mutation.status === 'pending',
'c-mutation-list__item-status--approved':
mutation.status === 'approved',
'c-mutation-list__item-status--rejected':
mutation.status === 'rejected',
}"
class="c-mutation-list__item-status"
>
{{ mutation.status }}
</span>
</div>
</div>
<div class="c-mutation-list__item-time">
{{ new Date(mutation.created_at).toLocaleString() }}
</div>
</div>
<p class="c-mutation-list__item-desc">
{{ mutation.description }}
</p>
<div
v-if="mutation.media && mutation.media.length > 0"
class="c-mutation-list__media-list"
>
<div
v-for="item in mutation.media"
:key="item.id"
class="c-mutation-list__media-item"
>
<img
v-if="item.mime_type.startsWith('image/')"
:src="item.url"
class="c-mutation-list__media-img"
/>
<div
v-else-if="item.mime_type.startsWith('video/')"
class="c-mutation-list__media-video-wrapper"
>
<video
:src="item.url"
class="c-mutation-list__media-video"
></video>
<div class="c-mutation-list__media-video-overlay">
</div>
</div>
</div>
</div>
<!-- Owner Approve/Reject/Void Actions -->
<div
v-if="mutation.can?.update || mutation.can?.void"
class="c-mutation-list__actions"
>
<button
v-if="mutation.can?.update"
@click="updateStatus(mutation.id, 'approved')"
class="c-mutation-list__approve-btn"
>
Approve
</button>
<button
v-if="mutation.can?.update"
@click="updateStatus(mutation.id, 'rejected')"
class="c-mutation-list__reject-btn"
>
Reject
</button>
<button
v-if="mutation.can?.void"
@click="voidMutation(mutation.id)"
class="c-mutation-list__void-btn"
>
Void
</button>
</div>
<Chat v-if="mutation.chat"
:chat="mutation.chat"
:participants="dynamic.participants"
:dynamic-id="dynamicId"
/>
</div>
</template>
<style scoped>
@reference "../../../css/app.css";
.c-mutation-list__item {
@apply overflow-hidden bg-white p-4 shadow-sm sm:rounded-lg dark:bg-gray-800;
}
.c-mutation-list__item-header {
@apply flex items-start justify-between;
}
.c-mutation-list__item-author {
@apply font-semibold;
}
.c-mutation-list__item-meta {
@apply mt-1 flex items-center gap-2;
}
.c-mutation-list__item-amount {
@apply text-sm font-bold;
}
.c-mutation-list__item-amount--positive {
@apply text-green-500;
}
.c-mutation-list__item-amount--negative {
@apply text-red-500;
}
.c-mutation-list__item-amount--neutral {
@apply text-gray-500 dark:text-gray-400;
}
.c-mutation-list__item-status {
@apply rounded px-1.5 py-0.5 text-[10px] font-medium tracking-wider uppercase;
}
.c-mutation-list__item-status--pending {
@apply bg-yellow-100 text-yellow-800 dark:bg-yellow-900/30 dark:text-yellow-400;
}
.c-mutation-list__item-status--approved {
@apply bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400;
}
.c-mutation-list__item-status--rejected {
@apply bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400;
}
.c-mutation-list__item-time {
@apply text-xs text-gray-500;
}
.c-mutation-list__item-desc {
@apply mt-3 text-sm text-gray-600 dark:text-gray-400;
}
.c-mutation-list__media-list {
@apply mt-3 flex flex-wrap gap-2;
}
.c-mutation-list__media-item {
@apply max-w-[200px] overflow-hidden rounded-md border border-neutral-200 bg-black dark:border-neutral-700;
}
.c-mutation-list__media-img {
@apply h-auto max-h-[150px] w-full cursor-pointer object-cover transition-opacity hover:opacity-90;
}
.c-mutation-list__media-video-wrapper {
@apply relative cursor-pointer transition-opacity hover:opacity-90;
}
.c-mutation-list__media-video {
@apply h-auto max-h-[150px] w-full;
}
.c-mutation-list__media-video-overlay {
@apply absolute inset-0 flex items-center justify-center bg-black/40 text-2xl font-bold text-white;
}
.c-mutation-list__actions {
@apply mt-3 mb-3 flex gap-2 border-t border-neutral-100 pt-3 dark:border-neutral-700;
}
.c-mutation-list__approve-btn {
@apply inline-flex cursor-pointer items-center rounded bg-green-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-green-500;
}
.c-mutation-list__reject-btn {
@apply inline-flex cursor-pointer items-center rounded bg-red-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-red-500;
}
.c-mutation-list__void-btn {
@apply inline-flex cursor-pointer items-center rounded bg-gray-600 px-3 py-1.5 text-xs font-semibold text-white hover:bg-gray-500;
}
</style>
+1 -1
View File
@@ -8,5 +8,5 @@ Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
});
Broadcast::channel('chats.{chat}', function ($user, Chat $chat) {
return $user->can('view', $chat->chatable);
return $user?->can('view', $chat);
});
+1 -1
View File
@@ -31,7 +31,7 @@ abstract class DuskTestCase extends BaseTestCase
$options = (new ChromeOptions)->addArguments((new Collection([
$this->shouldStartMaximized() ? '--start-maximized' : '--window-size=1920,1080',
'--disable-gpu',
'--headless=new',
// '--headless=new',
'--no-sandbox',
'--disable-dev-shm-usage',
]))->unless(static::runningInSail(), function (Collection $arguments) {
+8 -8
View File
@@ -18,7 +18,7 @@ test('authenticated users can visit the dashboard', function () {
$response = $this->get(route('dashboard'));
$response->assertOk();
$response->assertInertia(fn ($page) => $page->component('Dashboard')->has('unreadEntities'));
$response->assertInertia(fn ($page) => $page->component('Dashboard')->has('unreadDynamics'));
});
test('visiting dynamic updates the read cursor', function () {
@@ -100,12 +100,12 @@ test('dashboard groups and filters unread entities correctly based on cursor', f
// Verify unread grouping structure
$response->assertInertia(fn ($page) => $page
->component('Dashboard')
->where('unreadEntities.0.name', 'Testing Dynamic')
->where('unreadEntities.0.unread_count', 1)
->has('unreadEntities.0.context_activities', 1) // Should have old message as context
->where('unreadEntities.0.context_activities.0.content', 'Old message context')
->has('unreadEntities.0.new_activities', 1) // Should have unread message
->where('unreadEntities.0.new_activities.0.content', 'New unread message alert')
->where('unreadDynamics.0.name', 'Testing Dynamic')
->where('unreadDynamics.0.unread_count', 1)
->has('unreadDynamics.0.context_activities', 1) // Should have old message as context
->where('unreadDynamics.0.context_activities.0.content', 'Old message context')
->has('unreadDynamics.0.new_activities', 1) // Should have unread message
->where('unreadDynamics.0.new_activities.0.content', 'New unread message alert')
);
// Now visit the Dynamic, which clears the unread count
@@ -116,7 +116,7 @@ test('dashboard groups and filters unread entities correctly based on cursor', f
$response2->assertOk();
$response2->assertInertia(fn ($page) => $page
->component('Dashboard')
->has('unreadEntities', 0)
->has('unreadDynamics', 0)
);
Carbon::setTestNow(); // Reset test time
+1 -1
View File
@@ -99,5 +99,5 @@ test('only the user with the specified email address can accept the link', funct
// Verify system notification is added to Dynamic activity chat
$chatMessages = $dynamic->chat->messages;
expect($chatMessages)->not->toBeEmpty();
expect($chatMessages->last()->content)->toBe("<user:{$invitee->id}> joined the Dynamic as a EDITOR");
expect($chatMessages->last()->content)->toBe("<user:{$invitee->uuid}> joined the Dynamic as a EDITOR");
});
+22
View File
@@ -55,3 +55,25 @@ test('non-owners cannot view ledger creation form or store ledgers', function ()
'name' => 'Illegal Ledger',
]);
});
test('owner can edit a ledger', function () {
$owner = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$this->actingAs($owner);
$response = $this->put(route('dynamics.ledgers.update', [$dynamic->uuid, $ledger->uuid]), [
'name' => 'Updated Ledger Name',
'rules' => 'Updated rules.',
'alignment' => 'negative',
]);
$response->assertRedirect(route('dynamics.ledgers.show', [$dynamic->uuid, $ledger->uuid]));
$ledger->refresh();
expect($ledger->name)->toBe('Updated Ledger Name');
expect($ledger->rules)->toBe('Updated rules.');
expect($ledger->alignment)->toBe('negative');
});
+42 -6
View File
@@ -33,12 +33,12 @@ test('owner can create a mutation which is automatically approved and does not s
$mutationChatMessages = $mutation->chat->messages;
expect($mutationChatMessages)->toHaveCount(1);
expect($mutationChatMessages->first()->user_id)->toBeNull();
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->id}>.");
expect($mutationChatMessages->first()->content)->toBe("Entry was created by <user:{$owner->uuid}>.");
$dynamicChatMessages = $dynamic->chat->messages;
expect($dynamicChatMessages)->toHaveCount(1);
expect($dynamicChatMessages->first()->user_id)->toBeNull();
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->id}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
expect($dynamicChatMessages->first()->content)->toBe("<user:{$owner->uuid}> added entry \"Direct point reward\" for +15 points on \"{$ledger->name}\" ledger.");
});
test('non-owner participant creates a suggestion which defaults to pending and says suggested', function () {
@@ -71,12 +71,12 @@ test('non-owner participant creates a suggestion which defaults to pending and s
$mutationChatMessages = $mutation->chat->messages;
expect($mutationChatMessages)->toHaveCount(1);
expect($mutationChatMessages->first()->user_id)->toBeNull();
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->id}>.");
expect($mutationChatMessages->first()->content)->toBe("Suggestion was created by <user:{$participant->uuid}>.");
$dynamicChatMessages = $dynamic->chat->messages;
expect($dynamicChatMessages)->toHaveCount(1);
expect($dynamicChatMessages->first()->user_id)->toBeNull();
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->id}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
expect($dynamicChatMessages->first()->content)->toBe("<user:{$participant->uuid}> suggested \"Suggested point reward\" for +10 points on \"{$ledger->name}\" ledger.");
});
test('owner can approve a pending suggestion and it is updated and logged', function () {
@@ -115,11 +115,11 @@ test('owner can approve a pending suggestion and it is updated and logged', func
// Note: one from boot created (empty or via seeder, but in our factory it starts with 0 messages if not manually logged,
// actually our model booted hook creates the chat but doesn't log on boot, the update method creates 1 message)
expect($mutationChatMessages->last()->user_id)->toBeNull();
expect($mutationChatMessages->last()->content)->toBe("Suggestion was APPROVED by <user:{$owner->id}>.");
expect($mutationChatMessages->last()->content)->toBe("<user:{$owner->uuid}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
$dynamicChatMessages = $dynamic->chat->messages;
expect($dynamicChatMessages->last()->user_id)->toBeNull();
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->id}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
expect($dynamicChatMessages->last()->content)->toBe("<user:{$owner->uuid}> APPROVED the suggestion \"Polished dungeon floors\" for +20 points on \"{$ledger->name}\" ledger.");
});
test('creating a mutation with 0 points fails validation', function () {
@@ -172,3 +172,39 @@ test('creating a mutation with less than -1000 points fails validation', functio
$response->assertSessionHasErrors(['amount']);
expect(Mutation::where('description', 'Abusive negative point demerit')->exists())->toBeFalse();
});
test('participant can choose and request a predefined mutation', function () {
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id, 'score' => 100]);
$predefined = \App\Models\PredefinedMutation::create([
'ledger_id' => $ledger->id,
'name' => 'Wash the Motorbunny',
'amount' => 50,
'description' => 'Must be fully cleaned and dried.',
]);
$this->actingAs($participant);
$response = $this->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
'amount' => 50,
'description' => 'Completed Wash the Motorbunny template chore.',
'predefined_mutation_id' => $predefined->uuid,
]);
$response->assertRedirect(route('dynamics.ledgers.show', [$dynamic, $ledger]));
$mutation = Mutation::firstWhere('description', 'Completed Wash the Motorbunny template chore.');
expect($mutation)->not->toBeNull();
expect($mutation->status)->toBe('pending');
expect($mutation->predefined_mutation_id)->toBe($predefined->id);
// Score should NOT be updated since it is pending!
$ledger->refresh();
expect($ledger->score)->toBe(100);
});
+110
View File
@@ -0,0 +1,110 @@
<?php
namespace Tests\Feature;
use App\Models\Dynamic;
use App\Models\Ledger;
use App\Models\Mutation;
use App\Models\User;
use App\Notifications\NewActivityNotification;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Tests\TestCase;
class NotificationDispatchTest extends TestCase
{
use RefreshDatabase;
public function test_notification_is_sent_on_mutation_suggestion()
{
Notification::fake();
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$this->actingAs($participant)
->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
'description' => 'A test suggestion',
'amount' => 10,
]);
Notification::assertSentTo($owner, NewActivityNotification::class);
Notification::assertNotSentTo($participant, NewActivityNotification::class);
}
public function test_notification_is_sent_on_mutation_approval()
{
Notification::fake();
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$mutation = Mutation::factory()->create([
'ledger_id' => $ledger->id,
'user_id' => $participant->id,
'status' => 'pending',
]);
$this->actingAs($owner)
->put(route('dynamics.ledgers.mutations.update', [$dynamic, $ledger, $mutation]), [
'status' => 'approved',
]);
Notification::assertSentTo($participant, NewActivityNotification::class);
Notification::assertNotSentTo($owner, NewActivityNotification::class);
}
public function test_notification_is_sent_on_mutation_void()
{
Notification::fake();
$owner = User::factory()->create();
$participant = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$mutation = Mutation::factory()->create([
'ledger_id' => $ledger->id,
'user_id' => $participant->id,
'status' => 'approved',
]);
$this->actingAs($owner)
->put(route('dynamics.ledgers.mutations.void', [$dynamic, $ledger, $mutation]));
Notification::assertSentTo($participant, NewActivityNotification::class);
Notification::assertNotSentTo($owner, NewActivityNotification::class);
}
public function test_notification_is_sent_to_other_participants_when_owner_adds_mutation()
{
Notification::fake();
$owner = User::factory()->create();
$participant1 = User::factory()->create();
$participant2 = User::factory()->create();
$dynamic = Dynamic::factory()->create();
$dynamic->participants()->attach($owner->id, ['role' => 'owner']);
$dynamic->participants()->attach($participant1->id, ['role' => 'participant']);
$dynamic->participants()->attach($participant2->id, ['role' => 'participant']);
$ledger = Ledger::factory()->create(['dynamic_id' => $dynamic->id]);
$this->actingAs($owner)
->post(route('dynamics.ledgers.mutations.store', [$dynamic, $ledger]), [
'description' => 'A test mutation from owner',
'amount' => 25,
]);
Notification::assertSentTo($participant1, NewActivityNotification::class);
Notification::assertSentTo($participant2, NewActivityNotification::class);
Notification::assertNotSentTo($owner, NewActivityNotification::class);
}
}
+1 -1
View File
@@ -21,7 +21,7 @@ test('authenticated participant can view another participant detail page in dyna
$response->assertInertia(fn ($page) => $page
->component('Dynamics/Participants/Show')
->has('dynamic')
->where('participant.id', $participant->id)
->where('participant.id', $participant->uuid)
->where('participant.name', $participant->name)
->where('participant.display_name', null)
->where('participant.role', 'participant')
+3 -3
View File
@@ -25,8 +25,8 @@ test('owner can view predefined mutations for ledger', function () {
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->component('Ledgers/PredefinedMutations/Index')
->where('dynamic.id', $dynamic->id)
->where('ledger.id', $ledger->id)
->where('dynamic.id', $dynamic->uuid)
->where('ledger.id', $ledger->uuid)
->has('predefined_mutations', 1)
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
);
@@ -112,7 +112,7 @@ test('owner can view edit form for predefined mutation', function () {
$response->assertOk();
$response->assertInertia(fn ($page) => $page
->component('Ledgers/PredefinedMutations/Edit')
->where('predefined_mutation.id', $predefined->id)
->where('predefined_mutation.id', $predefined->uuid)
);
});