feat: complete platform overhaul, bugfixes, and verified production release
This commit is contained in:
@@ -256,11 +256,35 @@ def admin_bulk_action(
|
||||
model_class.deleted_at == None,
|
||||
).all()
|
||||
|
||||
from app import crud
|
||||
from app.models import DocumentReviewEvent
|
||||
from datetime import datetime
|
||||
|
||||
count = 0
|
||||
for doc in docs:
|
||||
doc.review_status = new_status
|
||||
if new_status == "approved":
|
||||
doc.reviewed_at = datetime.utcnow()
|
||||
event = DocumentReviewEvent(
|
||||
doc_kind=doc_type,
|
||||
doc_id=doc.id,
|
||||
owner_user_id=payload.user_id,
|
||||
actor_id=current_user.id,
|
||||
actor_role="admin",
|
||||
action=f"bulk_{new_status}",
|
||||
from_status="pending",
|
||||
to_status=new_status,
|
||||
tax_year=doc.tax_year,
|
||||
)
|
||||
db.add(event)
|
||||
count += 1
|
||||
|
||||
crud.log_action(
|
||||
db, "bulk_review_docs",
|
||||
user_id=current_user.id,
|
||||
target=f"user:{payload.user_id}",
|
||||
detail=f"bulk_{new_status} {count} {doc_type} documents",
|
||||
)
|
||||
db.commit()
|
||||
logger.info(f"Admin {current_user.id} bulk {new_status} {count} {doc_type} docs for user {payload.user_id}")
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import html
|
||||
from fastapi import APIRouter, BackgroundTasks, HTTPException, Request
|
||||
from app.limiter import limiter
|
||||
from pydantic import BaseModel, EmailStr, field_validator
|
||||
@@ -7,7 +8,7 @@ from app.utils.emailer import send_email
|
||||
router = APIRouter(prefix="/api", tags=["contact"])
|
||||
|
||||
# Get admin email from environment, with fallback
|
||||
ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "admin@bookkeepro.net")
|
||||
ADMIN_EMAIL = os.getenv("ADMIN_EMAIL", "atharvg.aiindia@gmail.com")
|
||||
|
||||
class ContactForm(BaseModel):
|
||||
first_name: str
|
||||
@@ -28,6 +29,12 @@ class ContactForm(BaseModel):
|
||||
async def contact_message(request: Request, form: ContactForm, background: BackgroundTasks):
|
||||
if not ADMIN_EMAIL or "@" not in ADMIN_EMAIL:
|
||||
raise HTTPException(status_code=500, detail="Admin email not configured")
|
||||
safe_first = html.escape(form.first_name)
|
||||
safe_last = html.escape(form.last_name)
|
||||
safe_email = html.escape(str(form.email))
|
||||
safe_phone = html.escape(form.phone)
|
||||
safe_message = html.escape(form.message) if form.message else '(none)'
|
||||
|
||||
background.add_task(
|
||||
send_email,
|
||||
to=ADMIN_EMAIL,
|
||||
@@ -37,10 +44,10 @@ async def contact_message(request: Request, form: ContactForm, background: Backg
|
||||
<br><br>
|
||||
A new contact enquiry has been received. Please find the details below:
|
||||
<br><br>
|
||||
<b>Name:</b> {form.first_name} {form.last_name}<br>
|
||||
<b>Email:</b> {form.email}<br>
|
||||
<b>Phone:</b> {form.phone}<br>
|
||||
<b>Message:</b> {form.message or '(none)'}<br><br>
|
||||
<b>Name:</b> {safe_first} {safe_last}<br>
|
||||
<b>Email:</b> {safe_email}<br>
|
||||
<b>Phone:</b> {safe_phone}<br>
|
||||
<b>Message:</b> {safe_message}<br><br>
|
||||
Kindly follow up with the user at the earliest convenience.
|
||||
<br><br>
|
||||
Thank you,<br>
|
||||
@@ -54,7 +61,7 @@ async def contact_message(request: Request, form: ContactForm, background: Backg
|
||||
to=form.email,
|
||||
subject="Thanks for contacting BookKeepro",
|
||||
body=f"""
|
||||
Hi {form.first_name},<br><br>
|
||||
Hi {safe_first},<br><br>
|
||||
Thank you for reaching out to BookKeepro.<br>
|
||||
We’ve received your enquiry, and our team will get back to you shortly.<br><br>
|
||||
Best Regards,<br>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import os
|
||||
from datetime import date, timedelta
|
||||
from datetime import date, datetime, timedelta
|
||||
import logging
|
||||
from fastapi import APIRouter, BackgroundTasks, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -14,7 +14,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
router = APIRouter(prefix="/api/review", tags=["review"])
|
||||
|
||||
DASHBOARD_LINK = f"{os.getenv('FRONTEND_URL', 'https://aiindiacpa.duckdns.org')}/dashboard"
|
||||
DASHBOARD_LINK = f"{os.getenv('FRONTEND_URL', 'https://aicpa.duckdns.org')}/dashboard"
|
||||
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
@@ -127,6 +127,7 @@ async def notify_user_review(
|
||||
@router.post("/admin-doc-response")
|
||||
async def admin_doc_response(
|
||||
payload: AdminDocResponseRequest,
|
||||
background: BackgroundTasks,
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
@@ -147,6 +148,7 @@ async def admin_doc_response(
|
||||
raise HTTPException(status_code=403, detail="Not authorized")
|
||||
|
||||
doc.review_status = payload.status
|
||||
doc.reviewed_at = datetime.utcnow()
|
||||
if payload.reason:
|
||||
doc.review_note = payload.reason
|
||||
db.commit()
|
||||
@@ -166,28 +168,29 @@ async def admin_doc_response(
|
||||
db.add(event)
|
||||
db.commit()
|
||||
|
||||
admin = db.query(User).filter_by(id=doc.uploaded_by).first()
|
||||
if not admin:
|
||||
raise HTTPException(status_code=404, detail="Admin not found")
|
||||
admin = db.query(User).filter_by(id=doc.uploaded_by).first() if doc.uploaded_by else None
|
||||
admin_email = admin.email if admin else os.getenv("ADMIN_EMAIL")
|
||||
|
||||
body = f"""
|
||||
<p>Dear Admin,</p>
|
||||
<p>User <b>{current_user.email}</b> has <b>{payload.status.upper()}</b> the document:</p>
|
||||
<p><b>{doc.doc_label}</b></p>
|
||||
"""
|
||||
if payload.status == "rejected" and payload.reason:
|
||||
body += f"<p><strong>Reason:</strong></p><p>{payload.reason}</p>"
|
||||
if admin_email:
|
||||
body = f"""
|
||||
<p>Dear Admin,</p>
|
||||
<p>User <b>{current_user.email}</b> has <b>{payload.status.upper()}</b> the document:</p>
|
||||
<p><b>{doc.doc_label}</b></p>
|
||||
"""
|
||||
if payload.status == "rejected" and payload.reason:
|
||||
body += f"<p><strong>Reason:</strong></p><p>{payload.reason}</p>"
|
||||
|
||||
body += "<p style='margin-top:20px;'>BookKeepro System</p>"
|
||||
body += "<p style='margin-top:20px;'>BookKeepro System</p>"
|
||||
|
||||
await send_email(
|
||||
to=admin.email,
|
||||
subject=f"Admin Return Status {payload.status.capitalize()} — BookKeepro",
|
||||
body=body,
|
||||
)
|
||||
background.add_task(
|
||||
send_email,
|
||||
to=admin_email,
|
||||
subject=f"Admin Return Status {payload.status.capitalize()} — BookKeepro",
|
||||
body=body,
|
||||
)
|
||||
|
||||
logger.info(f"User {current_user.id} {payload.status} admin doc {payload.doc_id}")
|
||||
return {"status": "notified"}
|
||||
return {"status": "notified", "review_status": doc.review_status}
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# Update Status and History
|
||||
@@ -279,13 +282,40 @@ def update_document_status(
|
||||
# Get filing deadlines for a user
|
||||
# ─────────────────────────────────────────────
|
||||
|
||||
@router.get("/my-deadlines")
|
||||
def get_my_filing_deadlines(
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
from app.models import FilingDeadline
|
||||
deadlines = db.query(FilingDeadline).filter(FilingDeadline.user_id == current_user.id).all()
|
||||
today = date.today()
|
||||
result = []
|
||||
for dl in deadlines:
|
||||
days_left = (dl.deadline_date - today).days
|
||||
result.append({
|
||||
"id": dl.id,
|
||||
"doc_type": dl.doc_type,
|
||||
"deadline_date": dl.deadline_date.isoformat(),
|
||||
"days_given": dl.days_given,
|
||||
"days_left": days_left,
|
||||
"is_overdue": days_left < 0,
|
||||
})
|
||||
return result
|
||||
|
||||
|
||||
@router.get("/deadlines/{user_id}")
|
||||
def get_filing_deadlines(
|
||||
user_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
_=Depends(require_admin),
|
||||
):
|
||||
is_admin = current_user.role in ("admin", "super_admin") or (
|
||||
hasattr(current_user.role, "value") and current_user.role.value in ("admin", "super_admin")
|
||||
)
|
||||
if not is_admin and current_user.id != user_id:
|
||||
raise HTTPException(status_code=403, detail="Not authorized to view these deadlines")
|
||||
|
||||
from app.models import FilingDeadline
|
||||
deadlines = db.query(FilingDeadline).filter(FilingDeadline.user_id == user_id).all()
|
||||
today = date.today()
|
||||
@@ -293,6 +323,7 @@ def get_filing_deadlines(
|
||||
for dl in deadlines:
|
||||
days_left = (dl.deadline_date - today).days
|
||||
result.append({
|
||||
"id": dl.id,
|
||||
"doc_type": dl.doc_type,
|
||||
"deadline_date": dl.deadline_date.isoformat(),
|
||||
"days_given": dl.days_given,
|
||||
|
||||
@@ -29,7 +29,7 @@ router = APIRouter(prefix="/api/upload", tags=["upload"])
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
FRONTEND_URL = os.getenv("FRONTEND_URL", "https://aiindiacpa.duckdns.org")
|
||||
FRONTEND_URL = os.getenv("FRONTEND_URL", "https://aicpa.duckdns.org")
|
||||
|
||||
# ─────────────────────────────────────────────
|
||||
# Local File Storage (Contabo VPS Disk)
|
||||
@@ -282,9 +282,12 @@ async def upload_admin_document(
|
||||
logger.info(f"Admin {current_user.id} uploading document for user {user_id}")
|
||||
storage_key = await upload_to_storage(file)
|
||||
|
||||
safe_doc_key = (doc_key or "").strip()[:100]
|
||||
safe_doc_label = (doc_label or "").strip()[:150]
|
||||
|
||||
record = AdminDocument(
|
||||
doc_key=doc_key,
|
||||
doc_label=doc_label,
|
||||
doc_key=safe_doc_key,
|
||||
doc_label=safe_doc_label,
|
||||
filename=file.filename,
|
||||
storage_key=storage_key,
|
||||
content_type=file.content_type,
|
||||
@@ -415,6 +418,12 @@ def delete_admin_document(
|
||||
detail="Standard admins can only manage documents for standard users"
|
||||
)
|
||||
|
||||
if doc.review_status == "approved":
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
detail="Cannot delete an approved return. Approved documents are locked."
|
||||
)
|
||||
|
||||
logger.info(f"Admin {current_user.id} deleting admin document {doc_id}")
|
||||
delete_from_storage(doc.storage_key)
|
||||
doc.deleted_at = datetime.utcnow()
|
||||
@@ -819,7 +828,7 @@ async def set_personal_review_status(
|
||||
subject="Action Required: Document Rejected — BookKeepro",
|
||||
body=f"""
|
||||
<p>Dear {owner.name or 'Client'},</p>
|
||||
<p>Your personal document <strong>{doc.doc_type}</strong> (Tax Year {doc.tax_year}) has been <strong style='color:#c0392b;'>rejected</strong> by our team.</p>
|
||||
<p>Your personal document <strong>{doc.filename}</strong> (Tax Year {doc.tax_year}) has been <strong style='color:#c0392b;'>rejected</strong> by our team.</p>
|
||||
{note_html}
|
||||
<p>Please log in to your dashboard, review the reason, and re-upload a corrected document.</p>
|
||||
<p><a href='{FRONTEND_URL}/upload-personal' style='color:#0077c8;font-weight:600;'>Re-upload Personal Documents →</a></p>
|
||||
@@ -883,7 +892,7 @@ async def set_business_review_status(
|
||||
subject="Action Required: Document Rejected — BookKeepro",
|
||||
body=f"""
|
||||
<p>Dear {owner.name or 'Client'},</p>
|
||||
<p>Your business document <strong>{doc.business_type}</strong> (Tax Year {doc.tax_year}) has been <strong style='color:#c0392b;'>rejected</strong> by our team.</p>
|
||||
<p>Your business document <strong>{doc.filename}</strong> (Tax Year {doc.tax_year}) has been <strong style='color:#c0392b;'>rejected</strong> by our team.</p>
|
||||
{note_html}
|
||||
<p>Please log in to your dashboard, review the reason, and re-upload a corrected document.</p>
|
||||
<p><a href='{FRONTEND_URL}/upload-business' style='color:#0077c8;font-weight:600;'>Re-upload Business Documents →</a></p>
|
||||
@@ -1234,17 +1243,17 @@ from app.models import RequiredDocumentTemplate
|
||||
|
||||
@router.get("/templates")
|
||||
def list_templates(
|
||||
category: str,
|
||||
tax_year: int,
|
||||
category: str | None = None,
|
||||
tax_year: int | None = None,
|
||||
db: Session = Depends(get_db),
|
||||
current_user=Depends(get_current_user),
|
||||
):
|
||||
templates = (
|
||||
db.query(RequiredDocumentTemplate)
|
||||
.filter_by(category=category, tax_year=tax_year)
|
||||
.order_by(RequiredDocumentTemplate.id.asc())
|
||||
.all()
|
||||
)
|
||||
query = db.query(RequiredDocumentTemplate)
|
||||
if category:
|
||||
query = query.filter(RequiredDocumentTemplate.category == category)
|
||||
if tax_year:
|
||||
query = query.filter(RequiredDocumentTemplate.tax_year == tax_year)
|
||||
templates = query.order_by(RequiredDocumentTemplate.id.asc()).all()
|
||||
|
||||
results = []
|
||||
for t in templates:
|
||||
|
||||
Reference in New Issue
Block a user