Revert "Added events system"

This reverts commit f00d569db3.
This commit is contained in:
2025-05-29 14:45:52 +02:00
parent f00d569db3
commit 6d959ac253
24 changed files with 114 additions and 1186 deletions

78
utils.py Normal file
View File

@@ -0,0 +1,78 @@
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)
def clean_path(path):
"""
Clean a file path by removing leading/trailing slashes and normalizing separators.
Args:
path: Path string to clean
Returns:
str: Cleaned path
"""
if not path:
return ''
return path.strip('/\\')
def timeago(date):
"""Convert a datetime to a human-readable time ago string."""
if not date:
return ''
# Convert naive datetime to UTC if it's naive
if date.tzinfo is None:
date = date.replace(tzinfo=timezone.utc)
now = datetime.now(timezone.utc)
diff = now - date
if diff.days > 365:
years = diff.days // 365
return f'{years} year{"s" if years != 1 else ""} ago'
elif diff.days > 30:
months = diff.days // 30
return f'{months} month{"s" if months != 1 else ""} ago'
elif diff.days > 0:
return f'{diff.days} day{"s" if diff.days != 1 else ""} ago'
elif diff.seconds > 3600:
hours = diff.seconds // 3600
return f'{hours} hour{"s" if hours != 1 else ""} ago'
elif diff.seconds > 60:
minutes = diff.seconds // 60
return f'{minutes} minute{"s" if minutes != 1 else ""} ago'
else:
return 'just now'