added events to event system
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from flask import Blueprint, jsonify, request, abort
|
||||
from flask_login import login_required, current_user
|
||||
from models import db, Room, User, RoomMemberPermission
|
||||
from utils import user_has_permission, log_event
|
||||
from utils import user_has_permission, log_event, create_notification
|
||||
from datetime import datetime
|
||||
|
||||
room_members_bp = Blueprint('room_members', __name__)
|
||||
|
||||
@@ -69,6 +70,21 @@ def add_room_member(room_id):
|
||||
permission.can_share = permissions.get('can_share', False)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Create notification for the invited user
|
||||
create_notification(
|
||||
notif_type='room_invite',
|
||||
user_id=user_id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': f'You have been invited to join room "{room.name}"',
|
||||
'room_id': room_id,
|
||||
'room_name': room.name,
|
||||
'invited_by': f"{current_user.username} {current_user.last_name}",
|
||||
'permissions': permissions,
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
log_event(
|
||||
event_type='room_member_add',
|
||||
@@ -77,8 +93,7 @@ def add_room_member(room_id):
|
||||
'room_name': room.name,
|
||||
'added_user_id': user_id,
|
||||
'added_user_name': f"{user.username} {user.last_name}",
|
||||
'added_by': f"{current_user.username} {current_user.last_name}",
|
||||
'permissions': permissions
|
||||
'added_by': f"{current_user.username} {current_user.last_name}"
|
||||
},
|
||||
user_id=current_user.id
|
||||
)
|
||||
@@ -104,6 +119,20 @@ def remove_room_member(room_id, user_id):
|
||||
db.session.delete(permission)
|
||||
|
||||
db.session.commit()
|
||||
|
||||
# Create notification for the removed user
|
||||
create_notification(
|
||||
notif_type='room_invite_removed',
|
||||
user_id=user_id,
|
||||
sender_id=current_user.id,
|
||||
details={
|
||||
'message': f'You have been removed from room "{room.name}"',
|
||||
'room_id': room_id,
|
||||
'room_name': room.name,
|
||||
'removed_by': f"{current_user.username} {current_user.last_name}",
|
||||
'timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
)
|
||||
|
||||
log_event(
|
||||
event_type='room_member_remove',
|
||||
|
||||
Reference in New Issue
Block a user