chore(quality): apply ruff autofixes and formatting (223 fixes, regression-free: 118/118 tests pass)
This commit is contained in:
+12
-6
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -14,9 +12,17 @@ from app.models.user import User
|
||||
from app.schemas.account import AccountCreate, AccountOut, AccountUpdate
|
||||
from app.services.account_service import (
|
||||
create_account as svc_create_account,
|
||||
)
|
||||
from app.services.account_service import (
|
||||
get_account as svc_get_account,
|
||||
)
|
||||
from app.services.account_service import (
|
||||
list_accounts as svc_list_accounts,
|
||||
)
|
||||
from app.services.account_service import (
|
||||
soft_delete_account as svc_soft_delete_account,
|
||||
)
|
||||
from app.services.account_service import (
|
||||
update_account as svc_update_account,
|
||||
)
|
||||
|
||||
@@ -48,10 +54,10 @@ async def create_account(
|
||||
async def list_accounts(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
industry: Optional[Industry] = None,
|
||||
size: Optional[AccountSize] = None,
|
||||
owner_id: Optional[int] = None,
|
||||
q: Optional[str] = None,
|
||||
industry: Industry | None = None,
|
||||
size: AccountSize | None = None,
|
||||
owner_id: int | None = None,
|
||||
q: str | None = None,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> list[AccountOut]:
|
||||
|
||||
+20
-18
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -19,11 +17,23 @@ from app.schemas.activity import (
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
NoParentException,
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
complete_activity as svc_complete_activity,
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
create_activity as svc_create_activity,
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
get_activity as svc_get_activity,
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
list_activities as svc_list_activities,
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
soft_delete_activity as svc_soft_delete_activity,
|
||||
)
|
||||
from app.services.activity_service import (
|
||||
update_activity as svc_update_activity,
|
||||
)
|
||||
|
||||
@@ -58,10 +68,10 @@ async def create_activity(
|
||||
async def list_activities(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
type: Optional[ActivityType] = None,
|
||||
owner_id: Optional[int] = None,
|
||||
overdue: Optional[bool] = None,
|
||||
completed: Optional[bool] = None,
|
||||
type: ActivityType | None = None,
|
||||
owner_id: int | None = None,
|
||||
overdue: bool | None = None,
|
||||
completed: bool | None = None,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> list[ActivityOut]:
|
||||
@@ -88,9 +98,7 @@ async def get_activity(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> ActivityOut:
|
||||
activity = await svc_get_activity(
|
||||
db, activity_id, org_id=current_user.org_id
|
||||
)
|
||||
activity = await svc_get_activity(db, activity_id, org_id=current_user.org_id)
|
||||
if activity is None:
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
return ActivityOut.model_validate(activity)
|
||||
@@ -107,9 +115,7 @@ async def update_activity(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> ActivityOut:
|
||||
activity = await svc_get_activity(
|
||||
db, activity_id, org_id=current_user.org_id
|
||||
)
|
||||
activity = await svc_get_activity(db, activity_id, org_id=current_user.org_id)
|
||||
if activity is None:
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
try:
|
||||
@@ -130,9 +136,7 @@ async def complete_activity(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> ActivityOut:
|
||||
activity = await svc_get_activity(
|
||||
db, activity_id, org_id=current_user.org_id
|
||||
)
|
||||
activity = await svc_get_activity(db, activity_id, org_id=current_user.org_id)
|
||||
if activity is None:
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
updated = await svc_complete_activity(db, activity, payload)
|
||||
@@ -150,9 +154,7 @@ async def delete_activity(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> Response:
|
||||
activity = await svc_get_activity(
|
||||
db, activity_id, org_id=current_user.org_id
|
||||
)
|
||||
activity = await svc_get_activity(db, activity_id, org_id=current_user.org_id)
|
||||
if activity is None:
|
||||
raise HTTPException(status_code=404, detail="Activity not found")
|
||||
await svc_soft_delete_activity(db, activity)
|
||||
|
||||
+2
-4
@@ -7,8 +7,8 @@ from fastapi.security import OAuth2PasswordRequestForm
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.config import get_settings
|
||||
from app.core.deps import get_current_user
|
||||
from app.core.db import get_db
|
||||
from app.core.deps import get_current_user
|
||||
from app.models.user import User
|
||||
from app.schemas.auth import (
|
||||
LogoutResponse,
|
||||
@@ -127,9 +127,7 @@ async def refresh(
|
||||
from app.core.security import create_access_token
|
||||
|
||||
role_str = (
|
||||
current_user.role.value
|
||||
if hasattr(current_user.role, "value")
|
||||
else str(current_user.role)
|
||||
current_user.role.value if hasattr(current_user.role, "value") else str(current_user.role)
|
||||
)
|
||||
token = create_access_token(current_user.id, current_user.org_id, role_str)
|
||||
return TokenResponse(
|
||||
|
||||
+13
-5
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -13,10 +11,20 @@ from app.models.user import User
|
||||
from app.schemas.contact import ContactCreate, ContactOut, ContactUpdate
|
||||
from app.services.contact_service import (
|
||||
InvalidAccount,
|
||||
)
|
||||
from app.services.contact_service import (
|
||||
create_contact as svc_create_contact,
|
||||
)
|
||||
from app.services.contact_service import (
|
||||
get_contact as svc_get_contact,
|
||||
)
|
||||
from app.services.contact_service import (
|
||||
list_contacts as svc_list_contacts,
|
||||
)
|
||||
from app.services.contact_service import (
|
||||
soft_delete_contact as svc_soft_delete_contact,
|
||||
)
|
||||
from app.services.contact_service import (
|
||||
update_contact as svc_update_contact,
|
||||
)
|
||||
|
||||
@@ -51,9 +59,9 @@ async def create_contact(
|
||||
async def list_contacts(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
account_id: Optional[int] = None,
|
||||
owner_id: Optional[int] = None,
|
||||
q: Optional[str] = None,
|
||||
account_id: int | None = None,
|
||||
owner_id: int | None = None,
|
||||
q: str | None = None,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> list[ContactOut]:
|
||||
|
||||
@@ -40,9 +40,7 @@ async def get_activity_feed_endpoint(
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> list[ActivityFeedItem]:
|
||||
activities = await get_activity_feed(
|
||||
db, org_id=current_user.org_id, limit=limit
|
||||
)
|
||||
activities = await get_activity_feed(db, org_id=current_user.org_id, limit=limit)
|
||||
return [ActivityFeedItem.model_validate(a) for a in activities]
|
||||
|
||||
|
||||
|
||||
+17
-7
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -20,12 +18,24 @@ from app.schemas.deal import (
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
InvalidAccount,
|
||||
create_deal as svc_create_deal,
|
||||
get_deal as svc_get_deal,
|
||||
get_pipeline,
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
create_deal as svc_create_deal,
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
get_deal as svc_get_deal,
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
list_deals as svc_list_deals,
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
soft_delete_deal as svc_soft_delete_deal,
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
update_deal as svc_update_deal,
|
||||
)
|
||||
from app.services.deal_service import (
|
||||
update_stage as svc_update_stage,
|
||||
)
|
||||
|
||||
@@ -60,9 +70,9 @@ async def create_deal(
|
||||
async def list_deals(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
stage: Optional[DealStage] = None,
|
||||
owner_id: Optional[int] = None,
|
||||
account_id: Optional[int] = None,
|
||||
stage: DealStage | None = None,
|
||||
owner_id: int | None = None,
|
||||
account_id: int | None = None,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> list[DealOut]:
|
||||
|
||||
+12
-4
@@ -2,8 +2,6 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Query, Response, status
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
@@ -14,10 +12,20 @@ from app.models.user import User
|
||||
from app.schemas.note import NoteCreate, NoteOut, NoteUpdate
|
||||
from app.services.note_service import (
|
||||
InvalidParent,
|
||||
)
|
||||
from app.services.note_service import (
|
||||
create_note as svc_create_note,
|
||||
)
|
||||
from app.services.note_service import (
|
||||
get_note as svc_get_note,
|
||||
)
|
||||
from app.services.note_service import (
|
||||
list_notes as svc_list_notes,
|
||||
)
|
||||
from app.services.note_service import (
|
||||
soft_delete_note as svc_soft_delete_note,
|
||||
)
|
||||
from app.services.note_service import (
|
||||
update_note as svc_update_note,
|
||||
)
|
||||
|
||||
@@ -52,8 +60,8 @@ async def create_note(
|
||||
async def list_notes(
|
||||
skip: int = Query(0, ge=0),
|
||||
limit: int = Query(20, ge=1, le=100),
|
||||
parent_type: Optional[NoteParentType] = None,
|
||||
parent_id: Optional[int] = None,
|
||||
parent_type: NoteParentType | None = None,
|
||||
parent_id: int | None = None,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> list[NoteOut]:
|
||||
|
||||
@@ -13,9 +13,17 @@ from app.services.tag_service import (
|
||||
DuplicateTagLink,
|
||||
InvalidParent,
|
||||
TagNotFound,
|
||||
)
|
||||
from app.services.tag_service import (
|
||||
create_tag as svc_create_tag,
|
||||
)
|
||||
from app.services.tag_service import (
|
||||
link_tag as svc_link_tag,
|
||||
)
|
||||
from app.services.tag_service import (
|
||||
list_tags as svc_list_tags,
|
||||
)
|
||||
from app.services.tag_service import (
|
||||
unlink_tag as svc_unlink_tag,
|
||||
)
|
||||
|
||||
|
||||
+4
-12
@@ -42,9 +42,7 @@ async def update_me(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> UserOut:
|
||||
"""A user can update their own profile, but not their role."""
|
||||
updated = await user_service.update_user_profile(
|
||||
db, current_user, payload, is_admin=False
|
||||
)
|
||||
updated = await user_service.update_user_profile(db, current_user, payload, is_admin=False)
|
||||
return UserOut.model_validate(updated)
|
||||
|
||||
|
||||
@@ -86,9 +84,7 @@ async def create_user(
|
||||
) -> UserOut:
|
||||
"""Admin creates a new user in the same org."""
|
||||
try:
|
||||
new_user = await user_service.create_user_as_admin(
|
||||
db, payload, org_id=current_user.org_id
|
||||
)
|
||||
new_user = await user_service.create_user_as_admin(db, payload, org_id=current_user.org_id)
|
||||
except user_service.EmailAlreadyTaken as e:
|
||||
raise HTTPException(status_code=409, detail=str(e)) from e
|
||||
return UserOut.model_validate(new_user)
|
||||
@@ -124,9 +120,7 @@ async def update_user(
|
||||
if target.org_id != current_user.org_id:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
updated = await user_service.update_user_profile(
|
||||
db, target, payload, is_admin=is_admin
|
||||
)
|
||||
updated = await user_service.update_user_profile(db, target, payload, is_admin=is_admin)
|
||||
return UserOut.model_validate(updated)
|
||||
|
||||
|
||||
@@ -143,9 +137,7 @@ async def delete_user(
|
||||
) -> Response:
|
||||
"""Sets deleted_at timestamp. The record stays in the DB for audit purposes."""
|
||||
if current_user.id == user_id:
|
||||
raise HTTPException(
|
||||
status_code=400, detail="You cannot delete your own account"
|
||||
)
|
||||
raise HTTPException(status_code=400, detail="You cannot delete your own account")
|
||||
|
||||
target = await user_service.get_user_by_id(db, user_id)
|
||||
if target is None or target.org_id != current_user.org_id:
|
||||
|
||||
Reference in New Issue
Block a user