05/16 Fix bugs 2

This commit is contained in:
Nguyen Ngo
2026-05-16 14:02:53 -04:00
parent 0675acb8ec
commit edd81f4c59
7 changed files with 104 additions and 6 deletions
+14 -5
View File
@@ -105,8 +105,16 @@ def list_issues():
query = Issue.query
if user.role == 'inspector':
# Inspectors see only issues assigned to them
query = query.filter(Issue.assigned_to == user.id)
# Inspectors see issues assigned to them OR issues they reported.
# The reported_by path covers issues created on the iPad that haven't
# been assigned yet (assigned_to is NULL until a director assigns them).
# Pre-phase18 rows with reported_by = NULL still surface via assigned_to.
query = query.filter(
db.or_(
Issue.assigned_to == user.id,
Issue.reported_by == user.id,
)
)
else:
# Broader roles: exclude resolved by default so the list stays manageable
status_filter = request.args.get('status')
@@ -204,6 +212,7 @@ def create_issue():
photo_path = data.get('photo_path') or None,
status = 'open',
reported_at = now_eastern(),
reported_by = user.id,
mobile_local_id = mobile_local_id,
)
db.session.add(issue)
@@ -264,7 +273,7 @@ def get_issue(issue_id):
if issue is None:
return api_error('Issue not found', 404)
if user.role == 'inspector' and issue.assigned_to != user.id:
if user.role == 'inspector' and issue.assigned_to != user.id and issue.reported_by != user.id:
return api_error('Access denied', 403)
return api_ok(_issue_payload(issue))
@@ -294,8 +303,8 @@ def update_issue_status(issue_id):
if issue is None:
return api_error('Issue not found', 404)
if user.role == 'inspector' and issue.assigned_to != user.id:
return api_error('Access denied — you can only update issues assigned to you', 403)
if user.role == 'inspector' and issue.assigned_to != user.id and issue.reported_by != user.id:
return api_error('Access denied — you can only update issues assigned to or reported by you', 403)
data = request.get_json(silent=True) or {}
new_status = (data.get('status') or '').strip().lower()