05/06 Fix Issue's sla, and others
This commit is contained in:
+30
-3
@@ -210,8 +210,9 @@ def delete_user(user_id):
|
||||
return redirect(url_for('auth.list_users'))
|
||||
|
||||
# Guard: block deletion if user has related records that would orphan data
|
||||
# or violate FK constraints (inspections they conducted, issues assigned to them,
|
||||
# or templates they created).
|
||||
# or violate FK constraints. Issue.assigned_to and IssueComment.user_id carry
|
||||
# no ondelete clause, so MySQL defaults to RESTRICT — the DELETE would fail at
|
||||
# the DB level without these application-level checks and clear user-facing messages.
|
||||
if user.inspections.count() > 0:
|
||||
flash(
|
||||
f'Cannot delete "{user.username}" — they have existing inspection records. '
|
||||
@@ -220,6 +221,32 @@ def delete_user(user_id):
|
||||
)
|
||||
return redirect(url_for('auth.list_users'))
|
||||
|
||||
if user.assigned_issues.count() > 0:
|
||||
flash(
|
||||
f'Cannot delete "{user.username}" — they have issues assigned to them. '
|
||||
'Reassign or resolve those issues first, then deactivate the account.',
|
||||
'danger'
|
||||
)
|
||||
return redirect(url_for('auth.list_users'))
|
||||
|
||||
from app.models.issue import IssueComment
|
||||
if IssueComment.query.filter_by(user_id=user.id).count() > 0:
|
||||
flash(
|
||||
f'Cannot delete "{user.username}" — they have authored issue comments. '
|
||||
'Deactivate the account instead.',
|
||||
'danger'
|
||||
)
|
||||
return redirect(url_for('auth.list_users'))
|
||||
|
||||
from app.models.inspection import InspectionTemplate
|
||||
if InspectionTemplate.query.filter_by(created_by=user.id).count() > 0:
|
||||
flash(
|
||||
f'Cannot delete "{user.username}" — they have created inspection templates. '
|
||||
'Deactivate the account instead.',
|
||||
'danger'
|
||||
)
|
||||
return redirect(url_for('auth.list_users'))
|
||||
|
||||
username = user.username
|
||||
user_id = user.id
|
||||
db.session.delete(user)
|
||||
@@ -307,4 +334,4 @@ def notification_matrix():
|
||||
matrix_roles = MATRIX_ROLES,
|
||||
defaults = MATRIX_DEFAULTS,
|
||||
state = state,
|
||||
)
|
||||
)
|
||||
@@ -196,6 +196,12 @@ def view(issue_id):
|
||||
issue.sla_notified = None # clear so alerts fire again if re-opened
|
||||
elif form.status.data != 'resolved':
|
||||
issue.resolved_at = None
|
||||
# Reset SLA notification state whenever re-opening from resolved so
|
||||
# the SLA cron re-evaluates from scratch and fires fresh alerts.
|
||||
# Without this, sla_notified retains its previous 'at_risk'/'breached'
|
||||
# value and the cron skips the issue indefinitely.
|
||||
if old_status == 'resolved':
|
||||
issue.sla_notified = None
|
||||
|
||||
issue.result_notes = form.result_notes.data or None
|
||||
|
||||
@@ -552,8 +558,8 @@ def request_verification(issue_id):
|
||||
flash('Access denied.', 'danger')
|
||||
return redirect(url_for('issues.view', issue_id=issue_id))
|
||||
|
||||
if issue.status not in ('in_progress', 'resolved'):
|
||||
flash('Issue must be in progress or resolved to request verification.', 'warning')
|
||||
if issue.status not in ('in_progress',):
|
||||
flash('Issue must be in progress to request verification.', 'warning')
|
||||
return redirect(url_for('issues.view', issue_id=issue_id))
|
||||
|
||||
issue.status = 'pending_verification'
|
||||
|
||||
Reference in New Issue
Block a user