feat: Add admin notifications when user accepts/rejects changes
- Create notification for all admins when user accepts proposed changes - Create notification for all admins when user rejects proposed changes - Clear proposed_changes fields after user decision - Include rejection reason in admin notification Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
17eaa25805
commit
8a8d39632f
@ -12,7 +12,7 @@ from flask import render_template, request, redirect, url_for, flash, jsonify
|
||||
from flask_login import login_required, current_user
|
||||
|
||||
from . import bp
|
||||
from database import SessionLocal, MembershipApplication, CompanyDataRequest, Company
|
||||
from database import SessionLocal, MembershipApplication, CompanyDataRequest, Company, UserNotification, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -336,6 +336,25 @@ def accept_changes(app_id):
|
||||
application.status = 'under_review'
|
||||
application.updated_at = datetime.now()
|
||||
|
||||
# Clear proposed changes (they've been applied)
|
||||
application.proposed_changes = None
|
||||
application.proposed_changes_at = None
|
||||
application.proposed_changes_comment = None
|
||||
|
||||
# Create notification for admins
|
||||
admins = db.query(User).filter(User.is_admin == True).all()
|
||||
for admin in admins:
|
||||
notification = UserNotification(
|
||||
user_id=admin.id,
|
||||
title='Użytkownik zaakceptował zmiany',
|
||||
message=f'Użytkownik {current_user.name or current_user.email} zaakceptował proponowane zmiany dla firmy "{application.company_name}". Deklaracja oczekuje na ostateczne zatwierdzenie.',
|
||||
notification_type='alert',
|
||||
related_type='membership_application',
|
||||
related_id=app_id,
|
||||
action_url=f'/admin/membership/{app_id}'
|
||||
)
|
||||
db.add(notification)
|
||||
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
@ -386,6 +405,7 @@ def reject_changes(app_id):
|
||||
application.proposed_changes = None
|
||||
application.proposed_changes_at = None
|
||||
application.proposed_changes_by_id = None
|
||||
application.proposed_changes_comment = None
|
||||
|
||||
# Add user's rejection reason to review_comment
|
||||
if user_comment:
|
||||
@ -396,6 +416,20 @@ def reject_changes(app_id):
|
||||
application.status = 'under_review'
|
||||
application.updated_at = datetime.now()
|
||||
|
||||
# Create notification for admins
|
||||
admins = db.query(User).filter(User.is_admin == True).all()
|
||||
for admin in admins:
|
||||
notification = UserNotification(
|
||||
user_id=admin.id,
|
||||
title='Użytkownik odrzucił zmiany',
|
||||
message=f'Użytkownik {current_user.name or current_user.email} odrzucił proponowane zmiany dla firmy "{application.company_name}".{" Powód: " + user_comment if user_comment else ""} Deklaracja wraca do rozpatrzenia z oryginalnymi danymi.',
|
||||
notification_type='alert',
|
||||
related_type='membership_application',
|
||||
related_id=app_id,
|
||||
action_url=f'/admin/membership/{app_id}'
|
||||
)
|
||||
db.add(notification)
|
||||
|
||||
db.commit()
|
||||
|
||||
logger.info(
|
||||
|
||||
Loading…
Reference in New Issue
Block a user