feat(project): projects visible to members only, admins included

Admins no longer see projects they are not owner/member of: sidebar list,
project list API, project pages, search, inbox, notifications, reminders
and trash all follow access.visible_project_ids. Only the super admin
still sees every project. Member assignment stays admin-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 14:16:36 +09:00
parent 2a01d97dd0
commit b6dc82c0b3
7 changed files with 122 additions and 26 deletions
+15 -8
View File
@@ -94,7 +94,7 @@ def _require_admin(request: Request) -> dict[str, Any]:
def _can_manage(request: Request, st: Any, user: dict[str, Any], project_id: int) -> bool:
"""프로젝트 단위 관리 권한: 관리자이거나 멤버/owner (access.can_manage_project — 지금 기준)."""
"""프로젝트 단위 관리 권한: 멤버/owner(관리자도 마찬가지), 슈퍼관리자는 전부 (access.can_manage_project — 지금 기준)."""
return access.can_manage_project(st, user, project_id)
@@ -439,10 +439,11 @@ def _nav_projects(st: Any, user: dict[str, Any], admin: bool) -> list[dict[str,
"""좌측 사이드바(project/_side.html)의 프로젝트 트리 데이터.
내 업무 · 수신함 · 프로젝트 화면이 같은 사이드바를 쓰므로 한 곳에서 만든다.
내가 owner·멤버인 프로젝트만(관리자도 마찬가지, 슈퍼관리자만 전체 — access.sees_all_projects).
"""
projects = st.list_projects(
include_archived=False,
member_email=None if admin else user["email"],
member_email=None if access.sees_all_projects(user) else user["email"],
)
return [
{
@@ -775,7 +776,7 @@ def project_page(request: Request, project_id: int) -> HTMLResponse:
)
all_projects = st.list_projects(
include_archived=False,
member_email=None if admin else user["email"],
member_email=None if access.sees_all_projects(user) else user["email"],
)
members = st.list_members(project_id=project_id)
top_projects = [p for p in all_projects if not p.get("parent_id")] # 과거 서브프로젝트 제외
@@ -919,14 +920,11 @@ def _db_or_503(request: Request) -> Any:
@router.get("/api/projects")
def api_list_projects(request: Request) -> JSONResponse:
from app.store import is_admin # noqa: WPS433
user = _require_user(request)
st = _db_or_503(request)
admin = is_admin(user)
projects = st.list_projects(
include_archived=False,
member_email=None if admin else user["email"],
member_email=None if access.sees_all_projects(user) else user["email"],
)
return JSONResponse({"projects": projects, "tree": _build_tree(projects)})
@@ -2426,11 +2424,18 @@ def trash_page(request: Request) -> HTMLResponse:
"color_palette": list(store.COLOR_PALETTE),
"project_icons": list(store.PROJECT_ICONS),
"trash_enabled": enabled,
"items": _trash_view_items(st.list_trash()) if enabled else [],
# 휴지통도 내가 볼 수 있는 프로젝트(owner·멤버, 슈퍼관리자는 전체)의 것만
"items": _trash_view_items(_visible_trash(st, user)) if enabled else [],
},
)
def _visible_trash(st: Any, user: dict[str, Any]) -> list[dict[str, Any]]:
allowed = _accessible_project_ids(st, user)
items = st.list_trash()
return items if allowed is None else [it for it in items if it.get("project_id") in allowed]
def _trash_view_items(items: list[dict[str, Any]]) -> list[dict[str, Any]]:
"""휴지통 화면용 — 삭제 시각(KST 문자열)·남은 보관 일수."""
from datetime import datetime # noqa: WPS433
@@ -2457,6 +2462,8 @@ def api_restore_trash(request: Request, trash_id: int) -> JSONResponse:
"""휴지통 항목 복구 — 관리자 전용. 업무·하위 업무·댓글 등 원래 id 그대로."""
user = _require_admin(request)
st = _db_or_503(request)
if not any(int(it["id"]) == trash_id for it in _visible_trash(st, user)):
raise HTTPException(status_code=404, detail="휴지통 항목을 찾을 수 없습니다.") # 멤버가 아닌 프로젝트 것은 없는 것처럼
try:
result = st.restore_trash(trash_id=trash_id, restored_by=user["email"])
except KeyError: