@@ -1,35 +0,0 @@
|
||||
from flask_login import current_user
|
||||
from models import RoomMemberPermission
|
||||
from datetime import datetime, timezone
|
||||
|
||||
def user_has_permission(room, perm_name):
|
||||
"""
|
||||
Check if the current user has a specific permission in a room.
|
||||
|
||||
Args:
|
||||
room: Room object
|
||||
perm_name: Name of the permission to check (e.g., 'can_view', 'can_upload')
|
||||
|
||||
Returns:
|
||||
bool: True if user has permission, False otherwise
|
||||
"""
|
||||
# Admin users have all permissions
|
||||
if current_user.is_admin:
|
||||
return True
|
||||
|
||||
# Check if user is a member of the room
|
||||
if current_user not in room.members:
|
||||
return False
|
||||
|
||||
# Get user's permissions for this room
|
||||
permission = RoomMemberPermission.query.filter_by(
|
||||
room_id=room.id,
|
||||
user_id=current_user.id
|
||||
).first()
|
||||
|
||||
# If no specific permissions are set, user only has view access
|
||||
if not permission:
|
||||
return perm_name == 'can_view'
|
||||
|
||||
# Check the specific permission
|
||||
return getattr(permission, perm_name, False)
|
||||
Reference in New Issue
Block a user