added events to event system
This commit is contained in:
@@ -5,10 +5,11 @@ from forms import UserForm
|
||||
from flask import abort
|
||||
from sqlalchemy import or_
|
||||
from routes.auth import require_password_change
|
||||
from utils import log_event
|
||||
from utils import log_event, create_notification
|
||||
import json
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
from datetime import datetime
|
||||
|
||||
contacts_bp = Blueprint('contacts', __name__, url_prefix='/contacts')
|
||||
|
||||
@@ -122,6 +123,20 @@ def new_contact():
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
|
||||
# Create notification for the new user
|
||||
create_notification(
|
||||
notif_type='account_created',
|
||||
user_id=user.id,
|
||||
sender_id=current_user.id, # Admin who created the account
|
||||
details={
|
||||
'message': 'Your DocuPulse account has been created by an administrator.',
|
||||
'username': user.username,
|
||||
'email': user.email,
|
||||
'created_by': f"{current_user.username} {current_user.last_name}",
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
# Log user creation event
|
||||
log_event(
|
||||
event_type='user_create',
|
||||
@@ -304,6 +319,26 @@ def edit_contact(id):
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Create notification for the user being updated
|
||||
create_notification(
|
||||
notif_type='account_updated',
|
||||
user_id=user.id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': 'Your account has been updated by an administrator.',
|
||||
'updated_by': f"{current_user.username} {current_user.last_name}",
|
||||
'changes': {
|
||||
'name': f"{user.username} {user.last_name}",
|
||||
'email': user.email,
|
||||
'phone': user.phone,
|
||||
'company': user.company,
|
||||
'position': user.position,
|
||||
'password_changed': password_changed
|
||||
},
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
# Log user update event
|
||||
log_event(
|
||||
event_type='user_update',
|
||||
@@ -342,6 +377,18 @@ def delete_contact(id):
|
||||
flash('You cannot delete your own account.', 'error')
|
||||
return redirect(url_for('contacts.contacts_list'))
|
||||
|
||||
# Create notification for the user being deleted
|
||||
create_notification(
|
||||
notif_type='account_deleted',
|
||||
user_id=user.id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': 'Your account has been deleted by an administrator.',
|
||||
'deleted_by': f"{current_user.username} {current_user.last_name}",
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
# Log user deletion event
|
||||
log_event(
|
||||
event_type='user_delete',
|
||||
|
||||
Reference in New Issue
Block a user