Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14 скрытие части юзердаты от пользователя #23

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
alembic
auth-lib-profcomff[fastapi]
fastapi
fastapi==0.100.1
gitfresnel marked this conversation as resolved.
Show resolved Hide resolved
fastapi-sqlalchemy
gunicorn
logging-profcomff
psycopg2-binary
pydantic[dotenv]
SQLAlchemy
uvicorn
uvicorn==0.23.1
gitfresnel marked this conversation as resolved.
Show resolved Hide resolved
pydantic-settings
event_schema_profcomff
confluent_kafka
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_hidden: Mapped[bool] = mapped_column(Boolean, default=True)
gitfresnel marked this conversation as resolved.
Show resolved Hide resolved
name: Mapped[str] = mapped_column(String)
category_id: Mapped[int] = mapped_column(Integer, ForeignKey(Category.id))
is_required: Mapped[bool] = mapped_column(Boolean, default=False)
Expand Down
18 changes: 16 additions & 2 deletions userdata_api/routes/param.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,31 @@ async def create_param(


@param.get("/{id}", response_model=ParamGet)
async def get_param(id: int, category_id: int) -> ParamGet:
async def get_param(
id: int,
category_id: int,
_: dict[str, Any] = Depends(UnionAuth(scopes=[], allow_none=False, auto_error=True)),
) -> ParamGet:
gitfresnel marked this conversation as resolved.
Show resolved Hide resolved
"""
Получить параметр по айди
\f
:param id: Айди параметра
:param category_id: айди категории в которой этот параметр находиится
:param category_id: айди категории в которой этот параметр находится
:return: ParamGet - полученный параметр
:param _: Аутентификация
"""

res = Param.query(session=db.session).filter(Param.id == id, Param.category_id == category_id).one_or_none()
if not res:
raise ObjectNotFound(Param, id)
if res.is_hidden:
category_scopes = set(
Category.query(session=db.session).filter(Category.id == category_id).one_or_none().read_scope
)
user_scopes = set([scope["name"].lower() for scope in _["session_scopes"]])
if category_scopes - user_scopes:
raise ObjectNotFound(Param, id)
return ParamGet.model_validate(res)
gitfresnel marked this conversation as resolved.
Show resolved Hide resolved
return ParamGet.model_validate(res)


Expand Down
2 changes: 1 addition & 1 deletion userdata_api/routes/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def update_user(
Чтобы обновить от имени админиа, надо иметь скоуп `userdata.info.admin`
Чтобы обновить неизменяемую информацию надо обладать скоупом `userdata.info.update`
Для обновления своей информации(источник `user`) не нужны скоупы на обновление соответствующих категорий
Для обновления чужой информации от имени админа(источник `admin`)
Для обновления чужой информации от имени админа(источник `admin`)
нужны скоупы на обновление всех указанных в теле запроса категорий пользовательских данных данных
\f
:param request: Запрос из fastapi
Expand Down
Loading