Spaces:
Paused
Paused
Upload core/models/user.py with huggingface_hub
Browse files- core/models/user.py +71 -6
core/models/user.py
CHANGED
|
@@ -31,8 +31,13 @@ class User(Base):
|
|
| 31 |
mfa_enabled = Column(Boolean, default=False)
|
| 32 |
mfa_secret = Column(EncryptedString, nullable=True)
|
| 33 |
|
|
|
|
|
|
|
|
|
|
| 34 |
# Relationships
|
| 35 |
-
cases = relationship(
|
|
|
|
|
|
|
| 36 |
activities = relationship("CaseActivity", back_populates="user")
|
| 37 |
devices = relationship("UserDevice", backref="user")
|
| 38 |
onboarding_state = relationship("UserOnboardingState", backref="user")
|
|
@@ -75,6 +80,54 @@ class UserDevice(Base):
|
|
| 75 |
created_at = Column(DateTime, default=utc_now)
|
| 76 |
|
| 77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
class UserOnboardingState(Base):
|
| 79 |
__tablename__ = "user_onboarding_states"
|
| 80 |
|
|
@@ -106,9 +159,13 @@ class TrainingRecord(Base):
|
|
| 106 |
|
| 107 |
id = Column(String, primary_key=True, index=True)
|
| 108 |
user_id = Column(String, index=True)
|
| 109 |
-
training_type = Column(
|
|
|
|
|
|
|
| 110 |
training_module = Column(String, index=True) # specific course or topic
|
| 111 |
-
completion_status = Column(
|
|
|
|
|
|
|
| 112 |
score = Column(Float) # Test score if applicable
|
| 113 |
completion_date = Column(DateTime, index=True)
|
| 114 |
expiry_date = Column(DateTime, index=True)
|
|
@@ -134,10 +191,16 @@ class AccessReview(Base):
|
|
| 134 |
reviewer_id = Column(String, index=True)
|
| 135 |
review_period_start = Column(DateTime, index=True)
|
| 136 |
review_period_end = Column(DateTime, index=True)
|
| 137 |
-
review_status = Column(
|
|
|
|
|
|
|
| 138 |
overall_risk_assessment = Column(String, index=True) # low, medium, high, critical
|
| 139 |
-
findings = Column(
|
| 140 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
approval_status = Column(String, default="pending") # pending, approved, rejected
|
| 142 |
approved_by = Column(String)
|
| 143 |
approved_at = Column(DateTime)
|
|
@@ -151,6 +214,8 @@ __all__ = [
|
|
| 151 |
"Team",
|
| 152 |
"Project",
|
| 153 |
"UserDevice",
|
|
|
|
|
|
|
| 154 |
"UserOnboardingState",
|
| 155 |
"RookieChecklist",
|
| 156 |
"TrainingRecord",
|
|
|
|
| 31 |
mfa_enabled = Column(Boolean, default=False)
|
| 32 |
mfa_secret = Column(EncryptedString, nullable=True)
|
| 33 |
|
| 34 |
+
# Preferences - Store as JSON string for compatibility
|
| 35 |
+
preferences = Column(String, default=lambda: json.dumps({}))
|
| 36 |
+
|
| 37 |
# Relationships
|
| 38 |
+
cases = relationship(
|
| 39 |
+
"Case", back_populates="assignee", foreign_keys="Case.assignee_id"
|
| 40 |
+
)
|
| 41 |
activities = relationship("CaseActivity", back_populates="user")
|
| 42 |
devices = relationship("UserDevice", backref="user")
|
| 43 |
onboarding_state = relationship("UserOnboardingState", backref="user")
|
|
|
|
| 80 |
created_at = Column(DateTime, default=utc_now)
|
| 81 |
|
| 82 |
|
| 83 |
+
class UserSession(Base):
|
| 84 |
+
__tablename__ = "user_sessions"
|
| 85 |
+
|
| 86 |
+
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
| 87 |
+
user_id = Column(String, ForeignKey("users.id"), index=True, nullable=False)
|
| 88 |
+
session_token = Column(String, unique=True, index=True, nullable=False)
|
| 89 |
+
device_info = Column(String) # JSON string with device/browser info
|
| 90 |
+
ip_address = Column(String, nullable=False)
|
| 91 |
+
user_agent = Column(String)
|
| 92 |
+
location = Column(String) # Geolocation data
|
| 93 |
+
is_active = Column(Boolean, default=True, index=True)
|
| 94 |
+
is_current = Column(Boolean, default=False) # Mark current session
|
| 95 |
+
expires_at = Column(DateTime, index=True)
|
| 96 |
+
last_activity = Column(DateTime, default=utc_now, index=True)
|
| 97 |
+
created_at = Column(DateTime, default=utc_now)
|
| 98 |
+
|
| 99 |
+
# Relationships
|
| 100 |
+
user = relationship("User", backref="sessions")
|
| 101 |
+
|
| 102 |
+
__table_args__ = (
|
| 103 |
+
Index("idx_user_sessions_active", "user_id", "is_active"),
|
| 104 |
+
Index("idx_user_sessions_expires", "expires_at"),
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class LoginAttempt(Base):
|
| 109 |
+
__tablename__ = "login_attempts"
|
| 110 |
+
|
| 111 |
+
id = Column(String, primary_key=True, index=True, default=lambda: str(uuid.uuid4()))
|
| 112 |
+
email = Column(String, index=True) # Store email for non-existent users
|
| 113 |
+
user_id = Column(String, ForeignKey("users.id"), index=True, nullable=True)
|
| 114 |
+
ip_address = Column(String, nullable=False, index=True)
|
| 115 |
+
user_agent = Column(String)
|
| 116 |
+
location = Column(String)
|
| 117 |
+
device_type = Column(String, default="desktop")
|
| 118 |
+
success = Column(Boolean, default=False, index=True)
|
| 119 |
+
failure_reason = Column(String)
|
| 120 |
+
attempted_at = Column(DateTime, default=utc_now, index=True)
|
| 121 |
+
|
| 122 |
+
# Relationships
|
| 123 |
+
user = relationship("User", backref="login_attempts")
|
| 124 |
+
|
| 125 |
+
__table_args__ = (
|
| 126 |
+
Index("idx_login_attempts_user_time", "user_id", "attempted_at"),
|
| 127 |
+
Index("idx_login_attempts_ip_time", "ip_address", "attempted_at"),
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
class UserOnboardingState(Base):
|
| 132 |
__tablename__ = "user_onboarding_states"
|
| 133 |
|
|
|
|
| 159 |
|
| 160 |
id = Column(String, primary_key=True, index=True)
|
| 161 |
user_id = Column(String, index=True)
|
| 162 |
+
training_type = Column(
|
| 163 |
+
String, index=True
|
| 164 |
+
) # security_awareness, compliance, technical
|
| 165 |
training_module = Column(String, index=True) # specific course or topic
|
| 166 |
+
completion_status = Column(
|
| 167 |
+
String, default="not_started", index=True
|
| 168 |
+
) # not_started, in_progress, completed, failed
|
| 169 |
score = Column(Float) # Test score if applicable
|
| 170 |
completion_date = Column(DateTime, index=True)
|
| 171 |
expiry_date = Column(DateTime, index=True)
|
|
|
|
| 191 |
reviewer_id = Column(String, index=True)
|
| 192 |
review_period_start = Column(DateTime, index=True)
|
| 193 |
review_period_end = Column(DateTime, index=True)
|
| 194 |
+
review_status = Column(
|
| 195 |
+
String, default="pending", index=True
|
| 196 |
+
) # pending, in_progress, completed, overdue
|
| 197 |
overall_risk_assessment = Column(String, index=True) # low, medium, high, critical
|
| 198 |
+
findings = Column(
|
| 199 |
+
String, default=lambda: json.dumps([])
|
| 200 |
+
) # Specific access issues found
|
| 201 |
+
recommendations = Column(
|
| 202 |
+
String, default=lambda: json.dumps([])
|
| 203 |
+
) # Remediation actions
|
| 204 |
approval_status = Column(String, default="pending") # pending, approved, rejected
|
| 205 |
approved_by = Column(String)
|
| 206 |
approved_at = Column(DateTime)
|
|
|
|
| 214 |
"Team",
|
| 215 |
"Project",
|
| 216 |
"UserDevice",
|
| 217 |
+
"UserSession",
|
| 218 |
+
"LoginAttempt",
|
| 219 |
"UserOnboardingState",
|
| 220 |
"RookieChecklist",
|
| 221 |
"TrainingRecord",
|