We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9bc712b commit 7829134Copy full SHA for 7829134
.pre-commit-config.yaml
@@ -39,13 +39,13 @@ repos:
39
- id: chmod
40
args: ['644']
41
exclude_types: [shell]
42
- exclude: ^(.*__main__\.py|syncmaster/server/scripts/export_openapi_schema\.py)$
+ exclude: ^(.*__main__\.py|syncmaster/server/scripts/.*\.py)$
43
44
args: ['755']
45
types: [shell]
46
47
48
- files: ^(.*__main__\.py|syncmaster/server/scripts/export_openapi_schema\.py)$
+ files: ^(.*__main__\.py|syncmaster/server/scripts/.*\.py)$
49
- id: insert-license
50
types: [python]
51
exclude: ^(syncmaster/server/dependencies/stub.py|docs/.*\.py|tests/.*\.py)$
pyproject.toml
@@ -456,6 +456,7 @@ per-file-ignores = [
456
# WPS102 Found incorrect module name pattern
457
# WPS432 Found magic number: 256
458
"*migrations/*.py:WPS102,WPS432",
459
+ "*db/models/*.py:WPS102,WPS432",
460
# WPS237 Found a too complex `f` string
461
"*exceptions/*.py:WPS237",
462
"*exceptions/__init__.py:F40,WPS410",
syncmaster/db/migrations/versions/2023-11-23_0001_create_user_table.py
@@ -22,7 +22,7 @@ def upgrade():
22
"user",
23
sa.Column("id", sa.BigInteger(), nullable=False),
24
sa.Column("username", sa.String(length=256), nullable=False),
25
- sa.Column("email", sa.String(length=256), nullable=False),
+ sa.Column("email", sa.String(length=256), nullable=True),
26
sa.Column("first_name", sa.String(length=256), nullable=True),
27
sa.Column("last_name", sa.String(length=256), nullable=True),
28
sa.Column("middle_name", sa.String(length=256), nullable=True),
@@ -32,7 +32,6 @@ def upgrade():
32
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
33
sa.Column("is_deleted", sa.Boolean(), nullable=False),
34
sa.PrimaryKeyConstraint("id", name=op.f("pk__user")),
35
- sa.UniqueConstraint("email", name=op.f("uq__user__email")),
36
)
37
op.create_index(op.f("ix__user__username"), "user", ["username"], unique=True)
38
syncmaster/db/models/user.py
@@ -12,12 +12,12 @@
12
class User(Base, TimestampMixin, DeletableMixin):
13
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
14
username: Mapped[str] = mapped_column(String(256), nullable=False, unique=True, index=True)
15
- email: Mapped[str] = mapped_column(String(256), nullable=False, unique=True)
16
- first_name: Mapped[str] = mapped_column(String(256), nullable=True)
17
- last_name: Mapped[str] = mapped_column(String(256), nullable=True)
18
- middle_name: Mapped[str] = mapped_column(String(256), nullable=True)
+ email: Mapped[str | None] = mapped_column(String(256), nullable=True)
+ first_name: Mapped[str | None] = mapped_column(String(256), nullable=True)
+ last_name: Mapped[str | None] = mapped_column(String(256), nullable=True)
+ middle_name: Mapped[str | None] = mapped_column(String(256), nullable=True)
19
is_superuser: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
20
- is_active: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
+ is_active: Mapped[bool] = mapped_column(Boolean, default=True, nullable=False)
21
def __repr__(self) -> str:
return f"User(username={self.username}, is_superuser={self.is_superuser}, is_active={self.is_active})"
syncmaster/db/repositories/user.py
@@ -58,8 +58,7 @@ async def update(self, user_id: int, data: dict) -> User:
58
async def create(
59
self,
60
username: str,
61
- email: str,
62
- is_active: bool,
+ email: str | None = None,
63
first_name: str | None = None,
64
middle_name: str | None = None,
65
last_name: str | None = None,
@@ -73,7 +72,6 @@ async def create(
73
72
first_name=first_name,
74
middle_name=middle_name,
75
last_name=last_name,
76
- is_active=is_active,
77
is_superuser=is_superuser,
78
79
.returning(User)
syncmaster/server/providers/auth/dummy_provider.py
@@ -62,11 +62,7 @@ async def get_token_password_grant(
try:
user = await self._uow.user.read_by_username(login)
except EntityNotFoundError:
- user = await self._uow.user.create(
66
- username=login,
67
- email=f"{login}@example.com",
68
- is_active=True,
69
- )
+ user = await self._uow.user.create(username=login)
70
71
log.info("User with id %r found", user.id)
if not user.is_active:
syncmaster/server/providers/auth/keycloak_provider.py
@@ -72,7 +72,7 @@ async def get_token_authorization_code_grant(
except Exception as e:
raise AuthorizationError("Failed to get token") from e
- async def get_current_user(self, access_token: str, *args, **kwargs) -> Any:
+ async def get_current_user(self, access_token: str, *args, **kwargs) -> Any: # noqa: WPS231
request: Request = kwargs["request"]
refresh_token = request.session.get("refresh_token")
@@ -113,16 +113,12 @@ async def get_current_user(self, access_token: str, *args, **kwargs) -> Any:
113
# these names are hardcoded in keycloak:
114
# https://github.com/keycloak/keycloak/blob/3ca3a4ad349b4d457f6829eaf2ae05f1e01408be/core/src/main/java/org/keycloak/representations/IDToken.java
115
# TODO: make sure which fields are guaranteed
116
- user_id = token_info.get("sub")
117
login = token_info["preferred_username"]
118
- email = token_info["email"]
+ email = token_info.get("email")
119
first_name = token_info.get("given_name")
120
middle_name = token_info.get("middle_name")
121
last_name = token_info.get("family_name")
122
123
- if not user_id:
124
- raise AuthorizationError("Invalid token payload")
125
-
126
async with self._uow:
127
128
@@ -133,7 +129,6 @@ async def get_current_user(self, access_token: str, *args, **kwargs) -> Any:
133
129
134
130
135
131
136
137
132
138
return user
139
syncmaster/server/scripts/manage_superusers.py
100644
100755
@@ -29,7 +29,7 @@ async def add_superusers(session: AsyncSession, usernames: list[str]) -> None:
29
30
if not_found:
31
for username in not_found:
- session.add(User(username=username, email=f"{username}@mts.ru", is_active=True, is_superuser=True))
+ session.add(User(username=username, is_superuser=True))
logging.info(" %r (new user)", username)
await session.commit()
tests/test_unit/utils.py
@@ -35,10 +35,10 @@ async def create_user_cm(
is_active: bool = False,
is_superuser: bool = False,
is_deleted: bool = False,
- email: str = None,
- first_name: str = None,
- middle_name: str = None,
- last_name: str = None,
+ first_name: str | None = None,
+ middle_name: str | None = None,
+ last_name: str | None = None,
) -> AsyncGenerator[User, None]:
email = email or f"{username}@user.user"
first_name = first_name or f"{username}_first"
@@ -68,10 +68,10 @@ async def create_user(
) -> User:
0 commit comments