Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrations/versions/f8c57101c0f6_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Init

Revision ID: f8c57101c0f6
Revises:
Revises:
Create Date: 2023-05-09 12:48:25.550608

"""
Expand Down
27 changes: 27 additions & 0 deletions migrations/versions/fc911d58459b_add_is_public_field_to_param.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""add_is_public_field_to_param

Revision ID: fc911d58459b
Revises: 5a6490c55c81
Create Date: 2025-03-11 21:38:50.699014

"""

import sqlalchemy as sa
from alembic import op


# revision identifiers, used by Alembic.
revision = 'fc911d58459b'
down_revision = '5a6490c55c81'
branch_labels = None
depends_on = None


def upgrade():
op.add_column('param', sa.Column('is_public', sa.Boolean(), nullable=False, server_default=sa.false()))


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('param', 'is_public')
# ### end Alembic commands ###
1 change: 1 addition & 0 deletions userdata_api/models/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Param(BaseDbModel):
а параметры эти могут лежать в категории "контакты"
"""

is_public: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
visible_in_user_response: Mapped[bool] = mapped_column(Boolean, default=True)
name: Mapped[str] = mapped_column(String)
category_id: Mapped[int] = mapped_column(Integer, ForeignKey(Category.id))
Expand Down
3 changes: 1 addition & 2 deletions userdata_api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
@user.get("/{id}", response_model=UserInfoGet)
async def get_user_info(
id: int,
additional_data: list[int] = Query(default=[]),
user: dict[str, Any] = Depends(UnionAuth(scopes=[], allow_none=False, auto_error=True)),
) -> UserInfoGet:
"""
Expand All @@ -37,7 +36,7 @@ async def get_user_info(
}
"""

return UserInfoGet.model_validate(await get(id, user, additional_data))
return UserInfoGet.model_validate(await get(id, user))


@user.post("/{id}", response_model=StatusResponseModel)
Expand Down
2 changes: 2 additions & 0 deletions userdata_api/schemas/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@


class ParamPost(Base):
is_public: bool = False
visible_in_user_response: bool = True
name: constr(min_length=1)
is_required: bool
Expand All @@ -15,6 +16,7 @@ class ParamPost(Base):


class ParamPatch(Base):
is_public: bool = False
visible_in_user_response: bool = True
name: constr(min_length=1) | None = None
is_required: bool | None = None
Expand Down
11 changes: 6 additions & 5 deletions userdata_api/utils/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async def get_users_info(
user_ids: list[int],
category_ids: list[int] | None,
user: dict[str, int | list[dict[str, str | int]]],
additional_data: list[int],
additional_data: list[int] | None = None,
) -> list[dict[str, str | None]]:
""".
Возвращает информацию о данных пользователей в указанных категориях
Expand All @@ -123,6 +123,8 @@ async def get_users_info(
:param user: Сессия выполняющего запрос данных
:return: Список словарей содержащих id пользователя, категорию, параметр категории и значение этого параметра у пользователя
"""
if additional_data is None:
additional_data = []
is_single_user = category_ids is None
scope_names = [scope["name"] for scope in user["session_scopes"]]
param_dict: dict[Param, dict[int, list[Info] | Info | None] | None] = {}
Expand Down Expand Up @@ -152,6 +154,7 @@ async def get_users_info(
info.category.read_scope
and info.category.read_scope not in scope_names
and (not is_single_user or info.owner_id != user["id"])
and not info.param.is_public
):
continue
if info.param not in param_dict:
Expand Down Expand Up @@ -229,9 +232,7 @@ async def get_users_info_batch(
return UsersInfoGet(items=await get_users_info(user_ids, category_ids, user, additional_data))


async def get_user_info(
user_id: int, user: dict[str, int | list[dict[str, str | int]]], additional_data: list[int]
) -> UserInfoGet:
async def get_user_info(user_id: int, user: dict[str, int | list[dict[str, str | int]]]) -> UserInfoGet:
"""Возвращает информауию о пользователе в соотетствии с переданным токеном.

Пользователь может прочитать любую информацию о себе
Expand All @@ -243,7 +244,7 @@ async def get_user_info(
:return: Список словарей содержащих категорию, параметр категории и значение этого параметра у пользователя
"""

result = await get_users_info([user_id], None, user, additional_data)
result = await get_users_info([user_id], None, user)
for value in result:
del value["user_id"]
return UserInfoGet(items=result)