Compare commits
No commits in common. "11df4ef55c2a1ae1108199898e5d438304ebf116" and "c6d482e3deac9508a054c8181c10abc60a9ca4c9" have entirely different histories.
11df4ef55c
...
c6d482e3de
@ -58,12 +58,6 @@ This project has domain-specific skills available in `**/skills/**`. You MUST ac
|
|||||||
- Stick to existing directory structure; don't create new base folders without approval.
|
- Stick to existing directory structure; don't create new base folders without approval.
|
||||||
- Do not change the application's dependencies without approval.
|
- Do not change the application's dependencies without approval.
|
||||||
|
|
||||||
## Activity Service
|
|
||||||
|
|
||||||
- The `app/Services/ActivityService.php` class is used to create system messages and activities.
|
|
||||||
- To create a system message, use the `createMessage` method. The `$user` parameter should be `null` to indicate a system message.
|
|
||||||
- The `createMutation` method can be used to create a mutation and its associated system message.
|
|
||||||
|
|
||||||
## Frontend Bundling
|
## Frontend Bundling
|
||||||
|
|
||||||
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `npm run build`, `npm run dev`, or `composer run dev`. Ask them.
|
- If the user doesn't see a frontend change reflected in the UI, it could mean they need to run `npm run build`, `npm run dev`, or `composer run dev`. Ask them.
|
||||||
|
|||||||
@ -53,12 +53,6 @@ We implemented a secure Dynamic Invitation flow to allow owners to invite new me
|
|||||||
```
|
```
|
||||||
* **Access Control:** Access to invitations and creation is fully protected under Owner-only authorization checks.
|
* **Access Control:** Access to invitations and creation is fully protected under Owner-only authorization checks.
|
||||||
|
|
||||||
### 7. Centralized Activity Service for System Messages
|
|
||||||
We created `app/Services/ActivityService.php` to centralize the creation of system messages and activities.
|
|
||||||
* **System Messages as `null` user_id**: System messages are stored as `Message` records with a `null` `user_id`, cleanly distinguishing them from user-generated content.
|
|
||||||
* **Polymorphic Subject Linking**: System messages are linked to relevant entities (e.g., a `User` who joined a dynamic, a `Ledger` that was created) via a polymorphic `subject` relationship on the `messages` table. This allows system messages on the dashboard to link directly to the relevant entity.
|
|
||||||
* **Seeder Refactoring**: The `DatabaseSeeder` was refactored to use the `ActivityService` to generate all system messages, ensuring consistency.
|
|
||||||
|
|
||||||
## Initial Database Schema
|
## Initial Database Schema
|
||||||
|
|
||||||
I will start with a basic schema and evolve it as I build features.
|
I will start with a basic schema and evolve it as I build features.
|
||||||
|
|||||||
@ -1,47 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Models\Dynamic;
|
|
||||||
use App\Models\Ledger;
|
|
||||||
use App\Models\PredefinedMutation;
|
|
||||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Inertia\Inertia;
|
|
||||||
|
|
||||||
class PredefinedMutationController extends Controller
|
|
||||||
{
|
|
||||||
use AuthorizesRequests;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*/
|
|
||||||
public function index(Dynamic $dynamic, Ledger $ledger)
|
|
||||||
{
|
|
||||||
$this->authorize('update', $dynamic);
|
|
||||||
|
|
||||||
return Inertia::render('Ledgers/PredefinedMutations/Index', [
|
|
||||||
'dynamic' => $dynamic,
|
|
||||||
'ledger' => $ledger,
|
|
||||||
'predefined_mutations' => $ledger->predefinedMutations()->latest()->get(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store a newly created resource in storage.
|
|
||||||
*/
|
|
||||||
public function store(Request $request, Dynamic $dynamic, Ledger $ledger)
|
|
||||||
{
|
|
||||||
$this->authorize('update', $dynamic);
|
|
||||||
|
|
||||||
$request->validate([
|
|
||||||
'name' => ['required', 'string', 'max:255'],
|
|
||||||
'description' => ['nullable', 'string'],
|
|
||||||
'amount' => ['required', 'integer'],
|
|
||||||
]);
|
|
||||||
|
|
||||||
$ledger->predefinedMutations()->create($request->all());
|
|
||||||
|
|
||||||
return redirect()->route('dynamics.ledgers.predefined-mutations.index', [$dynamic, $ledger]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -31,11 +31,6 @@ class Ledger extends Model
|
|||||||
return $this->hasMany(Mutation::class);
|
return $this->hasMany(Mutation::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function predefinedMutations(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(PredefinedMutation::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function media(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
public function media(): \Illuminate\Database\Eloquent\Relations\MorphMany
|
||||||
{
|
{
|
||||||
return $this->morphMany(Media::class, 'mediable');
|
return $this->morphMany(Media::class, 'mediable');
|
||||||
|
|||||||
@ -20,7 +20,6 @@ class Mutation extends Model
|
|||||||
'amount',
|
'amount',
|
||||||
'description',
|
'description',
|
||||||
'status',
|
'status',
|
||||||
'predefined_mutation_id',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
public function ledger(): BelongsTo
|
public function ledger(): BelongsTo
|
||||||
@ -33,11 +32,6 @@ class Mutation extends Model
|
|||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function predefinedMutation(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(PredefinedMutation::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function chat(): MorphOne
|
public function chat(): MorphOne
|
||||||
{
|
{
|
||||||
return $this->morphOne(Chat::class, 'chatable');
|
return $this->morphOne(Chat::class, 'chatable');
|
||||||
|
|||||||
@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
||||||
|
|
||||||
class PredefinedMutation extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
protected $fillable = [
|
|
||||||
'ledger_id',
|
|
||||||
'name',
|
|
||||||
'description',
|
|
||||||
'amount',
|
|
||||||
];
|
|
||||||
|
|
||||||
public function ledger(): BelongsTo
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Ledger::class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -45,31 +45,6 @@ class ActivityService
|
|||||||
return $cursor ? $cursor->read_at : Carbon::parse('1970-01-01');
|
return $cursor ? $cursor->read_at : Carbon::parse('1970-01-01');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createMessage($chat, $user, $content, $subject = null)
|
|
||||||
{
|
|
||||||
$message = $chat->messages()->create([
|
|
||||||
'user_id' => $user ? $user->id : null,
|
|
||||||
'content' => $content,
|
|
||||||
'subject_id' => $subject ? $subject->id : null,
|
|
||||||
'subject_type' => $subject ? get_class($subject) : null,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $message;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createMutation($ledger, $user, $type, $amount, $description, $status)
|
|
||||||
{
|
|
||||||
$mutation = $ledger->mutations()->create([
|
|
||||||
'user_id' => $user->id,
|
|
||||||
'type' => $type,
|
|
||||||
'amount' => $amount,
|
|
||||||
'description' => $description,
|
|
||||||
'status' => $status,
|
|
||||||
]);
|
|
||||||
|
|
||||||
return $mutation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve all activities for a given entity.
|
* Retrieve all activities for a given entity.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -1,31 +0,0 @@
|
|||||||
<?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('predefined_mutations', function (Blueprint $table) {
|
|
||||||
$table->id();
|
|
||||||
$table->foreignId('ledger_id')->constrained()->cascadeOnDelete();
|
|
||||||
$table->string('name');
|
|
||||||
$table->text('description')->nullable();
|
|
||||||
$table->integer('amount');
|
|
||||||
$table->timestamps();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('predefined_mutations');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,29 +0,0 @@
|
|||||||
<?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('mutations', function (Blueprint $table) {
|
|
||||||
$table->foreignId('predefined_mutation_id')->nullable()->constrained()->onDelete('set null');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::table('mutations', function (Blueprint $table) {
|
|
||||||
$table->dropForeign(['predefined_mutation_id']);
|
|
||||||
$table->dropColumn('predefined_mutation_id');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, useForm, Link as InertiaLink } from '@inertiajs/vue3';
|
import { Head, useForm } from '@inertiajs/vue3';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
import AppLayout from '@/layouts/AppLayout.vue';
|
||||||
|
|
||||||
|
|||||||
@ -1,237 +0,0 @@
|
|||||||
<script setup lang="ts">
|
|
||||||
import { Head, useForm } from '@inertiajs/vue3';
|
|
||||||
import { route } from 'ziggy-js';
|
|
||||||
import AppLayout from '@/layouts/AppLayout.vue';
|
|
||||||
import { defineProps } from 'vue';
|
|
||||||
|
|
||||||
const props = defineProps<{
|
|
||||||
dynamic: {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
ledger: {
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
};
|
|
||||||
predefined_mutations: Array<{
|
|
||||||
id: number;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
amount: number;
|
|
||||||
}>;
|
|
||||||
}>();
|
|
||||||
|
|
||||||
const form = useForm({
|
|
||||||
name: '',
|
|
||||||
description: '',
|
|
||||||
amount: 0,
|
|
||||||
});
|
|
||||||
|
|
||||||
const breadcrumbs = [
|
|
||||||
{
|
|
||||||
name: 'Dynamics',
|
|
||||||
href: route('dynamics.index'),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.dynamic.name,
|
|
||||||
href: route('dynamics.show', props.dynamic.id),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: props.ledger.name,
|
|
||||||
href: route('dynamics.ledgers.show', [props.dynamic.id, props.ledger.id]),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Predefined Mutations',
|
|
||||||
href: route('dynamics.ledgers.predefined-mutations.index', [props.dynamic.id, props.ledger.id]),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
function submit() {
|
|
||||||
form.post(route('dynamics.ledgers.predefined-mutations.store', [props.dynamic.id, props.ledger.id]), {
|
|
||||||
onSuccess: () => form.reset(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<template>
|
|
||||||
<Head title="Predefined Mutations" />
|
|
||||||
|
|
||||||
<AppLayout :breadcrumbs="breadcrumbs">
|
|
||||||
<div class="c-predefined-mutations">
|
|
||||||
<div class="c-predefined-mutations__container">
|
|
||||||
<div class="c-predefined-mutations__card">
|
|
||||||
<div class="c-predefined-mutations__body">
|
|
||||||
<h3 class="c-predefined-mutations__title">
|
|
||||||
Predefined Mutations for {{ ledger.name }}
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<div class="c-predefined-mutations__list">
|
|
||||||
<div
|
|
||||||
v-for="mutation in predefined_mutations"
|
|
||||||
:key="mutation.id"
|
|
||||||
class="c-predefined-mutations__item"
|
|
||||||
>
|
|
||||||
<div class="c-predefined-mutations__item-details">
|
|
||||||
<h4 class="c-predefined-mutations__item-name">
|
|
||||||
{{ mutation.name }}
|
|
||||||
</h4>
|
|
||||||
<p class="c-predefined-mutations__item-description">
|
|
||||||
{{ mutation.description }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div class="c-predefined-mutations__item-amount">
|
|
||||||
{{ mutation.amount }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="c-predefined-mutations__card mt-8">
|
|
||||||
<div class="c-predefined-mutations__body">
|
|
||||||
<h3 class="c-predefined-mutations__title">
|
|
||||||
Create New Predefined Mutation
|
|
||||||
</h3>
|
|
||||||
|
|
||||||
<form
|
|
||||||
@submit.prevent="submit"
|
|
||||||
class="c-predefined-mutations__form"
|
|
||||||
>
|
|
||||||
<div class="c-predefined-mutations__field">
|
|
||||||
<label
|
|
||||||
for="name"
|
|
||||||
class="c-predefined-mutations__label"
|
|
||||||
>Name</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
v-model="form.name"
|
|
||||||
id="name"
|
|
||||||
type="text"
|
|
||||||
class="c-predefined-mutations__input"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="c-predefined-mutations__field">
|
|
||||||
<label
|
|
||||||
for="description"
|
|
||||||
class="c-predefined-mutations__label"
|
|
||||||
>Description</label
|
|
||||||
>
|
|
||||||
<textarea
|
|
||||||
v-model="form.description"
|
|
||||||
id="description"
|
|
||||||
rows="4"
|
|
||||||
class="c-predefined-mutations__textarea"
|
|
||||||
></textarea>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="c-predefined-mutations__field">
|
|
||||||
<label
|
|
||||||
for="amount"
|
|
||||||
class="c-predefined-mutations__label"
|
|
||||||
>Amount</label
|
|
||||||
>
|
|
||||||
<input
|
|
||||||
v-model="form.amount"
|
|
||||||
id="amount"
|
|
||||||
type="number"
|
|
||||||
class="c-predefined-mutations__input"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="c-predefined-mutations__actions">
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
:disabled="form.processing"
|
|
||||||
class="c-predefined-mutations__submit-btn"
|
|
||||||
>
|
|
||||||
Create
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</AppLayout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
@reference "../../../../css/app.css";
|
|
||||||
|
|
||||||
.c-predefined-mutations {
|
|
||||||
@apply py-12;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__container {
|
|
||||||
@apply mx-auto max-w-7xl sm:px-6 lg:px-8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__card {
|
|
||||||
@apply overflow-hidden bg-white shadow-sm sm:rounded-lg dark:bg-gray-800;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__body {
|
|
||||||
@apply p-6 text-gray-900 dark:text-gray-100;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__title {
|
|
||||||
@apply text-lg font-medium;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__list {
|
|
||||||
@apply mt-6 space-y-4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__item {
|
|
||||||
@apply flex items-center justify-between rounded-lg border p-4 dark:border-gray-700;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__item-details {
|
|
||||||
@apply flex-1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__item-name {
|
|
||||||
@apply font-semibold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__item-description {
|
|
||||||
@apply text-sm text-gray-600 dark:text-gray-400;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__item-amount {
|
|
||||||
@apply text-lg font-semibold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__form {
|
|
||||||
@apply mt-6 space-y-6;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__field {
|
|
||||||
@apply block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__label {
|
|
||||||
@apply block text-sm font-medium text-gray-700 dark:text-gray-300;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__input {
|
|
||||||
@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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__select {
|
|
||||||
@apply mt-1 block w-full rounded-md border-gray-300 bg-white p-2 text-sm 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-predefined-mutations__actions {
|
|
||||||
@apply flex items-center gap-4;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-predefined-mutations__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;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Head, Link as InertiaLink } from '@inertiajs/vue3';
|
import { Head } from '@inertiajs/vue3';
|
||||||
import { useEcho } from '@laravel/echo-vue';
|
import { useEcho } from '@laravel/echo-vue';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { route } from 'ziggy-js';
|
import { route } from 'ziggy-js';
|
||||||
@ -168,25 +168,13 @@ function isOwnerUser(userId: number): boolean {
|
|||||||
<div class="c-ledger-show__container">
|
<div class="c-ledger-show__container">
|
||||||
<div class="c-ledger-show__card">
|
<div class="c-ledger-show__card">
|
||||||
<div class="c-ledger-show__body">
|
<div class="c-ledger-show__body">
|
||||||
<div class="flex flex-col sm:flex-row sm:justify-between sm:items-start gap-4">
|
<h3 class="c-ledger-show__title">{{ ledger.name }}</h3>
|
||||||
<div>
|
<p class="c-ledger-show__score">
|
||||||
<h3 class="c-ledger-show__title">{{ ledger.name }}</h3>
|
Score: {{ ledger.score }}
|
||||||
<p class="c-ledger-show__score">
|
</p>
|
||||||
Score: {{ ledger.score }}
|
<p class="c-ledger-show__rules">
|
||||||
</p>
|
{{ ledger.rules }}
|
||||||
<p class="c-ledger-show__rules">
|
</p>
|
||||||
{{ ledger.rules }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<div v-if="isOwner" class="flex flex-col gap-2">
|
|
||||||
<InertiaLink
|
|
||||||
:href="route('dynamics.ledgers.predefined-mutations.index', [dynamic.id, ledger.id])"
|
|
||||||
class="c-ledger-show__manage-btn"
|
|
||||||
>
|
|
||||||
Predefined Mutations
|
|
||||||
</InertiaLink>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Ledger Alignment Badge / Subtitle -->
|
<!-- Ledger Alignment Badge / Subtitle -->
|
||||||
<div class="c-ledger-show__alignment-wrapper">
|
<div class="c-ledger-show__alignment-wrapper">
|
||||||
@ -300,10 +288,6 @@ function isOwnerUser(userId: number): boolean {
|
|||||||
@apply py-12;
|
@apply py-12;
|
||||||
}
|
}
|
||||||
|
|
||||||
.c-ledger-show__manage-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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.c-ledger-show__container {
|
.c-ledger-show__container {
|
||||||
@apply mx-auto max-w-7xl sm:px-6 lg:px-8;
|
@apply mx-auto max-w-7xl sm:px-6 lg:px-8;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,8 +19,6 @@ Route::middleware(['auth', 'verified'])->group(function () {
|
|||||||
Route::get('/dynamics/{dynamic}/ledgers/create', [LedgerController::class, 'create'])->name('dynamics.ledgers.create');
|
Route::get('/dynamics/{dynamic}/ledgers/create', [LedgerController::class, 'create'])->name('dynamics.ledgers.create');
|
||||||
Route::resource('dynamics.ledgers', LedgerController::class)->scoped()->except(['create']);
|
Route::resource('dynamics.ledgers', LedgerController::class)->scoped()->except(['create']);
|
||||||
|
|
||||||
Route::resource('dynamics.ledgers.predefined-mutations', \App\Http\Controllers\PredefinedMutationController::class)->scoped();
|
|
||||||
|
|
||||||
Route::resource('dynamics.ledgers.mutations', MutationController::class)->scoped();
|
Route::resource('dynamics.ledgers.mutations', MutationController::class)->scoped();
|
||||||
|
|
||||||
Route::get('/dynamics/{dynamic}/invitations/create', [\App\Http\Controllers\DynamicInvitationController::class, 'create'])->name('dynamics.invitations.create');
|
Route::get('/dynamics/{dynamic}/invitations/create', [\App\Http\Controllers\DynamicInvitationController::class, 'create'])->name('dynamics.invitations.create');
|
||||||
|
|||||||
@ -1,92 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Models\User;
|
|
||||||
use App\Models\Dynamic;
|
|
||||||
use App\Models\Ledger;
|
|
||||||
use App\Models\PredefinedMutation;
|
|
||||||
|
|
||||||
test('owner can view predefined mutations for 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]);
|
|
||||||
|
|
||||||
$predefined = PredefinedMutation::create([
|
|
||||||
'ledger_id' => $ledger->id,
|
|
||||||
'name' => 'Weekly Room Cleaning',
|
|
||||||
'description' => 'Cleaned up the master bedroom',
|
|
||||||
'amount' => 20,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->actingAs($owner);
|
|
||||||
|
|
||||||
$response = $this->get(route('dynamics.ledgers.predefined-mutations.index', [$dynamic->id, $ledger->id]));
|
|
||||||
|
|
||||||
$response->assertOk();
|
|
||||||
$response->assertInertia(fn ($page) => $page
|
|
||||||
->component('Ledgers/PredefinedMutations/Index')
|
|
||||||
->where('ledger.id', $ledger->id)
|
|
||||||
->has('predefined_mutations', 1)
|
|
||||||
->where('predefined_mutations.0.name', 'Weekly Room Cleaning')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('non-owner cannot view predefined mutations for ledger', 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]);
|
|
||||||
|
|
||||||
$this->actingAs($participant);
|
|
||||||
|
|
||||||
$response = $this->get(route('dynamics.ledgers.predefined-mutations.index', [$dynamic->id, $ledger->id]));
|
|
||||||
|
|
||||||
$response->assertStatus(403);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('owner can create predefined mutations for 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->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->id, $ledger->id]), [
|
|
||||||
'name' => 'Polished mirrors',
|
|
||||||
'description' => 'Mirror polishing in dungeon',
|
|
||||||
'amount' => 15,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertRedirect();
|
|
||||||
$this->assertDatabaseHas('predefined_mutations', [
|
|
||||||
'ledger_id' => $ledger->id,
|
|
||||||
'name' => 'Polished mirrors',
|
|
||||||
'amount' => 15,
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('non-owner cannot create predefined mutations for ledger', 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]);
|
|
||||||
|
|
||||||
$this->actingAs($participant);
|
|
||||||
|
|
||||||
$response = $this->post(route('dynamics.ledgers.predefined-mutations.store', [$dynamic->id, $ledger->id]), [
|
|
||||||
'name' => 'Polished mirrors',
|
|
||||||
'description' => 'Mirror polishing in dungeon',
|
|
||||||
'amount' => 15,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$response->assertStatus(403);
|
|
||||||
$this->assertDatabaseMissing('predefined_mutations', [
|
|
||||||
'ledger_id' => $ledger->id,
|
|
||||||
'name' => 'Polished mirrors',
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
Loading…
x
Reference in New Issue
Block a user