Skip to content

Commit

Permalink
♻️ Remove unused code (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick91 authored Dec 6, 2024
1 parent c77cf15 commit 0da22f5
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 244 deletions.
11 changes: 0 additions & 11 deletions backend/app/api/deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,6 @@ def get_current_user(session: SessionDep, token: TokenDep) -> User:
CurrentUser = Annotated[User, Depends(get_current_user)]


def get_first_superuser(current_user: CurrentUser) -> User:
settings = MainSettings.get_settings()
if current_user.email != settings.FIRST_SUPERUSER:
raise HTTPException(
status_code=403,
detail="The user doesn't have enough permissions to execute this action",
)

return current_user


def _rate_limit_per_minute(request: Request, redis: RedisDep, limit: int) -> None:
host_ip = request.client and request.client.host or "unknown"
current_path = request.url.path
Expand Down
34 changes: 2 additions & 32 deletions backend/app/api/routes/invitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@
from datetime import timedelta
from typing import Any, TypeVar

from fastapi import APIRouter, Depends, HTTPException
from fastapi.responses import HTMLResponse
from fastapi import APIRouter, HTTPException
from sqlmodel import col, func, select
from sqlmodel.sql.expression import SelectOfScalar

from app.api.deps import CurrentUser, SessionDep, get_first_superuser
from app.api.deps import CurrentUser, SessionDep
from app.api.utils.invitations import (
generate_invitation_token,
generate_invitation_token_email,
send_invitation_email,
verify_invitation_token,
)
Expand Down Expand Up @@ -288,33 +285,6 @@ def verify_invitation(
return invitation


@router.post(
"/team-invitation-html-content/{invitation_id}",
dependencies=[Depends(get_first_superuser)],
response_class=HTMLResponse,
)
def invitation_html_content(invitation_id: uuid.UUID, session: SessionDep) -> Any:
"""
HTML Content for Invitation email
"""
invitation = session.get(Invitation, invitation_id)
if not invitation:
raise HTTPException(status_code=404, detail="Invitation not found")
token = generate_invitation_token(invitation_id=invitation_id)
email_to = invitation.email
email_from = invitation.sender.email
email_data = generate_invitation_token_email(
team_name=invitation.team.name,
email_to=email_to,
email_from=email_from,
token=token,
)

return HTMLResponse(
content=email_data.html_content, headers={"subject:": email_data.subject}
)


@router.delete("/{inv_id}", response_model=Message)
def delete_invitation(
session: SessionDep,
Expand Down
28 changes: 0 additions & 28 deletions backend/app/api/routes/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from typing import Annotated, Any, Literal

from fastapi import APIRouter, Depends, Form, HTTPException, Request
from fastapi.responses import HTMLResponse
from fastapi.security import OAuth2PasswordRequestForm
from pydantic import BaseModel

Expand All @@ -11,7 +10,6 @@
CurrentUser,
RedisDep,
SessionDep,
get_first_superuser,
rate_limit_5_per_minute,
rate_limit_20_per_minute,
)
Expand Down Expand Up @@ -266,29 +264,3 @@ def reset_password(session: SessionDep, body: NewPassword) -> Message:
session.add(user)
session.commit()
return Message(message="Password updated successfully")


@router.post(
"/password-recovery-html-content/{email}",
dependencies=[Depends(get_first_superuser)],
response_class=HTMLResponse,
)
def recover_password_html_content(email: str, session: SessionDep) -> Any:
"""
HTML Content for Password Recovery
"""
user = crud.get_user_by_email(session=session, email=email)

if not user:
raise HTTPException(
status_code=404,
detail="The user with this username does not exist in the system.",
)
password_reset_token = generate_password_reset_token(email=email)
email_data = generate_reset_password_email(
email_to=user.email, email=email, token=password_reset_token
)

return HTMLResponse(
content=email_data.html_content, headers={"subject:": email_data.subject}
)
26 changes: 0 additions & 26 deletions backend/app/api/routes/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@

import emailable # type: ignore
from fastapi import APIRouter, Depends, HTTPException
from fastapi.responses import HTMLResponse
from sqlmodel import select

from app import crud
from app.api.deps import (
CurrentUser,
SessionDep,
get_first_superuser,
rate_limit_5_per_minute,
)
from app.api.utils.teams import generate_team_slug_name
Expand Down Expand Up @@ -236,30 +234,6 @@ def verify_email_token(session: SessionDep, payload: EmailVerificationToken) ->
return Message(message="Email successfully verified")


@router.post(
"/verify-email-html-content/{email}",
dependencies=[Depends(get_first_superuser)],
response_class=HTMLResponse,
)
def verify_email_html_content(email: str, session: SessionDep) -> Any:
"""
HTML Content for Email verification email
"""
user = crud.get_user_by_email(session=session, email=email)

if not user:
raise HTTPException(
status_code=404,
detail="The user with this username does not exist in the system.",
)

token = generate_verification_email_token(email=email)
email_data = generate_verification_email(email_to=email, token=token)
return HTMLResponse(
content=email_data.html_content, headers={"subject:": email_data.subject}
)


@router.post("/waiting-list", dependencies=[Depends(rate_limit_5_per_minute)])
def add_to_waiting_list(session: SessionDep, user_in: WaitingListUserCreate) -> Message:
"""
Expand Down
25 changes: 2 additions & 23 deletions backend/app/api/routes/utils.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,11 @@
from fastapi import APIRouter, Depends
from fastapi import APIRouter
from pydantic import BaseModel
from pydantic.networks import EmailStr

from app.api.deps import RedisDep, get_first_superuser
from app.models import Message
from app.utils import generate_test_email, send_email
from app.api.deps import RedisDep

router = APIRouter()


@router.post(
"/test-email/",
dependencies=[Depends(get_first_superuser)],
status_code=201,
)
def test_email(email_to: EmailStr) -> Message:
"""
Test emails.
"""
email_data = generate_test_email(email_to=email_to)
send_email(
email_to=email_to,
subject=email_data.subject,
html_content=email_data.html_content,
)
return Message(message="Test email sent")


class HealthCheckResponse(BaseModel):
redis: bool

Expand Down
100 changes: 0 additions & 100 deletions frontend/src/client/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ import type {
InvitationsAcceptInvitationResponse,
InvitationsVerifyInvitationData,
InvitationsVerifyInvitationResponse,
InvitationsInvitationHtmlContentData,
InvitationsInvitationHtmlContentResponse,
InvitationsDeleteInvitationData,
InvitationsDeleteInvitationResponse,
LoginLoginAccessTokenData,
Expand All @@ -65,8 +63,6 @@ import type {
LoginRecoverPasswordResponse,
LoginResetPasswordData,
LoginResetPasswordResponse,
LoginRecoverPasswordHtmlContentData,
LoginRecoverPasswordHtmlContentResponse,
PrivateCreateUserData,
PrivateCreateUserResponse,
PrivateCreateTeamData,
Expand Down Expand Up @@ -107,12 +103,8 @@ import type {
UsersRegisterUserResponse,
UsersVerifyEmailTokenData,
UsersVerifyEmailTokenResponse,
UsersVerifyEmailHtmlContentData,
UsersVerifyEmailHtmlContentResponse,
UsersAddToWaitingListData,
UsersAddToWaitingListResponse,
UtilsTestEmailData,
UtilsTestEmailResponse,
UtilsHealthCheckResponse,
} from "./types.gen"

Expand Down Expand Up @@ -647,29 +639,6 @@ export class InvitationsService {
})
}

/**
* Invitation Html Content
* HTML Content for Invitation email
* @param data The data for the request.
* @param data.invitationId
* @returns string Successful Response
* @throws ApiError
*/
public static invitationHtmlContent(
data: InvitationsInvitationHtmlContentData,
): CancelablePromise<InvitationsInvitationHtmlContentResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/invitations/team-invitation-html-content/{invitation_id}",
path: {
invitation_id: data.invitationId,
},
errors: {
422: "Validation Error",
},
})
}

/**
* Delete Invitation
* Delete an invitation.
Expand Down Expand Up @@ -861,29 +830,6 @@ export class LoginService {
},
})
}

/**
* Recover Password Html Content
* HTML Content for Password Recovery
* @param data The data for the request.
* @param data.email
* @returns string Successful Response
* @throws ApiError
*/
public static recoverPasswordHtmlContent(
data: LoginRecoverPasswordHtmlContentData,
): CancelablePromise<LoginRecoverPasswordHtmlContentResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/password-recovery-html-content/{email}",
path: {
email: data.email,
},
errors: {
422: "Validation Error",
},
})
}
}

export class PrivateService {
Expand Down Expand Up @@ -1362,29 +1308,6 @@ export class UsersService {
})
}

/**
* Verify Email Html Content
* HTML Content for Email verification email
* @param data The data for the request.
* @param data.email
* @returns string Successful Response
* @throws ApiError
*/
public static verifyEmailHtmlContent(
data: UsersVerifyEmailHtmlContentData,
): CancelablePromise<UsersVerifyEmailHtmlContentResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/users/verify-email-html-content/{email}",
path: {
email: data.email,
},
errors: {
422: "Validation Error",
},
})
}

/**
* Add To Waiting List
* Add user to waiting list
Expand All @@ -1409,29 +1332,6 @@ export class UsersService {
}

export class UtilsService {
/**
* Test Email
* Test emails.
* @param data The data for the request.
* @param data.emailTo
* @returns Message Successful Response
* @throws ApiError
*/
public static testEmail(
data: UtilsTestEmailData,
): CancelablePromise<UtilsTestEmailResponse> {
return __request(OpenAPI, {
method: "POST",
url: "/api/v1/utils/test-email/",
query: {
email_to: data.emailTo,
},
errors: {
422: "Validation Error",
},
})
}

/**
* Health Check
* Health check.
Expand Down
24 changes: 0 additions & 24 deletions frontend/src/client/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,6 @@ export type InvitationsVerifyInvitationData = {

export type InvitationsVerifyInvitationResponse = InvitationPublic

export type InvitationsInvitationHtmlContentData = {
invitationId: string
}

export type InvitationsInvitationHtmlContentResponse = string

export type InvitationsDeleteInvitationData = {
invId: string
}
Expand Down Expand Up @@ -520,12 +514,6 @@ export type LoginResetPasswordData = {

export type LoginResetPasswordResponse = Message

export type LoginRecoverPasswordHtmlContentData = {
email: string
}

export type LoginRecoverPasswordHtmlContentResponse = string

export type PrivateCreateUserData = {
requestBody: CreateUser
}
Expand Down Expand Up @@ -653,22 +641,10 @@ export type UsersVerifyEmailTokenData = {

export type UsersVerifyEmailTokenResponse = unknown

export type UsersVerifyEmailHtmlContentData = {
email: string
}

export type UsersVerifyEmailHtmlContentResponse = string

export type UsersAddToWaitingListData = {
requestBody: WaitingListUserCreate
}

export type UsersAddToWaitingListResponse = Message

export type UtilsTestEmailData = {
emailTo: string
}

export type UtilsTestEmailResponse = Message

export type UtilsHealthCheckResponse = HealthCheckResponse

0 comments on commit 0da22f5

Please sign in to comment.