Spaces:
Paused
Paused
Upload core/models/case.py with huggingface_hub
Browse files- core/models/case.py +50 -14
core/models/case.py
CHANGED
|
@@ -8,7 +8,17 @@ fraud case management and investigation.
|
|
| 8 |
import json
|
| 9 |
import uuid
|
| 10 |
|
| 11 |
-
from sqlalchemy import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
from sqlalchemy.orm import relationship
|
| 13 |
|
| 14 |
from .base import Base, CasePriority, CaseStatus, CaseType, EncryptedString, utc_now
|
|
@@ -18,7 +28,9 @@ class Case(Base):
|
|
| 18 |
__tablename__ = "cases"
|
| 19 |
|
| 20 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 21 |
-
project_id = Column(
|
|
|
|
|
|
|
| 22 |
title = Column(String, nullable=False, index=True)
|
| 23 |
description = Column(EncryptedString)
|
| 24 |
status = Column(String, default=CaseStatus.OPEN, index=True)
|
|
@@ -43,13 +55,27 @@ class Case(Base):
|
|
| 43 |
project = relationship("Project", back_populates="cases")
|
| 44 |
assignee = relationship("User", back_populates="cases", foreign_keys=[assignee_id])
|
| 45 |
creator = relationship("User", foreign_keys=[created_by])
|
| 46 |
-
transactions = relationship(
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
|
| 55 |
class Transaction(Base):
|
|
@@ -77,7 +103,9 @@ class Transaction(Base):
|
|
| 77 |
# Relationships
|
| 78 |
case = relationship("Case", back_populates="transactions")
|
| 79 |
|
| 80 |
-
__table_args__ = (
|
|
|
|
|
|
|
| 81 |
|
| 82 |
|
| 83 |
class Evidence(Base):
|
|
@@ -98,7 +126,9 @@ class Evidence(Base):
|
|
| 98 |
uploaded_by = Column(String, index=True)
|
| 99 |
|
| 100 |
# Processing information
|
| 101 |
-
processing_status = Column(
|
|
|
|
|
|
|
| 102 |
processed_at = Column(DateTime, index=True)
|
| 103 |
|
| 104 |
# Content analysis
|
|
@@ -144,7 +174,9 @@ class CaseActivity(Base):
|
|
| 144 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 145 |
case_id = Column(String, ForeignKey("cases.id"), index=True)
|
| 146 |
user_id = Column(String, ForeignKey("users.id"), index=True)
|
| 147 |
-
activity_type = Column(
|
|
|
|
|
|
|
| 148 |
description = Column(String, nullable=False)
|
| 149 |
activity_metadata = Column(JSON, default=dict)
|
| 150 |
created_at = Column(DateTime, default=utc_now, index=True)
|
|
@@ -160,7 +192,9 @@ class FraudAlert(Base):
|
|
| 160 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 161 |
case_id = Column(String, ForeignKey("cases.id"), index=True)
|
| 162 |
alert_type = Column(String, nullable=False, index=True)
|
| 163 |
-
severity = Column(
|
|
|
|
|
|
|
| 164 |
title = Column(String, nullable=False)
|
| 165 |
description = Column(EncryptedString)
|
| 166 |
alert_metadata = Column(JSON, default=dict)
|
|
@@ -229,7 +263,9 @@ class EvidenceChain(Base):
|
|
| 229 |
timestamp = Column(DateTime, default=utc_now, index=True)
|
| 230 |
chain_metadata = Column(EncryptedString, default="{}")
|
| 231 |
|
| 232 |
-
__table_args__ = (
|
|
|
|
|
|
|
| 233 |
|
| 234 |
|
| 235 |
__all__ = [
|
|
|
|
| 8 |
import json
|
| 9 |
import uuid
|
| 10 |
|
| 11 |
+
from sqlalchemy import (
|
| 12 |
+
JSON,
|
| 13 |
+
Boolean,
|
| 14 |
+
Column,
|
| 15 |
+
DateTime,
|
| 16 |
+
Float,
|
| 17 |
+
ForeignKey,
|
| 18 |
+
Index,
|
| 19 |
+
Integer,
|
| 20 |
+
String,
|
| 21 |
+
)
|
| 22 |
from sqlalchemy.orm import relationship
|
| 23 |
|
| 24 |
from .base import Base, CasePriority, CaseStatus, CaseType, EncryptedString, utc_now
|
|
|
|
| 28 |
__tablename__ = "cases"
|
| 29 |
|
| 30 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 31 |
+
project_id = Column(
|
| 32 |
+
String, ForeignKey("projects.id"), index=True, default="default"
|
| 33 |
+
)
|
| 34 |
title = Column(String, nullable=False, index=True)
|
| 35 |
description = Column(EncryptedString)
|
| 36 |
status = Column(String, default=CaseStatus.OPEN, index=True)
|
|
|
|
| 55 |
project = relationship("Project", back_populates="cases")
|
| 56 |
assignee = relationship("User", back_populates="cases", foreign_keys=[assignee_id])
|
| 57 |
creator = relationship("User", foreign_keys=[created_by])
|
| 58 |
+
transactions = relationship(
|
| 59 |
+
"Transaction", back_populates="case", cascade="all, delete-orphan"
|
| 60 |
+
)
|
| 61 |
+
evidence = relationship(
|
| 62 |
+
"Evidence", back_populates="case", cascade="all, delete-orphan"
|
| 63 |
+
)
|
| 64 |
+
notes = relationship(
|
| 65 |
+
"CaseNote", back_populates="case", cascade="all, delete-orphan"
|
| 66 |
+
)
|
| 67 |
+
activities = relationship(
|
| 68 |
+
"CaseActivity", back_populates="case", cascade="all, delete-orphan"
|
| 69 |
+
)
|
| 70 |
+
alerts = relationship(
|
| 71 |
+
"FraudAlert", back_populates="case", cascade="all, delete-orphan"
|
| 72 |
+
)
|
| 73 |
+
trade_transactions = relationship(
|
| 74 |
+
"TradeTransaction", back_populates="case", cascade="all, delete-orphan"
|
| 75 |
+
)
|
| 76 |
+
crypto_transactions = relationship(
|
| 77 |
+
"CryptoTransaction", back_populates="case", cascade="all, delete-orphan"
|
| 78 |
+
)
|
| 79 |
|
| 80 |
|
| 81 |
class Transaction(Base):
|
|
|
|
| 103 |
# Relationships
|
| 104 |
case = relationship("Case", back_populates="transactions")
|
| 105 |
|
| 106 |
+
__table_args__ = (
|
| 107 |
+
Index("idx_transactions_case_date_amount", "case_id", "date", "amount"),
|
| 108 |
+
)
|
| 109 |
|
| 110 |
|
| 111 |
class Evidence(Base):
|
|
|
|
| 126 |
uploaded_by = Column(String, index=True)
|
| 127 |
|
| 128 |
# Processing information
|
| 129 |
+
processing_status = Column(
|
| 130 |
+
String, default="pending", index=True
|
| 131 |
+
) # pending, processing, completed, failed
|
| 132 |
processed_at = Column(DateTime, index=True)
|
| 133 |
|
| 134 |
# Content analysis
|
|
|
|
| 174 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 175 |
case_id = Column(String, ForeignKey("cases.id"), index=True)
|
| 176 |
user_id = Column(String, ForeignKey("users.id"), index=True)
|
| 177 |
+
activity_type = Column(
|
| 178 |
+
String, nullable=False, index=True
|
| 179 |
+
) # created, updated, viewed, etc.
|
| 180 |
description = Column(String, nullable=False)
|
| 181 |
activity_metadata = Column(JSON, default=dict)
|
| 182 |
created_at = Column(DateTime, default=utc_now, index=True)
|
|
|
|
| 192 |
id = Column(String, primary_key=True, default=lambda: str(uuid.uuid4()))
|
| 193 |
case_id = Column(String, ForeignKey("cases.id"), index=True)
|
| 194 |
alert_type = Column(String, nullable=False, index=True)
|
| 195 |
+
severity = Column(
|
| 196 |
+
String, default="medium", index=True
|
| 197 |
+
) # low, medium, high, critical
|
| 198 |
title = Column(String, nullable=False)
|
| 199 |
description = Column(EncryptedString)
|
| 200 |
alert_metadata = Column(JSON, default=dict)
|
|
|
|
| 263 |
timestamp = Column(DateTime, default=utc_now, index=True)
|
| 264 |
chain_metadata = Column(EncryptedString, default="{}")
|
| 265 |
|
| 266 |
+
__table_args__ = (
|
| 267 |
+
Index("idx_evidence_package_timestamp", "package_id", "timestamp"),
|
| 268 |
+
)
|
| 269 |
|
| 270 |
|
| 271 |
__all__ = [
|