@@ -55,7 +55,7 @@ new #[Title('Dashboard')] 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;
|
||||
}
|
||||
}
|
||||
@@ -93,7 +93,7 @@ new #[Title('Dashboard')] 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;
|
||||
@@ -113,11 +113,20 @@ new #[Title('Dashboard')] 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,
|
||||
@@ -125,11 +134,11 @@ new #[Title('Dashboard')] 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),
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -138,7 +147,7 @@ new #[Title('Dashboard')] 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];
|
||||
|
||||
@@ -153,7 +162,7 @@ new #[Title('Dashboard')] 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();
|
||||
@@ -161,7 +170,7 @@ new #[Title('Dashboard')] 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();
|
||||
@@ -176,7 +185,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
#[Computed]
|
||||
public function todoCounts(): array
|
||||
{
|
||||
$query = Todo::query()->forUser(auth()->id());
|
||||
$query = Todo::query()->visibleTo(auth()->id(), $this->activeWorkspaceId());
|
||||
|
||||
return [
|
||||
'open' => (clone $query)->active()->count(),
|
||||
@@ -189,7 +198,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
#[Computed]
|
||||
public function folderTree(): Collection
|
||||
{
|
||||
return Folder::treeForUser(auth()->id());
|
||||
return Folder::treeForVisibleTo(auth()->id(), $this->activeWorkspaceId());
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
@@ -208,12 +217,12 @@ new #[Title('Dashboard')] class extends Component
|
||||
$tree = $this->folderTree;
|
||||
|
||||
$openByFolder = Todo::query()
|
||||
->forUser(auth()->id())
|
||||
->visibleTo(auth()->id(), $this->activeWorkspaceId())
|
||||
->active()
|
||||
->pluck('folder_id')
|
||||
->countBy();
|
||||
$overdueByFolder = Todo::query()
|
||||
->forUser(auth()->id())
|
||||
->visibleTo(auth()->id(), $this->activeWorkspaceId())
|
||||
->overdue()
|
||||
->pluck('folder_id')
|
||||
->countBy();
|
||||
@@ -264,7 +273,7 @@ new #[Title('Dashboard')] 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);
|
||||
@@ -284,7 +293,7 @@ new #[Title('Dashboard')] class extends Component
|
||||
|
||||
public function handleSort(int $todoId, int $position): void
|
||||
{
|
||||
$this->todoForUser($todoId);
|
||||
$this->todoForAction($todoId, 'update');
|
||||
|
||||
$offset = ($this->todos->currentPage() - 1) * self::PER_PAGE;
|
||||
|
||||
@@ -317,7 +326,7 @@ new #[Title('Dashboard')] 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));
|
||||
|
||||
@@ -326,7 +335,7 @@ new #[Title('Dashboard')] 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);
|
||||
@@ -338,7 +347,7 @@ new #[Title('Dashboard')] 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.'%')
|
||||
@@ -369,9 +378,21 @@ new #[Title('Dashboard')] 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;
|
||||
}
|
||||
}; ?>
|
||||
|
||||
@@ -510,18 +531,22 @@ new #[Title('Dashboard')] 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 }}">
|
||||
@@ -581,44 +606,46 @@ new #[Title('Dashboard')] 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