Skip to content

Commit 43003eb

Browse files
committed
Remove dead code
1 parent 05206fc commit 43003eb

File tree

2 files changed

+3
-118
lines changed

2 files changed

+3
-118
lines changed
Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,3 @@
1-
from typing import Literal
2-
3-
from fastapi import Depends, HTTPException, status
41
from fastapi.security import OAuth2PasswordBearer
5-
from sqlalchemy.ext.asyncio.session import AsyncSession
6-
7-
from futuramaapi.mixins.pydantic import DecodedTokenError
8-
from futuramaapi.repositories.session import get_async_session
9-
from futuramaapi.routers.exceptions import ModelNotFoundError
10-
from futuramaapi.routers.rest.tokens.schemas import DecodedUserToken
11-
from futuramaapi.routers.rest.users.schemas import User
122

133
_oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/api/tokens/users/auth")
14-
15-
16-
async def _get_user_from_token(
17-
sig: str,
18-
session: AsyncSession,
19-
type_: Literal["access", "refresh"],
20-
/,
21-
) -> User:
22-
try:
23-
decoded_token: DecodedUserToken = DecodedUserToken.decode(sig, allowed_type=type_)
24-
except DecodedTokenError:
25-
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) from None
26-
27-
try:
28-
user: User = await User.get(session, decoded_token.user.id)
29-
except ModelNotFoundError:
30-
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED) from None
31-
32-
return user
33-
34-
35-
async def from_signature(
36-
sig: str,
37-
session: AsyncSession = Depends(get_async_session), # noqa: B008
38-
) -> User:
39-
return await _get_user_from_token(sig, session, "access")

futuramaapi/routers/rest/users/schemas.py

Lines changed: 3 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from datetime import datetime
22
from typing import Any, ClassVar, Self
33

4-
from pydantic import EmailStr, Field, HttpUrl, PrivateAttr, SecretStr, computed_field, field_validator, model_validator
4+
from pydantic import EmailStr, Field, HttpUrl, PrivateAttr, SecretStr, model_validator
55
from sqlalchemy.ext.asyncio.session import AsyncSession
66

77
from futuramaapi.core import feature_flags, settings
@@ -11,8 +11,8 @@
1111
TemplateBodyMixin,
1212
)
1313
from futuramaapi.repositories import ModelDoesNotExistError
14-
from futuramaapi.repositories.models import AuthSessionModel, LinkModel, UserModel
15-
from futuramaapi.routers.exceptions import ModelExistsError, ModelNotFoundError
14+
from futuramaapi.repositories.models import AuthSessionModel, UserModel
15+
from futuramaapi.routers.exceptions import ModelNotFoundError
1616
from futuramaapi.routers.rest.tokens.schemas import DecodedUserToken
1717

1818

@@ -55,37 +55,6 @@ class UserPasswordError(UserBaseError): ...
5555
class UserAlreadyActivatedError(UserBaseError): ...
5656

5757

58-
class UserUpdateRequest(BaseModel):
59-
name: str | None = Field(
60-
min_length=1,
61-
max_length=64,
62-
default=None,
63-
)
64-
surname: str | None = Field(
65-
min_length=1,
66-
max_length=64,
67-
default=None,
68-
)
69-
middle_name: str | None = Field(
70-
default=None,
71-
min_length=1,
72-
max_length=64,
73-
)
74-
password: SecretStr | None = Field(
75-
default=None,
76-
min_length=8,
77-
max_length=128,
78-
)
79-
is_subscribed: bool | None = None
80-
81-
@field_validator("password", mode="after")
82-
@classmethod
83-
def hash_password(cls, value: SecretStr | None, /) -> SecretStr | None:
84-
if value is None:
85-
return None
86-
return SecretStr(cls.hasher.encode(value.get_secret_value()))
87-
88-
8958
class UserActivateRequest(BaseModel):
9059
is_confirmed: bool
9160

@@ -211,51 +180,3 @@ async def reset_password(
211180
"password": password.get_secret_value(),
212181
},
213182
)
214-
215-
216-
class Link(BaseModel, BaseModelDatabaseMixin):
217-
model: ClassVar[type[LinkModel]] = LinkModel
218-
219-
url: HttpUrl = Field(
220-
examples=[
221-
"https://example.com",
222-
],
223-
)
224-
shortened: str = Field(
225-
examples=[
226-
"LWlWthH",
227-
],
228-
)
229-
created_at: datetime
230-
counter: int
231-
path_prefix: ClassVar[str] = "s"
232-
233-
@computed_field( # type: ignore[misc]
234-
examples=[
235-
settings.build_url(path=f"{path_prefix}/LWlWthH", is_static=False).unicode_string(),
236-
],
237-
return_type=str,
238-
)
239-
@property
240-
def shortened_url(self) -> str:
241-
return settings.build_url(path=f"{self.path_prefix}/{self.shortened}", is_static=False).unicode_string()
242-
243-
@classmethod
244-
async def create(
245-
cls,
246-
session: AsyncSession,
247-
data: BaseModel,
248-
/,
249-
extra_fields: dict[
250-
str,
251-
Any,
252-
]
253-
| None = None,
254-
) -> Self:
255-
for _ in range(3):
256-
try:
257-
return await super().create(session, data, extra_fields=extra_fields)
258-
except ModelExistsError:
259-
continue
260-
261-
raise ModelExistsError() from None

0 commit comments

Comments
 (0)