diff --git a/sources/Workflows.csv b/sources/Workflows.csv deleted file mode 100644 index 430ecc2f..00000000 --- a/sources/Workflows.csv +++ /dev/null @@ -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 diff --git a/sources/nearbeach-permissions-guide.md b/sources/nearbeach-permissions-guide.md new file mode 100644 index 00000000..0dd52be0 --- /dev/null +++ b/sources/nearbeach-permissions-guide.md @@ -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 + +{% if user_level >= 3 %} + + New Task +{% endif %} + +{% for task in tasks %} + + {{ task.task_short_description }} + {{ task.get_task_status_display }} + {% if user_level >= 2 %} + Edit + {% else %} + — + {% endif %} + +{% endfor %} +``` + +### 6.2 Using `user_group_permissions` JSON (Advanced) + +```html + +``` + +--- + +## 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)." \ No newline at end of file diff --git a/sources/selected-task-20251029.md b/sources/selected-task-20251029.md new file mode 100644 index 00000000..046314a6 --- /dev/null +++ b/sources/selected-task-20251029.md @@ -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 \ No newline at end of file diff --git a/sources/task-list-wireframe.html b/sources/task-list-wireframe.html new file mode 100644 index 00000000..50805662 --- /dev/null +++ b/sources/task-list-wireframe.html @@ -0,0 +1,312 @@ + + + + + + NearBeach - Task List View Wireframe + + + +
+ +
+

All Tasks

+ +
+ + +
+ + + + +
+
+ Showing 1–25 of 142 tasks +
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
TitleStatusPriorityAssigneeProjectStart DateEnd DateCreatedActions
Design new dashboard layout
#T-1247
In ProgressHighAlex JohnsonWebsite Redesign2025-10-152025-11-012025-10-10
Implement JWT authentication
#T-1245
To DoHighSam ChenAPI v2 Migration2025-10-202025-10-302025-10-12
Write API documentation
#T-1242
In ReviewMediumMaria RodriguezAPI v2 Migration2025-10-012025-10-252025-09-28
Setup CI/CD pipeline
#T-1238
DoneMediumJames WilsonMobile App Launch2025-09-152025-10-052025-09-10
Fix memory leak in data processor
#T-1235
BlockedHighAlex JohnsonSecurity Audit2025-10-052025-10-202025-10-01
Create user onboarding flow
#T-1231
To DoLow—Website Redesign2025-11-012025-11-152025-10-18
Performance audit for dashboard
#T-1228
In ProgressMediumSam ChenWebsite Redesign2025-10-182025-11-052025-10-15
Add dark mode support
#T-1224
To DoLowMaria RodriguezMobile App Launch2025-11-102025-11-252025-10-20
+ + + +
+
+
+ + + + \ No newline at end of file diff --git a/sources/tdd-task-list-plan.md b/sources/tdd-task-list-plan.md new file mode 100644 index 00000000..3f327b88 --- /dev/null +++ b/sources/tdd-task-list-plan.md @@ -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. -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 `
`, 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 %}+ New Task{% 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. \ No newline at end of file