feat: 사용자 관리 및 권한 시스템 구현
- 관리자 전용 사용자 관리 페이지 추가 - 사용자 추가/삭제 기능 (한글 ID 지원) - 비밀번호 변경 기능 - 권한별 메뉴 접근 제한 - 관리자: 모든 메뉴 접근 가능 - 일반 사용자: 일일공수, 부적합등록/조회만 가능 - 이미지 없이 부적합 등록 가능 - 목록 관리에서 이미지 수정 기능 - 작업 시간 확인 버튼 개선 - 부적합 조회 페이지 간소화 (시간순 나열)
This commit is contained in:
Binary file not shown.
@@ -32,6 +32,10 @@ class UserUpdate(BaseModel):
|
||||
role: Optional[UserRole] = None
|
||||
is_active: Optional[bool] = None
|
||||
|
||||
class PasswordChange(BaseModel):
|
||||
current_password: str
|
||||
new_password: str
|
||||
|
||||
class User(UserBase):
|
||||
id: int
|
||||
is_active: bool
|
||||
|
||||
Binary file not shown.
@@ -112,20 +112,39 @@ async def update_user(
|
||||
db.refresh(db_user)
|
||||
return db_user
|
||||
|
||||
@router.delete("/users/{user_id}")
|
||||
@router.delete("/users/{username}")
|
||||
async def delete_user(
|
||||
user_id: int,
|
||||
username: str,
|
||||
current_admin: User = Depends(get_current_admin),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
db_user = db.query(User).filter(User.id == user_id).first()
|
||||
db_user = db.query(User).filter(User.username == username).first()
|
||||
if not db_user:
|
||||
raise HTTPException(status_code=404, detail="User not found")
|
||||
|
||||
# 관리자는 삭제 불가
|
||||
if db_user.role == UserRole.ADMIN:
|
||||
raise HTTPException(status_code=400, detail="Cannot delete admin user")
|
||||
# hyungi 계정은 삭제 불가
|
||||
if db_user.username == "hyungi":
|
||||
raise HTTPException(status_code=400, detail="Cannot delete primary admin user")
|
||||
|
||||
db.delete(db_user)
|
||||
db.commit()
|
||||
return {"detail": "User deleted successfully"}
|
||||
|
||||
@router.post("/change-password")
|
||||
async def change_password(
|
||||
password_change: schemas.PasswordChange,
|
||||
current_user: User = Depends(get_current_user),
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
# 현재 비밀번호 확인
|
||||
if not verify_password(password_change.current_password, current_user.hashed_password):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="Incorrect current password"
|
||||
)
|
||||
|
||||
# 새 비밀번호 설정
|
||||
current_user.hashed_password = get_password_hash(password_change.new_password)
|
||||
db.commit()
|
||||
|
||||
return {"detail": "Password changed successfully"}
|
||||
|
||||
Reference in New Issue
Block a user