jogosultsági szintek RBAC beállítva tesztelve

This commit is contained in:
Roo
2026-06-25 20:41:49 +00:00
parent 52011606ff
commit 36109fc722
242 changed files with 8672 additions and 2237 deletions

View File

@@ -33,7 +33,8 @@ router = APIRouter()
@router.get("/health-monitor", tags=["Sentinel Monitoring"])
async def get_system_health(
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:view")),
):
stats = {}
@@ -63,7 +64,8 @@ async def get_system_health(
@router.get("/pending-actions", response_model=List[Any], tags=["Sentinel Security"])
async def list_pending_actions(
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:view")),
):
stmt = select(PendingAction).where(PendingAction.status == ActionStatus.pending)
result = await db.execute(stmt)
@@ -73,7 +75,8 @@ async def list_pending_actions(
async def approve_action(
action_id: int,
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:edit")),
):
try:
await security_service.approve_action(db, admin.id, action_id)
@@ -84,7 +87,8 @@ async def approve_action(
@router.get("/parameters", tags=["Dynamic Configuration"])
async def list_all_parameters(
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:view")),
):
result = await db.execute(select(SystemParameter))
return result.scalars().all()
@@ -93,7 +97,8 @@ async def list_all_parameters(
async def set_parameter(
config: ConfigUpdate,
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:edit")),
):
query = text("""
INSERT INTO system.system_parameters (key, value, scope_level, scope_id, category, last_modified_by)
@@ -124,7 +129,8 @@ async def get_scoped_parameter(
region_id: Optional[str] = None,
country_code: Optional[str] = None,
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:view")),
):
"""
Hierarchikus paraméterlekérdezés a következő prioritással:
@@ -143,7 +149,8 @@ async def get_scoped_parameter(
@router.post("/translations/sync", tags=["System Utilities"])
async def sync_translations_to_json(
db: AsyncSession = Depends(deps.get_db),
admin: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:edit")),
):
await TranslationService.export_to_json(db)
return {"message": "JSON fájlok frissítve."}
@@ -151,7 +158,8 @@ async def sync_translations_to_json(
@router.get("/ping", tags=["Admin Test"])
async def admin_ping(
current_user: User = Depends(deps.get_current_admin)
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("settings:view")),
):
"""
Egyszerű ping végpont admin jogosultság ellenőrzéséhez.
@@ -166,8 +174,9 @@ async def admin_ping(
async def ban_user(
user_id: int,
reason: str = Body(..., embed=True),
current_admin: User = Depends(deps.get_current_admin),
db: AsyncSession = Depends(deps.get_db)
db: AsyncSession = Depends(deps.get_db),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("user:manage")),
):
"""
Felhasználó tiltása (Ban Hammer).
@@ -205,7 +214,7 @@ async def ban_user(
# 4. Audit log létrehozása
audit_log = SecurityAuditLog(
user_id=current_admin.id,
user_id=current_user.id,
action="ban_user",
target_user_id=user_id,
details=f"User banned. Reason: {reason}",
@@ -226,8 +235,9 @@ async def ban_user(
@router.post("/marketplace/services/{staging_id}/approve", tags=["Marketplace Moderation"])
async def approve_staged_service(
staging_id: int,
current_admin: User = Depends(deps.get_current_admin),
db: AsyncSession = Depends(deps.get_db)
db: AsyncSession = Depends(deps.get_db),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("moderation:manage")),
):
"""
Szerviz jóváhagyása a Piactéren (Kék Pipa).
@@ -255,7 +265,7 @@ async def approve_staged_service(
# Audit log
audit_log = SecurityAuditLog(
user_id=current_admin.id,
user_id=current_user.id,
action="approve_service",
target_staging_id=staging_id,
details=f"Service staging approved: {staging.service_name}",
@@ -294,8 +304,9 @@ class PenaltyRequest(BaseModel):
async def trigger_ai_pipeline(
service_id: int,
background_tasks: BackgroundTasks,
current_admin: User = Depends(deps.get_current_admin),
db: AsyncSession = Depends(deps.get_db)
db: AsyncSession = Depends(deps.get_db),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("services:manage")),
):
"""
AI Pipeline manuális indítása egy adott szerviz profilra.
@@ -318,7 +329,7 @@ async def trigger_ai_pipeline(
# Audit log
audit_log = SecurityAuditLog(
user_id=current_admin.id,
user_id=current_user.id,
action="trigger_ai_pipeline",
target_service_id=service_id,
details=f"AI pipeline manually triggered for service {service_id}",
@@ -354,8 +365,9 @@ async def run_validation_pipeline(profile_id: int):
async def update_service_location(
service_id: int,
location: LocationUpdate,
current_admin: User = Depends(deps.get_current_admin),
db: AsyncSession = Depends(deps.get_db)
db: AsyncSession = Depends(deps.get_db),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("services:manage")),
):
"""
Szerviz térképes mozgatása (Koordináta frissítés).
@@ -379,7 +391,7 @@ async def update_service_location(
# Audit log
audit_log = SecurityAuditLog(
user_id=current_admin.id,
user_id=current_user.id,
action="update_service_location",
target_service_id=service_id,
details=f"Service location updated to lat={location.latitude}, lon={location.longitude}",
@@ -401,8 +413,9 @@ async def update_service_location(
async def apply_gamification_penalty(
user_id: int,
penalty: PenaltyRequest,
current_admin: User = Depends(deps.get_current_admin),
db: AsyncSession = Depends(deps.get_db)
db: AsyncSession = Depends(deps.get_db),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("gamification:manage")),
):
"""
Gamification büntetés kiosztása egy felhasználónak.
@@ -446,7 +459,7 @@ async def apply_gamification_penalty(
# Audit log
audit_log = SecurityAuditLog(
user_id=current_admin.id,
user_id=current_user.id,
action="apply_gamification_penalty",
target_user_id=user_id,
details=f"Gamification penalty applied: level change {penalty.penalty_level}, reason: {penalty.reason}",
@@ -485,7 +498,8 @@ async def list_users(
is_active: Optional[bool] = Query(None, description="Aktív státusz szűrés"),
is_deleted: Optional[bool] = Query(None, description="Törölt státusz szűrés"),
db: AsyncSession = Depends(deps.get_db),
current_admin: User = Depends(deps.get_current_admin),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("user:view")),
):
"""
Felhasználók listázása lapozással és célzott kereséssel.
@@ -646,7 +660,8 @@ async def list_users(
async def bulk_user_action(
request: BulkActionRequest,
db: AsyncSession = Depends(deps.get_db),
current_admin: User = Depends(deps.get_current_admin),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("user:manage")),
):
"""
Csoportos műveletek felhasználókon.
@@ -658,7 +673,7 @@ async def bulk_user_action(
- **restore**: Lágy törlés visszaállítása (is_deleted=False, deleted_at=None). Rang >= 90 (Admin) szükséges.
- **hard_delete**: Végleges törlés az adatbázisból. Rang >= 100 (Superadmin) szükséges!
"""
role_key = current_admin.role.value.upper() if hasattr(current_admin.role, "value") else str(current_admin.role).upper()
role_key = current_user.role.value.upper() if hasattr(current_user.role, "value") else str(current_user.role).upper()
from app.core.security import DEFAULT_RANK_MAP
admin_rank = DEFAULT_RANK_MAP.get(role_key, 0)
@@ -698,7 +713,7 @@ async def bulk_user_action(
affected_count = 0
for user in users:
if user.role == UserRole.SUPERADMIN and user.id != current_admin.id:
if user.role == UserRole.SUPERADMIN and user.id != current_user.id:
continue
if request.action == "ban":
@@ -717,7 +732,7 @@ async def bulk_user_action(
affected_count += 1
audit_log = SecurityAuditLog(
user_id=current_admin.id,
user_id=current_user.id,
action=f"bulk_{request.action}",
details=f"Bulk action '{request.action}' on {affected_count} users. IDs: {request.user_ids}",
is_critical=(request.action in ("hard_delete", "ban")),
@@ -745,7 +760,8 @@ async def search_organizations(
name: str = Query(..., min_length=2, description="Cégnév vagy garázsnév keresése (ILIKE)"),
limit: int = Query(20, ge=1, le=100, description="Maximum találatok száma"),
db: AsyncSession = Depends(deps.get_db),
current_user: User = Depends(deps.get_current_admin),
current_user: User = Depends(deps.get_current_active_user),
_ = Depends(deps.RequirePermission("org:view")),
):
"""
🔍 Szervezetek / Garázsok keresése név alapján.