add new sources
- permissions - all about the permission system - selected task - requirements for the task - list-wireframe - html mock of the page - tdd - tdd step through implemention
This commit is contained in:
@@ -1,95 +0,0 @@
|
||||
Priority,Category,Workflow
|
||||
P0,Code Writing,Feature Implementation
|
||||
P0,Code Writing,Refactoring & Code Cleanup
|
||||
P0,Code Writing,Script & Automation Writing
|
||||
P0,Code Writing,Library / SDK Integration
|
||||
P0,Code Writing,Migration Script Writing
|
||||
P0,Code Writing,Prototyping / Spikes
|
||||
P0,Code Writing,Version Control Management
|
||||
P0,Testing,Unit Test Writing
|
||||
P0,Testing,Integration Test Writing
|
||||
P0,Testing,End-to-End Test Writing
|
||||
P0,Testing,Test Infrastructure Setup
|
||||
P0,Testing,Coverage Analysis & Gap Identification
|
||||
P0,Testing,Spec Compliance Verification
|
||||
P0,Testing,Performance & Load Testing
|
||||
P0,Testing,"Manual Testing (including CLI / API Correctness Testing and UI testing)"
|
||||
P0,Debugging,Root Cause Analysis
|
||||
P0,Debugging,Tracing & Observability-Based Investigation
|
||||
P0,Debugging,Issue Reproduction & Isolation
|
||||
P0,Debugging,Cross-Component Interaction Debugging
|
||||
P0,Debugging,Concurrency & Non-Determinism Debugging
|
||||
P0,Debugging,Performance Regression Debugging
|
||||
P0,Debugging,Blast Radius & Upstream Dependency Analysis
|
||||
P0,Debugging,Fix Implementation & Regression Prevention
|
||||
P0,Debugging,Temporary Mitigation Identification
|
||||
P0,Code Review,Pull Request Creation & Description Writing
|
||||
P0,Code Review,Code Review & Feedback / Asynchronous Peer Review
|
||||
P0,Code Review,Security Vulnerability Identification
|
||||
P0,Code Review,Architectural & Design Review
|
||||
P0,Code Review,Maintainability & Readability Review
|
||||
P0,Code Review,Responses to Change Requests
|
||||
P0,Code Review,Review of Pull Request Descriptions
|
||||
P0,Code Review,Pull Request Scoping & Branch History Cleanup
|
||||
P0,Code Review,Review of Pull Request Scoping & Branch History
|
||||
P0,Code Review,"Review of Responses to Requested Changes & Approval / Asynchronous Peer Review"
|
||||
P0,Code Review,Merging in Accordance with Branching & Merge Strategy
|
||||
P0,Product Interaction,CLI Ergonomics & UX Design
|
||||
P0,Product Interaction,API Discoverability & Developer Experience
|
||||
P0,Product Interaction,Contribute to UI/UX Design & Prototyping
|
||||
P0,Product Interaction,Error Message & Feedback Design
|
||||
P0,Product Interaction,Accessibility Review & Remediation
|
||||
P0,Product Interaction,Product Walkthrough & Usability Validation
|
||||
P0,Requirements,Requirements Gathering & Elicitation
|
||||
P0,Requirements,Scope Definition & Acceptance Criteria
|
||||
P0,Requirements,Edge Case & Constraint Identification
|
||||
P0,Requirements,Ambiguity Resolution & Clarifying Questions
|
||||
P0,Requirements,Specification Writing
|
||||
P0,Design,System Architecture Design
|
||||
P0,Design,API Design & Contract Definition
|
||||
P0,Design,Database Architecture & Schema Design
|
||||
P0,Design,Technical Specification Writing
|
||||
P0,Design,Technology Selection & Trade-off Analysis
|
||||
P0,Design,Change Impact Analysis
|
||||
P0,Design,Threat Modeling & Attack Surface Analysis
|
||||
P0,Design,Abstraction & Interface Design
|
||||
P0,Deployment,CI/CD Pipeline Authoring & Configuration
|
||||
P0,Deployment,Build & Artifact Management
|
||||
P0,Deployment,"Release Management (Rollouts, Rollbacks, Feature Flags)"
|
||||
P0,Deployment,"Infrastructure as Code (Terraform, CloudFormation)"
|
||||
P0,Deployment,Environment Provisioning & Configuration
|
||||
P0,Deployment,"Cloud Platform Operations (AWS, GCP, Azure)"
|
||||
P0,Deployment,"Containerization & Orchestration (Docker, Kubernetes)"
|
||||
P0,Deployment,Secrets & Credential Management
|
||||
P0,Deployment,Exploit Mitigation
|
||||
P0,Deployment,Branching & Merge Strategy
|
||||
P0,Maintenance,Performance Optimization & Performance Measurement
|
||||
P1,Maintenance,"Observability Framework Development & Usage (Logging, Metrics, Tracing)"
|
||||
P1,Maintenance,Monitoring & Alerting Configuration
|
||||
P1,Maintenance,Incident Triage & On-Call Response
|
||||
P1,Maintenance,Incident Postmortem Writing
|
||||
P1,Maintenance,Dependency Updates & Security Patching
|
||||
P1,Maintenance,Dependency Vulnerability Auditing
|
||||
P1,Maintenance,Dependency & Package Management
|
||||
P1,Maintenance,Security Incident Response
|
||||
P1,Maintenance,Database Migrations & Data Upgrades
|
||||
P1,Maintenance,Scaling & Capacity Management
|
||||
P1,Maintenance,Permission & Access Management
|
||||
P1,Maintenance,Technical Debt Remediation
|
||||
P1,Maintenance,Identify & Resolve Branch/Merge Mistakes
|
||||
P1,Communication,Technical Documentation Writing (Internal)
|
||||
P1,Communication,Runbook & Playbook Authoring
|
||||
P1,Communication,Stakeholder Update & Status Reporting
|
||||
P1,Communication,Feature Request Triage & Response
|
||||
P1,Communication,Knowledge Sharing & Onboarding Docs
|
||||
P1,Communication,Cross-Team Coordination & Handoffs
|
||||
P1,Communication,Customer-Facing Issue Communication
|
||||
P1,Communication,Vendor Tooling Evaluation
|
||||
P2,Planning & Prioritization,Project Scoping & Estimation
|
||||
P2,Planning & Prioritization,Sprint / Iteration Planning
|
||||
P2,Planning & Prioritization,Contribute to Roadmap Creation & Prioritization
|
||||
P2,Planning & Prioritization,Risk Assessment & Mitigation Planning
|
||||
P2,Planning & Prioritization,Resource Allocation & Capacity Planning
|
||||
P2,Planning & Prioritization,Technical Debt Triage & Prioritization
|
||||
P2,Planning & Prioritization,Stakeholder Alignment & Goal Setting
|
||||
P2,Planning & Prioritization,Task Decomposition & Sequencing
|
||||
|
417
sources/nearbeach-permissions-guide.md
Normal file
417
sources/nearbeach-permissions-guide.md
Normal file
@@ -0,0 +1,417 @@
|
||||
# NearBeach Permission System — Implementation Guide
|
||||
|
||||
*Based on codebase analysis of `/home/ericbell/workspaces/dataannotation/project-5/NearBeach/`*
|
||||
|
||||
---
|
||||
|
||||
## 1. Core Architecture
|
||||
|
||||
### 1.1 Models
|
||||
|
||||
| Model | Role |
|
||||
|-------|------|
|
||||
| **`UserGroup`** | Links `User` → `Group` + `PermissionSet` (permission levels per object type) |
|
||||
| **`ObjectAssignment`** | ACL: Links `Group` (or `assigned_user`) → `Project`/`Task`/`Requirement`/etc. — **access only** (yes/no) |
|
||||
| **`PermissionSet`** | Defines levels: `task` (1=read, 2=write, 3=create, 4=admin), `project`, `requirement`, etc. |
|
||||
|
||||
### 1.2 Permission Flow
|
||||
|
||||
```
|
||||
User
|
||||
└── UserGroup (is_deleted=False, username=request.user)
|
||||
├── group_id ──────────────────┐
|
||||
└── permission_set │
|
||||
├── task: 1..4 │
|
||||
├── project: 1..4 │ → MAX across groups = user_level
|
||||
├── requirement: 1..4 │
|
||||
└── ... │
|
||||
▼
|
||||
ObjectAssignment (is_deleted=False)
|
||||
├── group_id (FK to Group) ← PRIMARY
|
||||
├── assigned_user (FK to User) ← SECONDARY
|
||||
├── project_id (nullable)
|
||||
├── task_id (nullable)
|
||||
├── requirement_id (nullable)
|
||||
└── ... other objects
|
||||
```
|
||||
|
||||
**Key insight**: Permissions are **group-based**, not user-based. `ObjectAssignment.group_id` is the primary link; `assigned_user` is used sparingly (e.g., `get_my_objects`).
|
||||
|
||||
---
|
||||
|
||||
## 2. Permission Levels
|
||||
|
||||
| Level | Name | Typical Use |
|
||||
|-------|------|-------------|
|
||||
| 1 | Read | View object, list views |
|
||||
| 2 | Write | Edit object |
|
||||
| 3 | Create | Create new objects of this type |
|
||||
| 4 | Admin | Full control (delete, manage permissions) |
|
||||
|
||||
Superusers (`request.user.is_superuser`) bypass all checks → `user_level=4`.
|
||||
|
||||
---
|
||||
|
||||
## 3. Key Functions to Reuse
|
||||
|
||||
### 3.1 `task_permissions(request, kwargs)` — Single Object Check
|
||||
```python
|
||||
# NearBeach/decorators/check_user_permissions/partials/task_permissions.py
|
||||
def task_permissions(request, kwargs):
|
||||
user_group_results = UserGroup.objects.filter(
|
||||
is_deleted=False, username=request.user
|
||||
).filter(
|
||||
Q(group_id__in=ObjectAssignment.objects.filter(
|
||||
is_deleted=False, group_id__isnull=False,
|
||||
task_id=kwargs["task_id"]
|
||||
).values("group_id")) & Q(username=request.user)
|
||||
)
|
||||
if not user_group_results.exists():
|
||||
return False, 0, False
|
||||
user_level = user_group_results.aggregate(
|
||||
Max("permission_set__task")
|
||||
)["permission_set__task__max"]
|
||||
return True, user_level, False
|
||||
```
|
||||
|
||||
**Used by**: `@check_specific_object_permissions(min_permission_level=X, object_lookup="task")` decorator on `task_information`, `task_information_save`, `new_task`, `new_task_save`.
|
||||
|
||||
---
|
||||
|
||||
### 3.2 `get_user_group_permission(user, object_types)` — Template Context
|
||||
```python
|
||||
# NearBeach/views/tools/internal_functions.py
|
||||
def get_user_group_permission(username, object_types):
|
||||
# Returns JSON: [{group_id, group_name, object_type, object_permission_value}, ...]
|
||||
# Used in templates to conditionally show create/edit buttons
|
||||
```
|
||||
**Used in**: `new_task`, `new_project`, `new_requirement` views → passed to template as `user_group_permissions`.
|
||||
|
||||
---
|
||||
|
||||
### 3.3 Decorators
|
||||
|
||||
| Decorator | Use Case |
|
||||
|-----------|----------|
|
||||
| `@check_specific_object_permissions(min_level, object_lookup="task")` | Single-object views (`task_information`, `project_information`) |
|
||||
| `@check_user_generic_permissions(min_level)` | Generic destination/location_id views |
|
||||
| **List views use neither** | Just `@login_required` + manual queryset filtering |
|
||||
|
||||
---
|
||||
|
||||
## 4. List View Pattern — The Canonical Way
|
||||
|
||||
### 4.1 `sprint_list` (Reference Implementation)
|
||||
|
||||
```python
|
||||
# NearBeach/views/sprint_views.py
|
||||
@login_required(login_url="login", redirect_field_name="")
|
||||
def sprint_list(request):
|
||||
# 1. Get user's groups
|
||||
user_groups = UserGroup.objects.filter(
|
||||
is_deleted=False, username=request.user
|
||||
).values('group_id')
|
||||
|
||||
# 2. Get ObjectAssignments for those groups (project OR requirement level)
|
||||
object_assignment_results = ObjectAssignment.objects.filter(
|
||||
Q(
|
||||
is_deleted=False,
|
||||
group_id__in=user_groups,
|
||||
) & Q(
|
||||
Q(project_id__isnull=False) |
|
||||
Q(requirement_id__isnull=False)
|
||||
)
|
||||
)
|
||||
|
||||
# 3. Filter Sprints by those project/requirement IDs
|
||||
sprint_results = Sprint.objects.filter(
|
||||
Q(is_deleted=False, project_id__in=object_assignment_results.values("project_id")) |
|
||||
Q(is_deleted=False, requirement_id__in=object_assignment_results.values("requirement_id"))
|
||||
).exclude(sprint_status="Finished").values(...)
|
||||
```
|
||||
|
||||
### 4.2 `get_kanban_list` (Simpler Variant)
|
||||
|
||||
```python
|
||||
# NearBeach/views/dashboard_views.py
|
||||
@login_required(login_url="login", redirect_field_name="")
|
||||
@require_http_methods(["POST"])
|
||||
def get_kanban_list(request):
|
||||
object_assignment_results = ObjectAssignment.objects.filter(
|
||||
is_deleted=False,
|
||||
kanban_board_id__isnull=False,
|
||||
group_id__in=UserGroup.objects.filter(
|
||||
is_deleted=False, username=request.user
|
||||
).values("group_id"),
|
||||
)
|
||||
kanban_results = KanbanBoard.objects.filter(
|
||||
is_deleted=False,
|
||||
kanban_board_status="Open",
|
||||
kanban_board_id__in=object_assignment_results.values("kanban_board_id"),
|
||||
)
|
||||
```
|
||||
|
||||
### 4.3 `get_unassigned_objects` (With Permission Level Check)
|
||||
|
||||
```python
|
||||
# Adds permission_set__task__gt=0 to ensure user has at least read access
|
||||
task_results = Task.objects.filter(
|
||||
is_deleted=False,
|
||||
task_id__in=ObjectAssignment.objects.filter(
|
||||
is_deleted=False,
|
||||
group_id__in=UserGroup.objects.filter(
|
||||
is_deleted=False,
|
||||
username=request.user,
|
||||
permission_set__task__gt=0, # ← CHECKS PERMISSION LEVEL
|
||||
).values("group_id"),
|
||||
).values("task_id"),
|
||||
).exclude(...)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Task List View — Implementation Blueprint
|
||||
|
||||
### 5.1 View Function
|
||||
|
||||
```python
|
||||
# NearBeach/views/task_views.py — ADD THIS
|
||||
@login_required(login_url="login", redirect_field_name="")
|
||||
def task_list(request):
|
||||
"""
|
||||
Task list view with filtering, sorting, pagination.
|
||||
Respects ObjectAssignment group-based permissions.
|
||||
"""
|
||||
# 1. Get user's groups
|
||||
user_groups = UserGroup.objects.filter(
|
||||
is_deleted=False, username=request.user
|
||||
).values('group_id')
|
||||
|
||||
# 2. Get project IDs user has access to via ObjectAssignment
|
||||
# Tasks live in projects, so we filter at project level
|
||||
accessible_project_ids = ObjectAssignment.objects.filter(
|
||||
is_deleted=False,
|
||||
group_id__in=user_groups,
|
||||
project_id__isnull=False,
|
||||
).values_list('project_id', flat=True).distinct()
|
||||
|
||||
# 3. Base queryset — superuser sees all
|
||||
if request.user.is_superuser:
|
||||
tasks_qs = Task.objects.filter(is_deleted=False)
|
||||
else:
|
||||
tasks_qs = Task.objects.filter(
|
||||
is_deleted=False,
|
||||
project_id__in=accessible_project_ids,
|
||||
)
|
||||
|
||||
# 4. Apply filters (status, assignee, project, date range)
|
||||
# ... filter logic here ...
|
||||
|
||||
# 5. Apply sorting
|
||||
# ... sort logic here ...
|
||||
|
||||
# 6. Pagination
|
||||
# ... paginate logic here ...
|
||||
|
||||
# 7. Compute user_level for template (max task permission across accessible projects)
|
||||
user_level = 0
|
||||
if not request.user.is_superuser:
|
||||
user_level = UserGroup.objects.filter(
|
||||
is_deleted=False,
|
||||
username=request.user,
|
||||
group_id__in=ObjectAssignment.objects.filter(
|
||||
is_deleted=False,
|
||||
project_id__in=accessible_project_ids,
|
||||
).values('group_id')
|
||||
).aggregate(Max("permission_set__task"))["permission_set__task__max"] or 0
|
||||
|
||||
# 8. Context
|
||||
context = {
|
||||
"nearbeach_title": "All Tasks",
|
||||
"tasks": page_obj, # paginated queryset
|
||||
"user_level": user_level,
|
||||
"user_group_permissions": get_user_group_permission(request.user, ["task"]),
|
||||
"filter_form": filter_form,
|
||||
"theme": get_theme(request),
|
||||
}
|
||||
return render(request, "NearBeach/tasks/task_list.html", context)
|
||||
```
|
||||
|
||||
### 5.2 URL Route
|
||||
|
||||
```python
|
||||
# NearBeach/urls.py
|
||||
path("tasks/", views.task_list, name="task_list"),
|
||||
```
|
||||
|
||||
### 5.3 Template Variables Available
|
||||
|
||||
| Variable | Source | Use |
|
||||
|----------|--------|-----|
|
||||
| `tasks` | Paginated queryset | Main table rows |
|
||||
| `user_level` | Computed (max permission) | Show/hide edit/create buttons |
|
||||
| `user_group_permissions` | `get_user_group_permission()` JSON | Fine-grained UI permissions |
|
||||
| `filter_form` | `TaskFilterForm` | Filter sidebar |
|
||||
| `theme` | `get_theme(request)` | UI theming |
|
||||
|
||||
---
|
||||
|
||||
## 6. Template Permission Patterns
|
||||
|
||||
### 6.1 Conditional UI (Buttons, Links)
|
||||
|
||||
```html
|
||||
<!-- NearBeach/templates/NearBeach/tasks/task_list.html -->
|
||||
{% if user_level >= 3 %}
|
||||
<a href="{% url 'new_task' %}" class="btn btn-primary">+ New Task</a>
|
||||
{% endif %}
|
||||
|
||||
{% for task in tasks %}
|
||||
<tr>
|
||||
<td>{{ task.task_short_description }}</td>
|
||||
<td>{{ task.get_task_status_display }}</td>
|
||||
{% if user_level >= 2 %}
|
||||
<td><a href="{% url 'task_information' task.task_id %}">Edit</a></td>
|
||||
{% else %}
|
||||
<td>—</td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
```
|
||||
|
||||
### 6.2 Using `user_group_permissions` JSON (Advanced)
|
||||
|
||||
```html
|
||||
<script>
|
||||
const userPerms = {{ user_group_permissions|safe }};
|
||||
// userPerms = [{group_id: 1, group_name: "PMs", object_type: "task", object_permission_value: 3}, ...]
|
||||
const maxTaskPerm = Math.max(...userPerms.filter(p => p.object_type === "task").map(p => p.object_permission_value));
|
||||
if (maxTaskPerm >= 3) { /* show create button */ }
|
||||
</script>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. Testing Permissions
|
||||
|
||||
### 7.1 Required Test Cases (per task brief)
|
||||
|
||||
```python
|
||||
# NearBeach/tests/tests_views/tests_task/test_task_list_permissions.py
|
||||
class TaskListPermissionTests(TestCase):
|
||||
def setUp(self):
|
||||
self.admin = User.objects.create_superuser("admin", "a@b.com", "pass")
|
||||
self.user1 = User.objects.create_user("u1", "u1@b.com", "pass")
|
||||
self.user2 = User.objects.create_user("u2", "u2@b.com", "pass")
|
||||
self.group1 = Group.objects.create(group_name="Project Alpha Team")
|
||||
self.group2 = Group.objects.create(group_name="Project Beta Team")
|
||||
UserGroup.objects.create(username=self.user1, group=self.group1, permission_set=PermissionSet.objects.create(task=2))
|
||||
UserGroup.objects.create(username=self.user2, group=self.group2, permission_set=PermissionSet.objects.create(task=1))
|
||||
self.project_alpha = Project.objects.create(project_name="Alpha", ...)
|
||||
self.project_beta = Project.objects.create(project_name="Beta", ...)
|
||||
ObjectAssignment.objects.create(group=self.group1, project=self.project_alpha)
|
||||
ObjectAssignment.objects.create(group=self.group2, project=self.project_beta)
|
||||
self.task_alpha = Task.objects.create(project=self.project_alpha, ...)
|
||||
self.task_beta = Task.objects.create(project=self.project_beta, ...)
|
||||
|
||||
def test_user1_sees_only_alpha_tasks(self):
|
||||
self.client.force_login(self.user1)
|
||||
response = self.client.get("/tasks/")
|
||||
self.assertContains(response, self.task_alpha.task_short_description)
|
||||
self.assertNotContains(response, self.task_beta.task_short_description)
|
||||
|
||||
def test_user2_sees_only_beta_tasks(self):
|
||||
self.client.force_login(self.user2)
|
||||
response = self.client.get("/tasks/")
|
||||
self.assertContains(response, self.task_beta.task_short_description)
|
||||
self.assertNotContains(response, self.task_alpha.task_short_description)
|
||||
|
||||
def test_admin_sees_all_tasks(self):
|
||||
self.client.force_login(self.admin)
|
||||
response = self.client.get("/tasks/")
|
||||
self.assertContains(response, self.task_alpha.task_short_description)
|
||||
self.assertContains(response, self.task_beta.task_short_description)
|
||||
|
||||
def test_user_without_group_sees_no_tasks(self):
|
||||
user3 = User.objects.create_user("u3", "u3@b.com", "pass")
|
||||
self.client.force_login(user3)
|
||||
response = self.client.get("/tasks/")
|
||||
self.assertNotContains(response, self.task_alpha.task_short_description)
|
||||
self.assertNotContains(response, self.task_beta.task_short_description)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 8. Common Pitfalls to Avoid
|
||||
|
||||
| ❌ Wrong | ✅ Correct |
|
||||
|----------|------------|
|
||||
| Filter in template with `{% if %}` | Filter in **queryset** |
|
||||
| Use `assigned_user=request.user` for list views | Use `group_id__in=UserGroup.objects.filter(username=request.user)` |
|
||||
| Apply decorator `@check_specific_object_permissions` to list view | Use `@login_required` only + manual queryset filter |
|
||||
| Forget `is_deleted=False` on all queries | Always include `is_deleted=False` |
|
||||
| Skip superuser bypass | `if request.user.is_superuser: qs = Model.objects.filter(is_deleted=False)` |
|
||||
| Use `values()` before permission filter | Filter first, then `values()` for serialization |
|
||||
|
||||
---
|
||||
|
||||
## 9. Files to Modify for Task List
|
||||
|
||||
| File | Change |
|
||||
|------|--------|
|
||||
| `NearBeach/views/task_views.py` | Add `task_list(request)` function |
|
||||
| `NearBeach/urls.py` | Add `path("tasks/", views.task_list, name="task_list")` |
|
||||
| `NearBeach/forms.py` | Add `TaskFilterForm` |
|
||||
| `NearBeach/templates/NearBeach/tasks/task_list.html` | New template (filter sidebar + table + pagination) |
|
||||
| `NearBeach/tests/tests_views/tests_task/` | New test files (10+ tests) |
|
||||
|
||||
---
|
||||
|
||||
## 10. Quick Reference: Query Patterns
|
||||
|
||||
```python
|
||||
# User's groups
|
||||
UserGroup.objects.filter(is_deleted=False, username=request.user).values('group_id')
|
||||
|
||||
# Project access via groups
|
||||
ObjectAssignment.objects.filter(
|
||||
is_deleted=False,
|
||||
group_id__in=user_groups,
|
||||
project_id__isnull=False
|
||||
).values_list('project_id', flat=True).distinct()
|
||||
|
||||
# Task queryset with permission filter
|
||||
Task.objects.filter(
|
||||
is_deleted=False,
|
||||
project_id__in=accessible_project_ids,
|
||||
)
|
||||
|
||||
# Superuser bypass
|
||||
if request.user.is_superuser:
|
||||
qs = Model.objects.filter(is_deleted=False)
|
||||
else:
|
||||
qs = Model.objects.filter(is_deleted=False, project_id__in=accessible_project_ids)
|
||||
|
||||
# Max permission level for template
|
||||
user_level = UserGroup.objects.filter(
|
||||
is_deleted=False,
|
||||
username=request.user,
|
||||
group_id__in=ObjectAssignment.objects.filter(
|
||||
is_deleted=False, project_id__in=accessible_project_ids
|
||||
).values('group_id')
|
||||
).aggregate(Max("permission_set__task"))["permission_set__task__max"] or 0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 11. Summary for LiveCompare Session
|
||||
|
||||
**Tell the model in your first message:**
|
||||
|
||||
> "Build a task list at `/tasks/` with filtering, sorting, pagination.
|
||||
>
|
||||
> **Permissions**: Use the existing `ObjectAssignment` group-based system. Filter the queryset by projects the user has access to via their groups (same pattern as `sprint_list` in `sprint_views.py`). Superusers see all. No permission decorator on the list view — just `@login_required`. Pass `user_level` (max task permission across accessible projects) and `user_group_permissions` JSON to template for UI decisions.
|
||||
>
|
||||
> **Reference implementations**: `sprint_list` (project/requirement access), `get_kanban_list` (kanban board access), `get_unassigned_objects` (permission level check via `permission_set__task__gt=0`).
|
||||
>
|
||||
> **Tests**: 10+ tests covering filter/sort/pagination + permission enforcement (create second user without project access, verify they can't see those tasks)."
|
||||
64
sources/selected-task-20251029.md
Normal file
64
sources/selected-task-20251029.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Selected Task for LiveCompare
|
||||
|
||||
## User Selection
|
||||
- **Chosen**: Task List View with Filtering, Sorting, and Pagination
|
||||
- **Score**: 25/25
|
||||
- **Selection Date**: 2025-10-29
|
||||
- **User Notes**: No modifications - use Task Brief as-is
|
||||
|
||||
## Complete Task Brief (Ready for LiveCompare)
|
||||
|
||||
### Task Description
|
||||
NearBeach has task detail views (`task_information`) and task creation (`new_task`), but **no general task list view** for users to see all their tasks across projects. Users must navigate through individual projects or kanban boards to find tasks, which is inefficient for project managers overseeing multiple projects. A dedicated task list with filtering, sorting, and pagination is a standard project management feature that would significantly improve task discoverability and workflow.
|
||||
|
||||
### How to Judge Completion
|
||||
In the repo folder, run the NearBeach start commands:
|
||||
```bash
|
||||
cd /workspace/nearbeach
|
||||
python3 -m pip install --user --break-system-packages -r requirements.txt
|
||||
python3 manage.py migrate
|
||||
DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_EMAIL=admin@example.com DJANGO_SUPERUSER_PASSWORD=password python3 manage.py createsuperuser --noinput
|
||||
python3 manage.py runserver 0.0.0.0:8000
|
||||
```
|
||||
Then open `http://localhost:8000` and log in as `admin` / `password`.
|
||||
|
||||
**Verification steps:**
|
||||
1. Navigate to `/tasks/` (new URL) - should display a paginated table of all tasks the user has permission to view
|
||||
2. Test filtering: select a status from dropdown → table updates to show only tasks with that status
|
||||
3. Test filtering: select an assignee → shows only tasks assigned to that user
|
||||
4. Test filtering: select a project → shows only tasks in that project
|
||||
5. Test filtering: enter date range for start/end dates → shows only tasks in range
|
||||
6. Test sorting: click column headers (Created, Start Date, End Date, Priority, Status, Project) → toggles asc/desc
|
||||
7. Test pagination: page size selector (10, 25, 50, 100) and page navigation work
|
||||
8. Run `python3 manage.py test NearBeach.tests.tests_views.tests_task` - should pass with 10+ new tests covering filtering, sorting, pagination, and permissions
|
||||
9. Verify permission enforcement: create a second user without access to a project, log in as that user, verify they cannot see tasks from that project
|
||||
|
||||
### Other Notes for Reviewer
|
||||
NearBeach is an open-source Django/Vue project management tool for tracking requirements, projects, tasks, kanban boards, sprints, and RFCs. It's used by small teams to enterprises. The missing task list view is a significant UX gap - users currently have no central place to view all their tasks across projects. This task adds a core feature that project managers would expect, improving daily workflow for anyone managing multiple projects. The implementation touches Django views, templates, URL routing, the existing permission system (group-based via ObjectAssignment), and requires comprehensive tests to ensure permission filtering works correctly.
|
||||
|
||||
### Practical Details
|
||||
- **Setup Commands**:
|
||||
```bash
|
||||
cd /workspace/nearbeach
|
||||
python3 -m pip install --user --break-system-packages -r requirements.txt
|
||||
python3 manage.py migrate
|
||||
DJANGO_SUPERUSER_USERNAME=admin DJANGO_SUPERUSER_EMAIL=admin@example.com DJANGO_SUPERUSER_PASSWORD=password python3 manage.py createsuperuser --noinput
|
||||
python3 manage.py runserver 0.0.0.0:8000
|
||||
```
|
||||
- **Key Files Likely Involved**:
|
||||
- `NearBeach/views/task_views.py` - new `task_list` view function
|
||||
- `NearBeach/urls.py` - new route for `/tasks/`
|
||||
- `NearBeach/templates/NearBeach/tasks/task_list.html` - new template with filter sidebar, table, pagination
|
||||
- `NearBeach/forms.py` - new `TaskFilterForm` for filter validation
|
||||
- `NearBeach/tests/tests_views/tests_task/` - new test files
|
||||
- **Potential Challenges**:
|
||||
- Permission filtering must respect existing `ObjectAssignment` group-based system
|
||||
- Filter combinations (status + assignee + project + date range) need efficient queryset construction
|
||||
- Vue frontend may need updates if task list integrates with existing UI patterns
|
||||
|
||||
## Next Steps for User
|
||||
1. Copy the Task Brief above into LiveCompare (Task Description, How to Judge Completion, Other Notes for Reviewer)
|
||||
2. Download the NearBeach repo zip from the approved repos table in project-rules.md
|
||||
3. Mount the archive in LiveCompare before your first message
|
||||
4. Use the File Source URL: `https://github.com/nearbeach/NearBeach`
|
||||
5. Start the conversation with the model using the Task Description as your first message
|
||||
312
sources/task-list-wireframe.html
Normal file
312
sources/task-list-wireframe.html
Normal file
@@ -0,0 +1,312 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>NearBeach - Task List View Wireframe</title>
|
||||
<style>
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
|
||||
body { background: #f5f6f8; min-height: 100vh; padding: 20px; }
|
||||
.container { max-width: 1400px; margin: 0 auto; background: white; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); overflow: hidden; }
|
||||
|
||||
/* Header */
|
||||
.header { padding: 20px 24px; border-bottom: 1px solid #e1e4e8; display: flex; justify-content: space-between; align-items: center; }
|
||||
.header h1 { font-size: 1.5rem; font-weight: 600; color: #24292e; }
|
||||
.btn { padding: 8px 16px; border-radius: 6px; font-size: 0.875rem; font-weight: 500; cursor: pointer; border: none; transition: all 0.15s; }
|
||||
.btn-primary { background: #0366d6; color: white; }
|
||||
.btn-primary:hover { background: #0256c7; }
|
||||
.btn-secondary { background: #fafbfc; color: #24292e; border: 1px solid #e1e4e8; }
|
||||
.btn-secondary:hover { background: #f3f4f6; }
|
||||
|
||||
/* Main Layout */
|
||||
.main { display: flex; min-height: 600px; }
|
||||
|
||||
/* Filter Sidebar */
|
||||
.sidebar { width: 280px; border-right: 1px solid #e1e4e8; padding: 20px; background: #fafbfc; overflow-y: auto; }
|
||||
.filter-section { margin-bottom: 24px; }
|
||||
.filter-section h3 { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: #586069; margin-bottom: 12px; }
|
||||
.form-group { margin-bottom: 16px; }
|
||||
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; color: #24292e; margin-bottom: 6px; }
|
||||
.form-control { width: 100%; padding: 8px 12px; border: 1px solid #e1e4e8; border-radius: 6px; font-size: 0.875rem; background: white; }
|
||||
.form-control:focus { outline: none; border-color: #0366d6; box-shadow: 0 0 0 3px rgba(3,102,214,0.15); }
|
||||
.checkbox-group { display: flex; flex-direction: column; gap: 8px; }
|
||||
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; color: #24292e; cursor: pointer; }
|
||||
.checkbox-label input { width: 16px; height: 16px; accent-color: #0366d6; }
|
||||
.date-range { display: flex; gap: 8px; }
|
||||
.date-range .form-control { flex: 1; }
|
||||
.filter-actions { display: flex; gap: 8px; margin-top: 24px; padding-top: 16px; border-top: 1px solid #e1e4e8; }
|
||||
|
||||
/* Table Area */
|
||||
.table-area { flex: 1; padding: 20px 24px; overflow-x: auto; }
|
||||
.table-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
|
||||
.results-info { font-size: 0.875rem; color: #586069; }
|
||||
.page-size select { padding: 6px 10px; border: 1px solid #e1e4e8; border-radius: 6px; font-size: 0.875rem; background: white; }
|
||||
|
||||
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
|
||||
th { text-align: left; padding: 12px 16px; font-weight: 600; color: #586069; background: #fafbfc; border-bottom: 1px solid #e1e4e8; white-space: nowrap; cursor: pointer; user-select: none; transition: background 0.15s; }
|
||||
th:hover { background: #f3f4f6; }
|
||||
th.sorted-asc::after { content: " ▲"; font-size: 0.7rem; color: #0366d6; }
|
||||
th.sorted-desc::after { content: " ▼"; font-size: 0.7rem; color: #0366d6; }
|
||||
td { padding: 12px 16px; border-bottom: 1px solid #e1e4e8; color: #24292e; vertical-align: middle; }
|
||||
tr:hover td { background: #fafbfc; }
|
||||
|
||||
/* Status Badges */
|
||||
.badge { display: inline-block; padding: 3px 8px; border-radius: 12px; font-size: 0.75rem; font-weight: 500; text-transform: capitalize; }
|
||||
.badge-todo { background: #fff3cd; color: #856404; }
|
||||
.badge-in-progress { background: #cce5ff; color: #004085; }
|
||||
.badge-review { background: #e2d9f3; color: #5a32a3; }
|
||||
.badge-done { background: #d4edda; color: #155724; }
|
||||
.badge-blocked { background: #f8d7da; color: #721c24; }
|
||||
|
||||
/* Priority */
|
||||
.priority { display: inline-flex; align-items: center; gap: 4px; font-size: 0.8125rem; font-weight: 500; }
|
||||
.priority-high { color: #cb2431; }
|
||||
.priority-medium { color: #e67e22; }
|
||||
.priority-low { color: #28a745; }
|
||||
.priority-indicator { width: 8px; height: 8px; border-radius: 50%; }
|
||||
.priority-high .priority-indicator { background: #cb2431; }
|
||||
.priority-medium .priority-indicator { background: #e67e22; }
|
||||
.priority-low .priority-indicator { background: #28a745; }
|
||||
|
||||
/* Pagination */
|
||||
.pagination { display: flex; justify-content: center; align-items: center; gap: 4px; margin-top: 20px; padding-top: 16px; border-top: 1px solid #e1e4e8; }
|
||||
.pagination button { min-width: 36px; height: 36px; padding: 0 12px; border: 1px solid #e1e4e8; background: white; border-radius: 6px; font-size: 0.875rem; color: #24292e; cursor: pointer; transition: all 0.15s; }
|
||||
.pagination button:hover:not(:disabled) { background: #f3f4f6; border-color: #d1d5da; }
|
||||
.pagination button.active { background: #0366d6; color: white; border-color: #0366d6; }
|
||||
.pagination button:disabled { opacity: 0.5; cursor: not-allowed; }
|
||||
.pagination .ellipsis { padding: 0 8px; color: #586069; }
|
||||
|
||||
/* Empty State */
|
||||
.empty-state { text-align: center; padding: 60px 20px; color: #586069; }
|
||||
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.5; }
|
||||
.empty-state h3 { font-size: 1.125rem; font-weight: 600; color: #24292e; margin-bottom: 8px; }
|
||||
|
||||
/* Responsive */
|
||||
@media (max-width: 1024px) {
|
||||
.main { flex-direction: column; }
|
||||
.sidebar { width: 100%; border-right: none; border-bottom: 1px solid #e1e4e8; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<!-- Header -->
|
||||
<header class="header">
|
||||
<h1>All Tasks</h1>
|
||||
<button class="btn btn-primary">+ New Task</button>
|
||||
</header>
|
||||
|
||||
<!-- Main Content -->
|
||||
<div class="main">
|
||||
<!-- Filter Sidebar -->
|
||||
<aside class="sidebar">
|
||||
<div class="filter-section">
|
||||
<h3>Status</h3>
|
||||
<div class="checkbox-group">
|
||||
<label class="checkbox-label"><input type="checkbox" name="status" value="todo"> To Do</label>
|
||||
<label class="checkbox-label"><input type="checkbox" name="status" value="in_progress"> In Progress</label>
|
||||
<label class="checkbox-label"><input type="checkbox" name="status" value="review"> In Review</label>
|
||||
<label class="checkbox-label"><input type="checkbox" name="status" value="done"> Done</label>
|
||||
<label class="checkbox-label"><input type="checkbox" name="status" value="blocked"> Blocked</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="filter-section">
|
||||
<h3>Assignee</h3>
|
||||
<select class="form-control" id="assignee-filter">
|
||||
<option value="">All Assignees</option>
|
||||
<option value="1">Alex Johnson</option>
|
||||
<option value="2">Sam Chen</option>
|
||||
<option value="3">Maria Rodriguez</option>
|
||||
<option value="4">James Wilson</option>
|
||||
<option value="unassigned">Unassigned</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="filter-section">
|
||||
<h3>Project</h3>
|
||||
<select class="form-control" id="project-filter">
|
||||
<option value="">All Projects</option>
|
||||
<option value="1">Website Redesign</option>
|
||||
<option value="2">API v2 Migration</option>
|
||||
<option value="3">Mobile App Launch</option>
|
||||
<option value="4">Security Audit</option>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="filter-section">
|
||||
<h3>Date Range</h3>
|
||||
<div class="form-group">
|
||||
<label>Start Date</label>
|
||||
<div class="date-range">
|
||||
<input type="date" class="form-control" id="start-date">
|
||||
<input type="date" class="form-control" id="end-date">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="filter-actions">
|
||||
<button class="btn btn-secondary" style="flex: 1">Clear Filters</button>
|
||||
<button class="btn btn-primary" style="flex: 1">Apply</button>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<!-- Task Table -->
|
||||
<section class="table-area">
|
||||
<div class="table-header">
|
||||
<span class="results-info">Showing 1–25 of 142 tasks</span>
|
||||
<div class="page-size">
|
||||
<select id="page-size">
|
||||
<option value="10">10 per page</option>
|
||||
<option value="25" selected>25 per page</option>
|
||||
<option value="50">50 per page</option>
|
||||
<option value="100">100 per page</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<table id="task-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-sort="title">Title</th>
|
||||
<th data-sort="status">Status</th>
|
||||
<th data-sort="priority">Priority</th>
|
||||
<th data-sort="assignee">Assignee</th>
|
||||
<th data-sort="project">Project</th>
|
||||
<th data-sort="start_date">Start Date</th>
|
||||
<th data-sort="end_date">End Date</th>
|
||||
<th data-sort="created">Created</th>
|
||||
<th style="width: 60px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><strong>Design new dashboard layout</strong><br><span style="font-size:0.75rem;color:#586069">#T-1247</span></td>
|
||||
<td><span class="badge badge-in-progress">In Progress</span></td>
|
||||
<td><span class="priority priority-high"><span class="priority-indicator"></span>High</span></td>
|
||||
<td>Alex Johnson</td>
|
||||
<td>Website Redesign</td>
|
||||
<td>2025-10-15</td>
|
||||
<td>2025-11-01</td>
|
||||
<td>2025-10-10</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Implement JWT authentication</strong><br><span style="font-size:0.75rem;color:#586069">#T-1245</span></td>
|
||||
<td><span class="badge badge-todo">To Do</span></td>
|
||||
<td><span class="priority priority-high"><span class="priority-indicator"></span>High</span></td>
|
||||
<td>Sam Chen</td>
|
||||
<td>API v2 Migration</td>
|
||||
<td>2025-10-20</td>
|
||||
<td>2025-10-30</td>
|
||||
<td>2025-10-12</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Write API documentation</strong><br><span style="font-size:0.75rem;color:#586069">#T-1242</span></td>
|
||||
<td><span class="badge badge-review">In Review</span></td>
|
||||
<td><span class="priority priority-medium"><span class="priority-indicator"></span>Medium</span></td>
|
||||
<td>Maria Rodriguez</td>
|
||||
<td>API v2 Migration</td>
|
||||
<td>2025-10-01</td>
|
||||
<td>2025-10-25</td>
|
||||
<td>2025-09-28</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Setup CI/CD pipeline</strong><br><span style="font-size:0.75rem;color:#586069">#T-1238</span></td>
|
||||
<td><span class="badge badge-done">Done</span></td>
|
||||
<td><span class="priority priority-medium"><span class="priority-indicator"></span>Medium</span></td>
|
||||
<td>James Wilson</td>
|
||||
<td>Mobile App Launch</td>
|
||||
<td>2025-09-15</td>
|
||||
<td>2025-10-05</td>
|
||||
<td>2025-09-10</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Fix memory leak in data processor</strong><br><span style="font-size:0.75rem;color:#586069">#T-1235</span></td>
|
||||
<td><span class="badge badge-blocked">Blocked</span></td>
|
||||
<td><span class="priority priority-high"><span class="priority-indicator"></span>High</span></td>
|
||||
<td>Alex Johnson</td>
|
||||
<td>Security Audit</td>
|
||||
<td>2025-10-05</td>
|
||||
<td>2025-10-20</td>
|
||||
<td>2025-10-01</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Create user onboarding flow</strong><br><span style="font-size:0.75rem;color:#586069">#T-1231</span></td>
|
||||
<td><span class="badge badge-todo">To Do</span></td>
|
||||
<td><span class="priority priority-low"><span class="priority-indicator"></span>Low</span></td>
|
||||
<td>—</td>
|
||||
<td>Website Redesign</td>
|
||||
<td>2025-11-01</td>
|
||||
<td>2025-11-15</td>
|
||||
<td>2025-10-18</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Performance audit for dashboard</strong><br><span style="font-size:0.75rem;color:#586069">#T-1228</span></td>
|
||||
<td><span class="badge badge-in-progress">In Progress</span></td>
|
||||
<td><span class="priority priority-medium"><span class="priority-indicator"></span>Medium</span></td>
|
||||
<td>Sam Chen</td>
|
||||
<td>Website Redesign</td>
|
||||
<td>2025-10-18</td>
|
||||
<td>2025-11-05</td>
|
||||
<td>2025-10-15</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Add dark mode support</strong><br><span style="font-size:0.75rem;color:#586069">#T-1224</span></td>
|
||||
<td><span class="badge badge-todo">To Do</span></td>
|
||||
<td><span class="priority priority-low"><span class="priority-indicator"></span>Low</span></td>
|
||||
<td>Maria Rodriguez</td>
|
||||
<td>Mobile App Launch</td>
|
||||
<td>2025-11-10</td>
|
||||
<td>2025-11-25</td>
|
||||
<td>2025-10-20</td>
|
||||
<td><button class="btn btn-secondary" style="padding:4px 8px;font-size:0.75rem">View</button></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<!-- Pagination -->
|
||||
<nav class="pagination" aria-label="Task pagination">
|
||||
<button disabled>« Previous</button>
|
||||
<button class="active">1</button>
|
||||
<button>2</button>
|
||||
<button>3</button>
|
||||
<button>4</button>
|
||||
<button>5</button>
|
||||
<span class="ellipsis">…</button>
|
||||
<button>6</button>
|
||||
<button>Next »</button>
|
||||
</nav>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Simple sort toggle demo
|
||||
document.querySelectorAll('th[data-sort]').forEach(th => {
|
||||
th.addEventListener('click', () => {
|
||||
document.querySelectorAll('th[data-sort]').forEach(other => {
|
||||
if (other !== th) other.classList.remove('sorted-asc', 'sorted-desc');
|
||||
});
|
||||
if (th.classList.contains('sorted-asc')) {
|
||||
th.classList.replace('sorted-asc', 'sorted-desc');
|
||||
} else {
|
||||
th.classList.add('sorted-asc');
|
||||
th.classList.remove('sorted-desc');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Page size change
|
||||
document.getElementById('page-size').addEventListener('change', (e) => {
|
||||
console.log('Page size changed to:', e.target.value);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
305
sources/tdd-task-list-plan.md
Normal file
305
sources/tdd-task-list-plan.md
Normal file
@@ -0,0 +1,305 @@
|
||||
# TDD Plan: Task List View with Filtering, Sorting, Pagination
|
||||
|
||||
*Use this in LiveCompare — each step = one test + implementation cycle*
|
||||
|
||||
---
|
||||
|
||||
## Test File Location
|
||||
```
|
||||
NearBeach/tests/tests_views/tests_task/test_task_list.py
|
||||
```
|
||||
|
||||
## Run Single Test Command
|
||||
```bash
|
||||
cd /workspace/nearbeach
|
||||
python3 manage.py test NearBeach.tests.tests_views.tests_task.test_task_list.TestTaskList.<test_method> -v 2
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## STEP 1: URL + Template Rendering
|
||||
|
||||
### TEST PROMPT (send to model)
|
||||
> Write a test `test_task_list_url_accessible` in `test_task_list.py` that:
|
||||
> - Creates a superuser
|
||||
> - Logs in the client
|
||||
> - GETs `/tasks/`
|
||||
> - Asserts status code 200
|
||||
> - Asserts template `NearBeach/tasks/task_list.html` is used
|
||||
> - Asserts "All Tasks" appears in response content
|
||||
>
|
||||
> Run it — it should FAIL (no view/URL/template exists yet).
|
||||
|
||||
### IMPL PROMPT (after test fails)
|
||||
> Implement the minimal code to make `test_task_list_url_accessible` pass:
|
||||
> 1. Add `task_list(request)` view in `NearBeach/views/task_views.py` with `@login_required`, returns render of `NearBeach/tasks/task_list.html` with context `{"nearbeach_title": "All Tasks"}`
|
||||
> 2. Add URL route `path("tasks/", views.task_list, name="task_list")` in `NearBeach/urls.py`
|
||||
> 3. Create minimal template `NearBeach/templates/NearBeach/tasks/task_list.html` extending base, showing "All Tasks" heading
|
||||
> 4. Run the test again — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 2: Permission Filtering (Core)
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_filters_by_user_projects`:
|
||||
> - Create two users: `user_alpha`, `user_beta`
|
||||
> - Create two groups: `group_alpha`, `group_beta` with `permission_set__task=2`
|
||||
> - Create two projects: `project_alpha`, `project_beta`
|
||||
> - Create `ObjectAssignment(group_alpha, project_alpha)` and `ObjectAssignment(group_beta, project_beta)`
|
||||
> - Create tasks: `task_alpha` in `project_alpha`, `task_beta` in `project_beta`
|
||||
> - Login as `user_alpha` → GET `/tasks/` → assert `task_alpha` in response, `task_beta` NOT in response
|
||||
> - Login as `user_beta` → GET `/tasks/` → assert `task_beta` in response, `task_alpha` NOT in response
|
||||
> - Login as superuser → GET `/tasks/` → assert BOTH tasks in response
|
||||
|
||||
### IMPL PROMPT
|
||||
> Update `task_list` view to filter tasks by user's project access via `ObjectAssignment`:
|
||||
> 1. Get user's groups: `UserGroup.objects.filter(is_deleted=False, username=request.user).values('group_id')`
|
||||
> 2. Get accessible project IDs: `ObjectAssignment.objects.filter(is_deleted=False, group_id__in=user_groups, project_id__isnull=False).values_list('project_id', flat=True).distinct()`
|
||||
> 3. If superuser: `Task.objects.filter(is_deleted=False)` else: `Task.objects.filter(is_deleted=False, project_id__in=accessible_project_ids)`
|
||||
> 4. Pass `tasks` queryset to template
|
||||
> 5. Update template to loop through `tasks` and display `task_short_description`
|
||||
> 6. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 3: Filter by Status
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_filter_by_status`:
|
||||
> - Setup: user with access to project, 3 tasks with different statuses (To Do, In Progress, Done)
|
||||
> - GET `/tasks/?status=in_progress` → assert only "In Progress" task shown
|
||||
> - GET `/tasks/?status=todo&status=done` → assert To Do and Done shown, In Progress hidden
|
||||
> - GET `/tasks/` (no filter) → assert all 3 shown
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add status filtering to `task_list` view:
|
||||
> 1. Create `TaskFilterForm` in `forms.py` with `status = forms.MultipleChoiceField(choices=ListOfTaskStatus.choices, required=False, widget=forms.CheckboxSelectMultiple)`
|
||||
> 2. In view: instantiate form with `request.GET`, if valid apply `tasks_qs = tasks_qs.filter(task_status__in=form.cleaned_data['status'])` when status provided
|
||||
> 3. Pass `filter_form` to template
|
||||
> 4. Update template: render status checkboxes in sidebar, preserve other filters in form action
|
||||
> 5. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 4: Filter by Assignee
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_filter_by_assignee`:
|
||||
> - Setup: user with project access, 2 assignees (user1, user2), 3 tasks (2 assigned to user1, 1 to user2, 1 unassigned)
|
||||
> - GET `/tasks/?assignee=user1_id` → assert only user1's tasks shown
|
||||
> - GET `/tasks/?assignee=unassigned` → assert only unassigned task shown
|
||||
> - GET `/tasks/?assignee=user1_id&assignee=unassigned` → assert both shown
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add assignee filtering:
|
||||
> 1. Add `assignee = forms.ChoiceField(choices=[("", "All Assignees"), ("unassigned", "Unassigned")] + dynamic user choices, required=False)` to `TaskFilterForm`
|
||||
> 2. In view: if `assignee == "unassigned"` → `tasks_qs.filter(assigned_user__isnull=True)`; elif assignee ID → `tasks_qs.filter(assigned_user_id=assignee)`
|
||||
> 3. Populate assignee choices from users in accessible projects (or all users)
|
||||
> 4. Update template: assignee dropdown in sidebar
|
||||
> 5. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 5: Filter by Project
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_filter_by_project`:
|
||||
> - Setup: user with access to 2 projects (project_a, project_b), tasks in each
|
||||
> - GET `/tasks/?project=project_a_id` → assert only project_a tasks shown
|
||||
> - GET `/tasks/?project=project_b_id` → assert only project_b tasks shown
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add project filtering:
|
||||
> 1. Add `project = forms.ChoiceField(choices=[("", "All Projects")] + dynamic project choices, required=False)` to `TaskFilterForm`
|
||||
> 2. In view: if project selected → `tasks_qs.filter(project_id=project)`
|
||||
> 3. Project choices = user's accessible projects (from Step 2 queryset)
|
||||
> 4. Update template: project dropdown in sidebar
|
||||
> 5. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 6: Filter by Date Range
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_filter_by_date_range`:
|
||||
> - Setup: tasks with start_date/end_date across October 2025
|
||||
> - GET `/tasks/?start_date=2025-10-15&end_date=2025-10-25` → assert only tasks with start_date >= 15th AND end_date <= 25th shown
|
||||
> - GET `/tasks/?start_date=2025-10-01` (only start) → assert tasks with start_date >= 1st
|
||||
> - GET `/tasks/?end_date=2025-10-31` (only end) → assert tasks with end_date <= 31st
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add date range filtering:
|
||||
> 1. Add `start_date = forms.DateField(required=False, widget=forms.DateInput(attrs={'type': 'date'}))` and `end_date` to `TaskFilterForm`
|
||||
> 2. In view: if start_date → `tasks_qs.filter(task_start_date__gte=start_date)`; if end_date → `tasks_qs.filter(task_end_date__lte=end_date)`
|
||||
> 3. Update template: two date inputs in sidebar
|
||||
> 4. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 7: Sorting by Column Headers
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_sorting`:
|
||||
> - Setup: 5 tasks with different created, start_date, end_date, priority, status, project
|
||||
> - GET `/tasks/?sort=created` → assert tasks ordered by created ASC
|
||||
> - GET `/tasks/?sort=-created` → assert tasks ordered by created DESC
|
||||
> - GET `/tasks/?sort=priority` → assert priority order (High > Medium > Low)
|
||||
> - GET `/tasks/?sort=project` → assert ordered by project name
|
||||
> - Verify toggle: clicking same column again reverses order
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add sorting:
|
||||
> 1. Add `sort = forms.ChoiceField(choices=[("created", "Created"), ("-created", "Created ↓"), ("start_date", "Start Date"), ("-start_date", "Start Date ↓"), ("end_date", "End Date"), ("-end_date", "End Date ↓"), ("priority", "Priority"), ("-priority", "Priority ↓"), ("status", "Status"), ("-status", "Status ↓"), ("project", "Project"), ("-project", "Project ↓")], required=False)` to form
|
||||
> 2. In view: parse sort param, apply `.order_by(sort_field)` to queryset
|
||||
> 3. For priority: custom ordering using `Case/When` (High=1, Medium=2, Low=3)
|
||||
> 4. Update template: table headers as links with `?sort=...` preserving other filters, show ▲/▼ indicator
|
||||
> 5. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 8: Pagination
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_pagination`:
|
||||
> - Setup: 50 tasks in user's project
|
||||
> - GET `/tasks/?page_size=10&page=1` → assert 10 tasks shown, page 1 active
|
||||
> - GET `/tasks/?page_size=10&page=3` → assert tasks 21-30 shown
|
||||
> - GET `/tasks/?page_size=25` → assert 25 tasks shown
|
||||
> - GET `/tasks/?page_size=100` → assert all 50 shown (single page)
|
||||
> - Verify page navigation links (prev/next, page numbers, ellipsis)
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add pagination:
|
||||
> 1. Add `page_size = forms.ChoiceField(choices=[(10, "10"), (25, "25"), (50, "50"), (100, "100")], required=False, initial=25)` to form
|
||||
> 2. In view: use `Paginator(tasks_qs, page_size)`, get `page_obj = paginator.get_page(page_number)`
|
||||
> 3. Pass `page_obj`, `paginator`, `page_size` to template
|
||||
> 4. Update template: pagination controls (prev/next, page numbers with ellipsis, page size selector)
|
||||
> 5. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 9: Combined Filters + Sort + Pagination
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_combined_filters_sort_pagination`:
|
||||
> - Setup: 100 tasks across 3 projects, various statuses, assignees, dates
|
||||
> - GET `/tasks/?status=in_progress&project=proj1_id&sort=-priority&page_size=10&page=2`
|
||||
> - Assert: only In Progress tasks from proj1, sorted by priority DESC, page 2 (items 11-20)
|
||||
|
||||
### IMPL PROMPT
|
||||
> Ensure all filters/sort/pagination work together:
|
||||
> 1. In view: apply filters → sort → paginate in that order
|
||||
> 2. Template: all filter/sort inputs in same `<form method="GET">`, pagination links preserve all query params
|
||||
> 3. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 10: UI Permissions (user_level, user_group_permissions)
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_ui_permissions`:
|
||||
> - Setup: user with task permission level 1 (read only), user with level 3 (create)
|
||||
> - Login as level 1 → GET `/tasks/` → assert "New Task" button NOT in response
|
||||
> - Login as level 3 → GET `/tasks/` → assert "New Task" button IS in response
|
||||
> - Verify `user_level` in context equals max permission_set__task across accessible projects
|
||||
|
||||
### IMPL PROMPT
|
||||
> Add permission context to template:
|
||||
> 1. In view: compute `user_level = UserGroup.objects.filter(...).aggregate(Max("permission_set__task"))["permission_set__task__max"] or 0`
|
||||
> 2. Pass `user_level` and `user_group_permissions = get_user_group_permission(request.user, ["task"])` to template
|
||||
> 3. Template: `{% if user_level >= 3 %}<a href="{% url 'new_task' %}">+ New Task</a>{% endif %}`
|
||||
> 4. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 11: Empty State + Edge Cases
|
||||
|
||||
### TEST PROMPT
|
||||
> Write test `test_task_list_edge_cases`:
|
||||
> - User with no project access → GET `/tasks/` → assert "No tasks found" message, 0 tasks
|
||||
> - Filter returns no results → assert "No tasks found"
|
||||
> - Invalid page number → redirects to last page
|
||||
> - Invalid sort param → defaults to created DESC
|
||||
|
||||
### IMPL PROMPT
|
||||
> Handle edge cases:
|
||||
> 1. Template: `{% empty %}` clause in task loop showing "No tasks found"
|
||||
> 2. View: `Paginator.get_page()` handles invalid pages gracefully
|
||||
> 3. View: validate sort param against allowed list, default to `-created`
|
||||
> 4. Run test — should PASS
|
||||
|
||||
---
|
||||
|
||||
## STEP 12: Full Test Suite Run
|
||||
|
||||
### FINAL VERIFICATION PROMPT
|
||||
> Run the complete test suite:
|
||||
> ```bash
|
||||
> python3 manage.py test NearBeach.tests.tests_views.tests_task -v 2
|
||||
> ```
|
||||
> Should report **10+ tests passing** covering all verification steps from the task brief.
|
||||
|
||||
---
|
||||
|
||||
## Quick Reference: Test Class Structure
|
||||
|
||||
```python
|
||||
# NearBeach/tests/tests_views/tests_task/test_task_list.py
|
||||
from django.test import TestCase, Client
|
||||
from django.urls import reverse
|
||||
from django.contrib.auth import get_user_model
|
||||
from NearBeach.models import *
|
||||
|
||||
class TestTaskList(TestCase):
|
||||
def setUp(self):
|
||||
# Common setup: users, groups, projects, ObjectAssignments, tasks
|
||||
pass
|
||||
|
||||
def test_task_list_url_accessible(self):
|
||||
pass # Step 1
|
||||
|
||||
def test_task_list_filters_by_user_projects(self):
|
||||
pass # Step 2
|
||||
|
||||
def test_task_list_filter_by_status(self):
|
||||
pass # Step 3
|
||||
|
||||
def test_task_list_filter_by_assignee(self):
|
||||
pass # Step 4
|
||||
|
||||
def test_task_list_filter_by_project(self):
|
||||
pass # Step 5
|
||||
|
||||
def test_task_list_filter_by_date_range(self):
|
||||
pass # Step 6
|
||||
|
||||
def test_task_list_sorting(self):
|
||||
pass # Step 7
|
||||
|
||||
def test_task_list_pagination(self):
|
||||
pass # Step 8
|
||||
|
||||
def test_task_list_combined_filters_sort_pagination(self):
|
||||
pass # Step 9
|
||||
|
||||
def test_task_list_ui_permissions(self):
|
||||
pass # Step 10
|
||||
|
||||
def test_task_list_edge_cases(self):
|
||||
pass # Step 11
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## LiveCompare Session Tips
|
||||
|
||||
1. **Send TEST PROMPT first** → model writes test
|
||||
2. **Run in Sandbox** → confirm FAIL
|
||||
3. **Send IMPL PROMPT** → model implements
|
||||
4. **Run in Sandbox** → confirm PASS
|
||||
5. **Commit/continue** to next step
|
||||
|
||||
If model writes buggy implementation → test fails → you say "Test still fails, here's the error: [paste error]" → model fixes.
|
||||
|
||||
This gives you **granular control** and **visible progress** at each step.
|
||||
Reference in New Issue
Block a user