Skip to content

Commit a8f86d1

Browse files
authored
эксклюзивные права на чтение (#46)
* эксклюзивные права на чтение * эксклюзивные права на чтение * Delete migrations/versions/f8c57101c0f6_init.py * эксклюзивные права на чтение * эксклюзивные права на чтение * эксклюзивные права на чтение
1 parent 84fda0b commit a8f86d1

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

migrations/versions/f8c57101c0f6_init.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Init
22
33
Revision ID: f8c57101c0f6
4-
Revises:
4+
Revises:
55
Create Date: 2023-05-09 12:48:25.550608
66
77
"""
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""add_is_public_field_to_param
2+
3+
Revision ID: fc911d58459b
4+
Revises: 5a6490c55c81
5+
Create Date: 2025-03-11 21:38:50.699014
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = 'fc911d58459b'
15+
down_revision = '5a6490c55c81'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
op.add_column('param', sa.Column('is_public', sa.Boolean(), nullable=False, server_default=sa.false()))
22+
23+
24+
def downgrade():
25+
# ### commands auto generated by Alembic - please adjust! ###
26+
op.drop_column('param', 'is_public')
27+
# ### end Alembic commands ###

userdata_api/models/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class Param(BaseDbModel):
5757
а параметры эти могут лежать в категории "контакты"
5858
"""
5959

60+
is_public: Mapped[bool] = mapped_column(Boolean, default=False, nullable=False)
6061
visible_in_user_response: Mapped[bool] = mapped_column(Boolean, default=True)
6162
name: Mapped[str] = mapped_column(String)
6263
category_id: Mapped[int] = mapped_column(Integer, ForeignKey(Category.id))

userdata_api/routes/user.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
@user.get("/{id}", response_model=UserInfoGet)
1919
async def get_user_info(
2020
id: int,
21-
additional_data: list[int] = Query(default=[]),
2221
user: dict[str, Any] = Depends(UnionAuth(scopes=[], allow_none=False, auto_error=True)),
2322
) -> UserInfoGet:
2423
"""
@@ -37,7 +36,7 @@ async def get_user_info(
3736
}
3837
"""
3938

40-
return UserInfoGet.model_validate(await get(id, user, additional_data))
39+
return UserInfoGet.model_validate(await get(id, user))
4140

4241

4342
@user.post("/{id}", response_model=StatusResponseModel)

userdata_api/schemas/param.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77

88
class ParamPost(Base):
9+
is_public: bool = False
910
visible_in_user_response: bool = True
1011
name: constr(min_length=1)
1112
is_required: bool
@@ -15,6 +16,7 @@ class ParamPost(Base):
1516

1617

1718
class ParamPatch(Base):
19+
is_public: bool = False
1820
visible_in_user_response: bool = True
1921
name: constr(min_length=1) | None = None
2022
is_required: bool | None = None

userdata_api/utils/user.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ async def get_users_info(
113113
user_ids: list[int],
114114
category_ids: list[int] | None,
115115
user: dict[str, int | list[dict[str, str | int]]],
116-
additional_data: list[int],
116+
additional_data: list[int] | None = None,
117117
) -> list[dict[str, str | None]]:
118118
""".
119119
Возвращает информацию о данных пользователей в указанных категориях
@@ -123,6 +123,8 @@ async def get_users_info(
123123
:param user: Сессия выполняющего запрос данных
124124
:return: Список словарей содержащих id пользователя, категорию, параметр категории и значение этого параметра у пользователя
125125
"""
126+
if additional_data is None:
127+
additional_data = []
126128
is_single_user = category_ids is None
127129
scope_names = [scope["name"] for scope in user["session_scopes"]]
128130
param_dict: dict[Param, dict[int, list[Info] | Info | None] | None] = {}
@@ -152,6 +154,7 @@ async def get_users_info(
152154
info.category.read_scope
153155
and info.category.read_scope not in scope_names
154156
and (not is_single_user or info.owner_id != user["id"])
157+
and not info.param.is_public
155158
):
156159
continue
157160
if info.param not in param_dict:
@@ -229,9 +232,7 @@ async def get_users_info_batch(
229232
return UsersInfoGet(items=await get_users_info(user_ids, category_ids, user, additional_data))
230233

231234

232-
async def get_user_info(
233-
user_id: int, user: dict[str, int | list[dict[str, str | int]]], additional_data: list[int]
234-
) -> UserInfoGet:
235+
async def get_user_info(user_id: int, user: dict[str, int | list[dict[str, str | int]]]) -> UserInfoGet:
235236
"""Возвращает информауию о пользователе в соотетствии с переданным токеном.
236237
237238
Пользователь может прочитать любую информацию о себе
@@ -243,7 +244,7 @@ async def get_user_info(
243244
:return: Список словарей содержащих категорию, параметр категории и значение этого параметра у пользователя
244245
"""
245246

246-
result = await get_users_info([user_id], None, user, additional_data)
247+
result = await get_users_info([user_id], None, user)
247248
for value in result:
248249
del value["user_id"]
249250
return UserInfoGet(items=result)

0 commit comments

Comments
 (0)