storage cards on dash
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from flask import render_template, Blueprint, redirect, url_for, request, flash, Response, jsonify, session
|
||||
from flask_login import current_user, login_required
|
||||
from models import User, db, Room, RoomFile, RoomMemberPermission, SiteSettings, Event
|
||||
from models import User, db, Room, RoomFile, RoomMemberPermission, SiteSettings, Event, Conversation, Message, MessageAttachment
|
||||
from routes.auth import require_password_change
|
||||
import os
|
||||
from werkzeug.utils import secure_filename
|
||||
@@ -49,7 +49,20 @@ def init_routes(main_bp):
|
||||
if current_user.is_admin:
|
||||
recent_events = Event.query.order_by(Event.timestamp.desc()).limit(7).all()
|
||||
else:
|
||||
recent_events = Event.query.filter_by(user_id=current_user.id).order_by(Event.timestamp.desc()).limit(7).all()
|
||||
# Get events where user is the actor OR events from conversations they are a member of
|
||||
recent_events = Event.query.filter(
|
||||
db.or_(
|
||||
Event.user_id == current_user.id, # User's own actions
|
||||
db.and_(
|
||||
Event.event_type.in_(['conversation_create', 'message_create']), # Conversation-related events
|
||||
Event.details['conversation_id'].astext.in_(
|
||||
db.session.query(Conversation.id)
|
||||
.join(Conversation.members)
|
||||
.filter(User.id == current_user.id)
|
||||
)
|
||||
)
|
||||
)
|
||||
).order_by(Event.timestamp.desc()).limit(7).all()
|
||||
|
||||
# Room count and size logic
|
||||
if current_user.is_admin:
|
||||
@@ -253,6 +266,21 @@ def init_routes(main_bp):
|
||||
RoomFile.deleted==True
|
||||
).group_by('extension').all()
|
||||
|
||||
# Get conversation statistics
|
||||
if current_user.is_admin:
|
||||
conversation_count = Conversation.query.count()
|
||||
message_count = Message.query.count()
|
||||
attachment_count = MessageAttachment.query.count()
|
||||
conversation_total_size = db.session.query(db.func.sum(MessageAttachment.size)).scalar() or 0
|
||||
recent_conversations = Conversation.query.order_by(Conversation.created_at.desc()).limit(5).all()
|
||||
else:
|
||||
# For regular users, only show their conversations
|
||||
conversation_count = Conversation.query.filter(Conversation.members.any(id=current_user.id)).count()
|
||||
message_count = Message.query.join(Conversation).filter(Conversation.members.any(id=current_user.id)).count()
|
||||
attachment_count = MessageAttachment.query.join(Message).join(Conversation).filter(Conversation.members.any(id=current_user.id)).count()
|
||||
conversation_total_size = db.session.query(db.func.sum(MessageAttachment.size)).join(Message).join(Conversation).filter(Conversation.members.any(id=current_user.id)).scalar() or 0
|
||||
recent_conversations = Conversation.query.filter(Conversation.members.any(id=current_user.id)).order_by(Conversation.created_at.desc()).limit(5).all()
|
||||
|
||||
return render_template('dashboard/dashboard.html',
|
||||
recent_contacts=recent_contacts,
|
||||
active_count=active_count,
|
||||
@@ -260,7 +288,7 @@ def init_routes(main_bp):
|
||||
room_count=room_count,
|
||||
file_count=file_count,
|
||||
folder_count=folder_count,
|
||||
total_size=total_size,
|
||||
total_size=total_size, # Room storage size
|
||||
storage_by_type=storage_by_type,
|
||||
trash_count=trash_count,
|
||||
starred_count=starred_count,
|
||||
@@ -269,7 +297,12 @@ def init_routes(main_bp):
|
||||
pending_deletion=pending_deletion,
|
||||
trash_by_type=trash_by_type,
|
||||
recent_events=recent_events,
|
||||
is_admin=current_user.is_admin)
|
||||
is_admin=current_user.is_admin,
|
||||
conversation_count=conversation_count,
|
||||
message_count=message_count,
|
||||
attachment_count=attachment_count,
|
||||
conversation_total_size=conversation_total_size, # Conversation storage size
|
||||
recent_conversations=recent_conversations)
|
||||
|
||||
UPLOAD_FOLDER = os.path.join(os.getcwd(), 'uploads', 'profile_pics')
|
||||
if not os.path.exists(UPLOAD_FOLDER):
|
||||
|
||||
Reference in New Issue
Block a user