@@ -52,7 +52,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
$folderId = (int) $folderId;
|
||||
|
||||
if (Folder::query()->forUser(auth()->id())->whereKey($folderId)->exists()) {
|
||||
if (Folder::query()->visibleTo(auth()->id(), $this->activeWorkspaceId())->whereKey($folderId)->exists()) {
|
||||
$this->folderId = $folderId;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
public function openEditForm(int $todoId): void
|
||||
{
|
||||
$todo = $this->todoForUser($todoId);
|
||||
$todo = $this->todoForAction($todoId, 'update');
|
||||
|
||||
$this->editingTodoId = $todo->id;
|
||||
$this->description = $todo->description;
|
||||
@@ -110,11 +110,20 @@ new #[Title('Todos')] class extends Component
|
||||
'todoStatus' => ['required', Rule::enum(TodoStatus::class)],
|
||||
'dueDate' => ['nullable', 'date'],
|
||||
'notes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
|
||||
'formFolderId' => ['required', 'integer', Rule::exists('folders', 'id')->where('user_id', auth()->id())],
|
||||
'formFolderId' => ['required', 'integer', Rule::exists('folders', 'id')->whereIn(
|
||||
'id',
|
||||
Folder::query()->visibleTo(auth()->id(), $this->activeWorkspaceId())->select('folders.id')
|
||||
)],
|
||||
]);
|
||||
|
||||
$folder = Folder::query()
|
||||
->visibleTo(auth()->id(), $this->activeWorkspaceId())
|
||||
->findOrFail($validated['formFolderId']);
|
||||
|
||||
abort_unless(auth()->user()->can('create', [Todo::class, $folder]), 403);
|
||||
|
||||
$data = [
|
||||
'folder_id' => $validated['formFolderId'],
|
||||
'folder_id' => $folder->id,
|
||||
'description' => $validated['description'],
|
||||
'status' => TodoStatus::from($validated['todoStatus']),
|
||||
'due_date' => filled($validated['dueDate']) ? Carbon::parse($validated['dueDate']) : null,
|
||||
@@ -122,11 +131,11 @@ new #[Title('Todos')] class extends Component
|
||||
];
|
||||
|
||||
if ($this->editingTodoId !== null) {
|
||||
$this->todoForUser($this->editingTodoId)->update($data);
|
||||
$this->todoForAction($this->editingTodoId, 'update')->update($data);
|
||||
} else {
|
||||
Todo::create($data + [
|
||||
'user_id' => auth()->id(),
|
||||
'position' => Todo::nextPositionFor(auth()->user()),
|
||||
'position' => Todo::nextPositionFor($folder),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -135,7 +144,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
public function toggleComplete(int $todoId): void
|
||||
{
|
||||
$todo = $this->todoForUser($todoId);
|
||||
$todo = $this->todoForAction($todoId, 'markComplete');
|
||||
|
||||
$data = ['completed_at' => $todo->completed_at === null ? now() : null];
|
||||
|
||||
@@ -150,7 +159,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
public function confirmTodoDelete(int $todoId): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
$this->todoForAction($todoId, 'delete');
|
||||
|
||||
$this->confirmingTodoDelete = $todoId;
|
||||
$this->modal('confirm-todo-delete')->show();
|
||||
@@ -158,7 +167,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
public function deleteTodo(): void
|
||||
{
|
||||
$this->todoForUser($this->confirmingTodoDelete)->delete();
|
||||
$this->todoForAction($this->confirmingTodoDelete ?? 0, 'delete')->delete();
|
||||
|
||||
$this->confirmingTodoDelete = null;
|
||||
$this->modal('confirm-todo-delete')->close();
|
||||
@@ -181,7 +190,7 @@ new #[Title('Todos')] class extends Component
|
||||
#[Computed]
|
||||
public function folderTree(): Collection
|
||||
{
|
||||
return Folder::treeForUser(auth()->id());
|
||||
return Folder::treeForVisibleTo(auth()->id(), $this->activeWorkspaceId());
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
@@ -243,7 +252,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
public function moveTodo(int $todoId, string $direction): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
$this->todoForAction($todoId, 'update');
|
||||
|
||||
$ids = $this->orderedTodoIds;
|
||||
$currentIndex = array_search($todoId, $ids, true);
|
||||
@@ -263,7 +272,7 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
public function handleSort(int $todoId, int $position): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
$this->todoForAction($todoId, 'update');
|
||||
|
||||
$this->reorderTodo($todoId, $position);
|
||||
}
|
||||
@@ -294,7 +303,7 @@ new #[Title('Todos')] class extends Component
|
||||
unset($visibleOrder[$currentIndex]);
|
||||
array_splice($visibleOrder, $newIndex, 0, $todoId);
|
||||
|
||||
$ids = Todo::query()->forUser(auth()->id())->priority()->pluck('id')->all();
|
||||
$ids = Todo::query()->visibleTo(auth()->id(), $this->activeWorkspaceId())->priority()->pluck('id')->all();
|
||||
|
||||
$slots = array_keys(array_intersect($ids, $visibleIds));
|
||||
|
||||
@@ -303,7 +312,7 @@ new #[Title('Todos')] class extends Component
|
||||
}
|
||||
|
||||
foreach ($ids as $position => $id) {
|
||||
Todo::query()->forUser(auth()->id())->whereKey($id)->update(['position' => $position]);
|
||||
Todo::query()->visibleTo(auth()->id(), $this->activeWorkspaceId())->whereKey($id)->update(['position' => $position]);
|
||||
}
|
||||
|
||||
unset($this->todos, $this->orderedTodoIds);
|
||||
@@ -315,7 +324,7 @@ new #[Title('Todos')] class extends Component
|
||||
private function filteredTodoQuery(): Builder
|
||||
{
|
||||
return Todo::query()
|
||||
->forUser(auth()->id())
|
||||
->visibleTo(auth()->id(), $this->activeWorkspaceId())
|
||||
->when(
|
||||
$this->search !== '',
|
||||
fn (Builder $query) => $query->where('description', 'like', '%'.$this->search.'%')
|
||||
@@ -346,9 +355,21 @@ new #[Title('Todos')] class extends Component
|
||||
return $ids;
|
||||
}
|
||||
|
||||
private function todoForUser(int $todoId): Todo
|
||||
private function todoForAction(int $todoId, string $ability): Todo
|
||||
{
|
||||
return Todo::query()->forUser(auth()->id())->findOrFail($todoId);
|
||||
$todo = Todo::query()
|
||||
->visibleTo(auth()->id(), $this->activeWorkspaceId())
|
||||
->with('folder')
|
||||
->findOrFail($todoId);
|
||||
|
||||
abort_unless(auth()->user()->can($ability, $todo), 403);
|
||||
|
||||
return $todo;
|
||||
}
|
||||
|
||||
private function activeWorkspaceId(): int
|
||||
{
|
||||
return (int) auth()->user()->current_organization_id;
|
||||
}
|
||||
}; ?>
|
||||
|
||||
@@ -424,18 +445,22 @@ new #[Title('Todos')] class extends Component
|
||||
@forelse ($this->todos as $todo)
|
||||
<flux:table.row :key="$todo->id" wire:sort:item="{{ $todo->id }}" data-test="todo-row">
|
||||
<flux:table.cell class="py-0 text-zinc-300 dark:text-zinc-600">
|
||||
<div wire:sort:handle class="inline-flex cursor-grab" title="{{ __('Reorder') }}">
|
||||
<flux:icon.chevrons-up-down variant="micro" />
|
||||
</div>
|
||||
@can('update', $todo)
|
||||
<div wire:sort:handle class="inline-flex cursor-grab" title="{{ __('Reorder') }}">
|
||||
<flux:icon.chevrons-up-down variant="micro" />
|
||||
</div>
|
||||
@endcan
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell class="py-0">
|
||||
<flux:checkbox
|
||||
:checked="$todo->completed_at !== null"
|
||||
:title="$todo->completed_at ? __('Mark as not done') : __('Mark as done')"
|
||||
wire:click="toggleComplete({{ $todo->id }})"
|
||||
data-test="toggle-complete-{{ $todo->id }}"
|
||||
/>
|
||||
@can('markComplete', $todo)
|
||||
<flux:checkbox
|
||||
:checked="$todo->completed_at !== null"
|
||||
:title="$todo->completed_at ? __('Mark as not done') : __('Mark as done')"
|
||||
wire:click="toggleComplete({{ $todo->id }})"
|
||||
data-test="toggle-complete-{{ $todo->id }}"
|
||||
/>
|
||||
@endcan
|
||||
</flux:table.cell>
|
||||
|
||||
<flux:table.cell :variant="$todo->completed_at ? 'strong' : 'default'" data-test="todo-description-{{ $todo->id }}">
|
||||
@@ -491,44 +516,46 @@ new #[Title('Todos')] class extends Component
|
||||
|
||||
<flux:table.cell class="py-0">
|
||||
<div class="flex justify-end gap-1">
|
||||
@if ($todo->id !== ($this->orderedTodoIds[0] ?? null))
|
||||
@can('update', $todo)
|
||||
@if ($todo->id !== ($this->orderedTodoIds[0] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-up"
|
||||
:title="__('Move up')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'up')"
|
||||
data-test="move-todo-up-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
|
||||
@if ($todo->id !== ($this->orderedTodoIds[array_key_last($this->orderedTodoIds)] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-down"
|
||||
:title="__('Move down')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'down')"
|
||||
data-test="move-todo-down-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-up"
|
||||
:title="__('Move up')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'up')"
|
||||
data-test="move-todo-up-{{ $todo->id }}"
|
||||
icon="pencil-square"
|
||||
:title="__('Edit todo')"
|
||||
wire:click="openEditForm({{ $todo->id }})"
|
||||
data-test="edit-todo-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
|
||||
@if ($todo->id !== ($this->orderedTodoIds[array_key_last($this->orderedTodoIds)] ?? null))
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="chevron-down"
|
||||
:title="__('Move down')"
|
||||
wire:click="moveTodo({{ $todo->id }}, 'down')"
|
||||
data-test="move-todo-down-{{ $todo->id }}"
|
||||
icon="trash"
|
||||
:title="__('Delete todo')"
|
||||
wire:click="confirmTodoDelete({{ $todo->id }})"
|
||||
data-test="delete-todo-{{ $todo->id }}"
|
||||
/>
|
||||
@endif
|
||||
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="pencil-square"
|
||||
:title="__('Edit todo')"
|
||||
wire:click="openEditForm({{ $todo->id }})"
|
||||
data-test="edit-todo-{{ $todo->id }}"
|
||||
/>
|
||||
<flux:button
|
||||
size="sm"
|
||||
variant="ghost"
|
||||
icon="trash"
|
||||
:title="__('Delete todo')"
|
||||
wire:click="confirmTodoDelete({{ $todo->id }})"
|
||||
data-test="delete-todo-{{ $todo->id }}"
|
||||
/>
|
||||
@endcan
|
||||
</div>
|
||||
</flux:table.cell>
|
||||
</flux:table.row>
|
||||
|
||||
Reference in New Issue
Block a user