Implemented simple authentication for testing and admin panel for user management: Backend: - Add simple email/password login for test users (admin@test.local, user@test.local) - Implement RBAC (Role-Based Access Control) with Permission enum - Create admin endpoints for user management and system analytics - Add bcrypt password hashing for test users - Create script to generate test users in database Frontend: - Add SimpleLogin component for test authentication - Create AdminPanel with user management and system analytics - Add role-based navigation (Admin tab visible only for admins) - Update AuthContext to support both MSAL and simple login - Add API methods for admin operations Features: - Admins can view all users, manage roles, activate/deactivate accounts - Admins can view system-wide analytics (users, conversations, tokens, costs) - Regular users only see their own chats and usage - Role badges in UI show user role (user/admin/superadmin) Note: Simple authentication is for testing only. Production uses Azure AD MSAL. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
56 lines
1.8 KiB
Python
56 lines
1.8 KiB
Python
"""
|
|
UserMemory model for storing long-term user memory across conversations
|
|
"""
|
|
|
|
from sqlalchemy import Column, String, Text, Numeric, DateTime, JSON, ForeignKey, UniqueConstraint
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
from sqlalchemy.sql import func
|
|
import uuid
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class UserMemory(Base):
|
|
"""
|
|
UserMemory model for storing important user information across conversations
|
|
|
|
This enables the bot to remember user preferences, frequently asked questions,
|
|
and important context from previous interactions.
|
|
"""
|
|
|
|
__tablename__ = "user_memory"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
|
|
user_id = Column(
|
|
UUID(as_uuid=True),
|
|
ForeignKey("users.id", ondelete="CASCADE"),
|
|
nullable=False,
|
|
index=True
|
|
)
|
|
|
|
# Memory key-value pair
|
|
memory_key = Column(String(255), nullable=False, index=True) # Category or topic
|
|
memory_value = Column(Text, nullable=False)
|
|
|
|
# Importance score (0.0 to 1.0)
|
|
importance_score = Column(Numeric(3, 2), default=0.5, nullable=False)
|
|
|
|
# Timestamps
|
|
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
|
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
|
last_accessed_at = Column(DateTime(timezone=True), server_default=func.now())
|
|
|
|
# JSON field for additional metadata
|
|
meta_data = Column(JSON, default=dict, nullable=False)
|
|
|
|
# Relationships
|
|
user = relationship("User", back_populates="memories")
|
|
|
|
# Constraints
|
|
__table_args__ = (
|
|
UniqueConstraint("user_id", "memory_key", name="uq_user_memory_key"),
|
|
)
|
|
|
|
def __repr__(self):
|
|
return f"<UserMemory {self.id} - {self.memory_key}>"
|