06/22 Fix Director notification issue
This commit is contained in:
+47
-23
@@ -103,32 +103,56 @@ def create_app(config_name='default'):
|
|||||||
|
|
||||||
@app.context_processor
|
@app.context_processor
|
||||||
def inject_notification_count():
|
def inject_notification_count():
|
||||||
|
if not current_user.is_authenticated:
|
||||||
|
return {
|
||||||
|
'unread_notification_count': 0,
|
||||||
|
'pending_verification_count': 0,
|
||||||
|
'open_support_tickets_count': 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
# ── Unread notification count (all roles) ──────────────────────────
|
||||||
|
# Computed first, in its own try/except, so a failure in the
|
||||||
|
# director-specific queries below never zeroes out the bell badge.
|
||||||
try:
|
try:
|
||||||
if current_user.is_authenticated:
|
from app.models.notification import Notification
|
||||||
from app.models.notification import Notification
|
unread = Notification.query.filter_by(
|
||||||
|
user_id=current_user.id, is_read=False
|
||||||
|
).count()
|
||||||
|
except Exception as exc:
|
||||||
|
import logging as _logging
|
||||||
|
_logging.getLogger(__name__).warning(
|
||||||
|
'inject_notification_count: unread query failed: %s', exc
|
||||||
|
)
|
||||||
|
unread = 0
|
||||||
|
|
||||||
|
# ── Director/admin-only counts ─────────────────────────────────────
|
||||||
|
pv_count = 0
|
||||||
|
open_support = 0
|
||||||
|
if current_user.role in ('admin', 'director'):
|
||||||
|
try:
|
||||||
from app.models.issue import Issue
|
from app.models.issue import Issue
|
||||||
unread = Notification.query.filter_by(
|
pv_count = Issue.query.filter_by(
|
||||||
user_id=current_user.id, is_read=False
|
status='pending_verification'
|
||||||
).count()
|
).count()
|
||||||
# Pending verification count — only computed for director+ roles
|
except Exception as exc:
|
||||||
pv_count = 0
|
import logging as _logging
|
||||||
if current_user.role in ('admin', 'director'):
|
_logging.getLogger(__name__).warning(
|
||||||
pv_count = Issue.query.filter_by(
|
'inject_notification_count: pv_count query failed: %s', exc
|
||||||
status='pending_verification'
|
)
|
||||||
).count()
|
try:
|
||||||
# Open support tickets — admin/director only
|
from app.models.support import SupportTicket
|
||||||
open_support = 0
|
open_support = SupportTicket.query.filter_by(status='open').count()
|
||||||
if current_user.role in ('admin', 'director'):
|
except Exception as exc:
|
||||||
from app.models.support import SupportTicket
|
import logging as _logging
|
||||||
open_support = SupportTicket.query.filter_by(status='open').count()
|
_logging.getLogger(__name__).warning(
|
||||||
return {
|
'inject_notification_count: support_tickets query failed: %s', exc
|
||||||
'unread_notification_count': unread,
|
)
|
||||||
'pending_verification_count': pv_count,
|
|
||||||
'open_support_tickets_count': open_support,
|
return {
|
||||||
}
|
'unread_notification_count': unread,
|
||||||
except Exception:
|
'pending_verification_count': pv_count,
|
||||||
pass
|
'open_support_tickets_count': open_support,
|
||||||
return {'unread_notification_count': 0, 'pending_verification_count': 0, 'open_support_tickets_count': 0}
|
}
|
||||||
|
|
||||||
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user