feat(tasks): complete task management system with Kanban, Calendar, notifications
- Add Task model with subtasks, priorities, status transitions, dates, hours - Add Comment polymorphic model for tasks/issues/projects - Livewire components: TaskManager (list+filters), TaskForm (modal), TaskDetail, TaskKanban (drag&drop), TaskCalendar (FullCalendar) - TaskPolicy with permissions (view/create/edit/delete/assign/manage all) - Notifications: assigned, status change, overdue, comment added - Daily overdue notification job scheduled - Dashboard widget unifies IssueTask + Task - i18n: en/es/fr/ru (393 keys each) - Routes, navigation, offline sync support - 101 tests passing, Pint compliant on new files
This commit is contained in:
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Task;
|
||||
use App\Models\User;
|
||||
|
||||
class TaskPolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any tasks.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
return $user->can('view tasks') || $user->can('manage all tasks');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the task.
|
||||
*/
|
||||
public function view(User $user, Task $task): bool
|
||||
{
|
||||
if ($user->can('manage all tasks')) {
|
||||
return true;
|
||||
}
|
||||
if (! $user->can('view tasks')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $task->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create tasks.
|
||||
*/
|
||||
public function create(User $user, $project = null): bool
|
||||
{
|
||||
if ($user->can('manage all tasks')) {
|
||||
return true;
|
||||
}
|
||||
if (! $user->can('create tasks')) {
|
||||
return false;
|
||||
}
|
||||
if ($project) {
|
||||
return $project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the task.
|
||||
*/
|
||||
public function update(User $user, Task $task): bool
|
||||
{
|
||||
if ($user->can('manage all tasks')) {
|
||||
return true;
|
||||
}
|
||||
if (! $user->can('edit tasks')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Own tasks or tasks in own projects
|
||||
return $task->created_by === $user->id
|
||||
|| $task->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the task.
|
||||
*/
|
||||
public function delete(User $user, Task $task): bool
|
||||
{
|
||||
if ($user->can('manage all tasks')) {
|
||||
return true;
|
||||
}
|
||||
if (! $user->can('delete tasks')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only creator or project admin can delete
|
||||
return $task->created_by === $user->id
|
||||
|| $task->project->users()->where('user_id', $user->id)->wherePivot('role_in_project', 'admin')->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can assign/reassign the task.
|
||||
*/
|
||||
public function assign(User $user, Task $task): bool
|
||||
{
|
||||
if ($user->can('manage all tasks')) {
|
||||
return true;
|
||||
}
|
||||
if (! $user->can('assign tasks')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $task->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the task.
|
||||
*/
|
||||
public function restore(User $user, Task $task): bool
|
||||
{
|
||||
if ($user->can('manage all tasks')) {
|
||||
return true;
|
||||
}
|
||||
if (! $user->can('edit tasks')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $task->project->users()->where('user_id', $user->id)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the task.
|
||||
*/
|
||||
public function forceDelete(User $user, Task $task): bool
|
||||
{
|
||||
return $user->can('manage all tasks');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user