Final audit fixes: D&D, Docker security, Seed script, review events
This commit is contained in:
+13
-1
@@ -13,6 +13,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|||||||
tesseract-ocr-eng \
|
tesseract-ocr-eng \
|
||||||
tesseract-ocr-hin \
|
tesseract-ocr-hin \
|
||||||
libgl1 \
|
libgl1 \
|
||||||
|
curl \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Install Python dependencies (plain UTF-8 requirements.txt)
|
# Install Python dependencies (plain UTF-8 requirements.txt)
|
||||||
@@ -22,15 +23,26 @@ RUN pip install --upgrade pip && pip install -r /tmp/requirements.txt
|
|||||||
# Copy app source
|
# Copy app source
|
||||||
COPY . /app
|
COPY . /app
|
||||||
|
|
||||||
|
# Create non-root user and ensure directories exist for volume mounts
|
||||||
|
RUN useradd -m appuser && \
|
||||||
|
mkdir -p /app/uploads /app/services/api/chroma_db && \
|
||||||
|
chown -R appuser:appuser /app
|
||||||
|
|
||||||
|
USER appuser
|
||||||
|
|
||||||
WORKDIR /app/services/api
|
WORKDIR /app/services/api
|
||||||
|
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
|
|
||||||
# --forwarded-allow-ips=* trusts X-Forwarded-For from nginx container
|
# --forwarded-allow-ips=* trusts X-Forwarded-For from nginx container
|
||||||
# Required so rate limiter and audit logs see real client IPs (not nginx's internal IP)
|
# Required so rate limiter and audit logs see real client IPs (not nginx's internal IP)
|
||||||
|
|
||||||
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
||||||
|
CMD curl -f http://localhost:8000/health || exit 1
|
||||||
|
|
||||||
|
# B6 Fix: Drop --workers 4 to prevent scheduler from running 4 times concurrently
|
||||||
CMD ["uvicorn", "app.main:app", \
|
CMD ["uvicorn", "app.main:app", \
|
||||||
"--host", "0.0.0.0", \
|
"--host", "0.0.0.0", \
|
||||||
"--port", "8000", \
|
"--port", "8000", \
|
||||||
"--workers", "4", \
|
|
||||||
"--proxy-headers", \
|
"--proxy-headers", \
|
||||||
"--forwarded-allow-ips=*"]
|
"--forwarded-allow-ips=*"]
|
||||||
|
|||||||
@@ -167,7 +167,22 @@ export default function UploadBusiness() {
|
|||||||
const isApproved = latestDoc?.review_status === 'approved';
|
const isApproved = latestDoc?.review_status === 'approved';
|
||||||
const isFiled = latestDoc?.review_status === 'filed';
|
const isFiled = latestDoc?.review_status === 'filed';
|
||||||
return (
|
return (
|
||||||
<div className="doc-slot fade-up" key={i} style={{ animationDelay: `${i * 0.04}s`, borderLeft: isRejected ? '3px solid #dc3545' : isApproved || isFiled ? '3px solid #2c7a5b' : 'none' }}>
|
<div
|
||||||
|
className="doc-slot fade-up"
|
||||||
|
key={i}
|
||||||
|
style={{ animationDelay: `${i * 0.04}s`, borderLeft: isRejected ? '3px solid #dc3545' : isApproved || isFiled ? '3px solid #2c7a5b' : 'none' }}
|
||||||
|
onDragOver={(e) => e.preventDefault()}
|
||||||
|
onDrop={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.dataTransfer.files && e.dataTransfer.files[0]) {
|
||||||
|
if (!uploaded.length || isRejected) {
|
||||||
|
uploadFile(e.dataTransfer.files[0], dt.name);
|
||||||
|
} else {
|
||||||
|
showToast("Document already uploaded for this type and year.", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div className="doc-slot-info">
|
<div className="doc-slot-info">
|
||||||
<div className="doc-slot-name">{i+1}. {dt.name}</div>
|
<div className="doc-slot-name">{i+1}. {dt.name}</div>
|
||||||
<div className="doc-slot-status">
|
<div className="doc-slot-status">
|
||||||
@@ -280,6 +295,14 @@ export default function UploadBusiness() {
|
|||||||
extraFileRef.current?.click();
|
extraFileRef.current?.click();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onDragOver={(e) => e.preventDefault()}
|
||||||
|
onDrop={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
||||||
|
const fakeEvent = { target: { files: e.dataTransfer.files } };
|
||||||
|
handleExtraUpload(fakeEvent);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="da-icon"><span className="material-symbols-outlined" style={{color: 'var(--brass)', fontSize: '32px'}}>folder</span></div>
|
<div className="da-icon"><span className="material-symbols-outlined" style={{color: 'var(--brass)', fontSize: '32px'}}>folder</span></div>
|
||||||
<div className="da-title" style={{fontWeight: 600, color: 'var(--navy)', fontSize: '14px'}}>Drag & drop files here</div>
|
<div className="da-title" style={{fontWeight: 600, color: 'var(--navy)', fontSize: '14px'}}>Drag & drop files here</div>
|
||||||
|
|||||||
@@ -169,7 +169,22 @@ export default function UploadPersonal() {
|
|||||||
const isApproved = latestDoc?.review_status === 'approved';
|
const isApproved = latestDoc?.review_status === 'approved';
|
||||||
const isFiled = latestDoc?.review_status === 'filed';
|
const isFiled = latestDoc?.review_status === 'filed';
|
||||||
return (
|
return (
|
||||||
<div className="doc-slot fade-up" key={i} style={{ animationDelay: `${i * 0.04}s`, borderLeft: isRejected ? '3px solid #dc3545' : isApproved || isFiled ? '3px solid #2c7a5b' : 'none' }}>
|
<div
|
||||||
|
className="doc-slot fade-up"
|
||||||
|
key={i}
|
||||||
|
style={{ animationDelay: `${i * 0.04}s`, borderLeft: isRejected ? '3px solid #dc3545' : isApproved || isFiled ? '3px solid #2c7a5b' : 'none' }}
|
||||||
|
onDragOver={(e) => e.preventDefault()}
|
||||||
|
onDrop={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.dataTransfer.files && e.dataTransfer.files[0]) {
|
||||||
|
if (!uploaded.length || isRejected) {
|
||||||
|
uploadFile(e.dataTransfer.files[0], dt.name);
|
||||||
|
} else {
|
||||||
|
showToast("Document already uploaded for this type and year.", "error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<div className="doc-slot-info">
|
<div className="doc-slot-info">
|
||||||
<div className="doc-slot-name">{i+1}. {dt.name}</div>
|
<div className="doc-slot-name">{i+1}. {dt.name}</div>
|
||||||
<div className="doc-slot-status">
|
<div className="doc-slot-status">
|
||||||
@@ -282,6 +297,14 @@ export default function UploadPersonal() {
|
|||||||
extraFileRef.current?.click();
|
extraFileRef.current?.click();
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
onDragOver={(e) => e.preventDefault()}
|
||||||
|
onDrop={(e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
||||||
|
const fakeEvent = { target: { files: e.dataTransfer.files } };
|
||||||
|
handleExtraUpload(fakeEvent);
|
||||||
|
}
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div className="da-icon"><span className="material-symbols-outlined" style={{color: 'var(--brass)', fontSize: '32px'}}>folder</span></div>
|
<div className="da-icon"><span className="material-symbols-outlined" style={{color: 'var(--brass)', fontSize: '32px'}}>folder</span></div>
|
||||||
<div className="da-title" style={{fontWeight: 600, color: 'var(--navy)', fontSize: '14px'}}>Drag & drop files here</div>
|
<div className="da-title" style={{fontWeight: 600, color: 'var(--navy)', fontSize: '14px'}}>Drag & drop files here</div>
|
||||||
|
|||||||
@@ -785,6 +785,22 @@ async def set_personal_review_status(
|
|||||||
detail=f"owner:{doc.user_id}" + (f" note:{payload.note}" if payload.note else ""),
|
detail=f"owner:{doc.user_id}" + (f" note:{payload.note}" if payload.note else ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from app.models import DocumentReviewEvent
|
||||||
|
event = DocumentReviewEvent(
|
||||||
|
doc_kind="personal",
|
||||||
|
doc_id=doc.id,
|
||||||
|
owner_user_id=doc.user_id,
|
||||||
|
actor_id=current_user.id,
|
||||||
|
actor_role="admin",
|
||||||
|
action="status_updated",
|
||||||
|
from_status=prev_status,
|
||||||
|
to_status=payload.status,
|
||||||
|
comment=payload.note,
|
||||||
|
tax_year=doc.tax_year
|
||||||
|
)
|
||||||
|
db.add(event)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
# Email client on rejection (Gap #3 fix)
|
# Email client on rejection (Gap #3 fix)
|
||||||
if payload.status == "rejected" and prev_status != "rejected":
|
if payload.status == "rejected" and prev_status != "rejected":
|
||||||
owner = db.query(User).filter_by(id=doc.user_id).first()
|
owner = db.query(User).filter_by(id=doc.user_id).first()
|
||||||
@@ -833,6 +849,22 @@ async def set_business_review_status(
|
|||||||
detail=f"owner:{doc.user_id}" + (f" note:{payload.note}" if payload.note else ""),
|
detail=f"owner:{doc.user_id}" + (f" note:{payload.note}" if payload.note else ""),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from app.models import DocumentReviewEvent
|
||||||
|
event = DocumentReviewEvent(
|
||||||
|
doc_kind="business",
|
||||||
|
doc_id=doc.id,
|
||||||
|
owner_user_id=doc.user_id,
|
||||||
|
actor_id=current_user.id,
|
||||||
|
actor_role="admin",
|
||||||
|
action="status_updated",
|
||||||
|
from_status=prev_status,
|
||||||
|
to_status=payload.status,
|
||||||
|
comment=payload.note,
|
||||||
|
tax_year=doc.tax_year
|
||||||
|
)
|
||||||
|
db.add(event)
|
||||||
|
db.commit()
|
||||||
|
|
||||||
# Email client on rejection (Gap #3 fix)
|
# Email client on rejection (Gap #3 fix)
|
||||||
if payload.status == "rejected" and prev_status != "rejected":
|
if payload.status == "rejected" and prev_status != "rejected":
|
||||||
owner = db.query(User).filter_by(id=doc.user_id).first()
|
owner = db.query(User).filter_by(id=doc.user_id).first()
|
||||||
|
|||||||
@@ -9,6 +9,9 @@ from sqlalchemy.orm import Session
|
|||||||
from app.db import SessionLocal
|
from app.db import SessionLocal
|
||||||
from app.models import User, PersonalDocument, BusinessDocument, UserRole
|
from app.models import User, PersonalDocument, BusinessDocument, UserRole
|
||||||
import app.crud as crud
|
import app.crud as crud
|
||||||
|
import secrets
|
||||||
|
import string
|
||||||
|
import fitz # PyMuPDF
|
||||||
|
|
||||||
UPLOAD_DIR = "/app/uploads"
|
UPLOAD_DIR = "/app/uploads"
|
||||||
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
os.makedirs(UPLOAD_DIR, exist_ok=True)
|
||||||
@@ -26,10 +29,20 @@ MOCK_USERS = [
|
|||||||
{"name": "Charles Martinez", "email": "charles.m@example.com"},
|
{"name": "Charles Martinez", "email": "charles.m@example.com"},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def generate_password(length=14):
|
||||||
|
alphabet = string.ascii_letters + string.digits + "!@#$%^&*"
|
||||||
|
while True:
|
||||||
|
pwd = "".join(secrets.choice(alphabet) for _ in range(length))
|
||||||
|
if (any(c.islower() for c in pwd) and any(c.isupper() for c in pwd) and
|
||||||
|
any(c.isdigit() for c in pwd) and any(c in "!@#$%^&*" for c in pwd)):
|
||||||
|
return pwd
|
||||||
|
|
||||||
def generate_pdf(filepath, title, content):
|
def generate_pdf(filepath, title, content):
|
||||||
minimal_pdf = b"%PDF-1.0\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 3 3]>>endobj\nxref\n0 4\n0000000000 65535 f\n0000000010 00000 n\n0000000053 00000 n\n0000000102 00000 n\ntrailer<</Size 4/Root 1 0 R>>\nstartxref\n149\n%EOF\n"
|
doc = fitz.open()
|
||||||
with open(filepath, 'wb') as f:
|
page = doc.new_page()
|
||||||
f.write(minimal_pdf)
|
page.insert_text((50, 50), f"{title}\n\n{content}", fontsize=12)
|
||||||
|
doc.save(filepath)
|
||||||
|
doc.close()
|
||||||
|
|
||||||
def seed_data():
|
def seed_data():
|
||||||
db: Session = SessionLocal()
|
db: Session = SessionLocal()
|
||||||
@@ -38,16 +51,17 @@ def seed_data():
|
|||||||
for user_data in MOCK_USERS:
|
for user_data in MOCK_USERS:
|
||||||
existing_user = db.query(User).filter(User.email == user_data["email"]).first()
|
existing_user = db.query(User).filter(User.email == user_data["email"]).first()
|
||||||
if not existing_user:
|
if not existing_user:
|
||||||
|
password = generate_password()
|
||||||
new_user = User(
|
new_user = User(
|
||||||
name=user_data["name"],
|
name=user_data["name"],
|
||||||
email=user_data["email"],
|
email=user_data["email"],
|
||||||
hashed_password=crud.hash_password("Password123!"),
|
hashed_password=crud.hash_password(password),
|
||||||
role=UserRole.user
|
role=UserRole.user
|
||||||
)
|
)
|
||||||
db.add(new_user)
|
db.add(new_user)
|
||||||
db.commit()
|
db.commit()
|
||||||
db.refresh(new_user)
|
db.refresh(new_user)
|
||||||
print(f"Created user: {new_user.email}")
|
print(f"Created user: {new_user.email} (Password: {password})")
|
||||||
user_id = new_user.id
|
user_id = new_user.id
|
||||||
else:
|
else:
|
||||||
user_id = existing_user.id
|
user_id = existing_user.id
|
||||||
|
|||||||
Reference in New Issue
Block a user