Hotfix: fix news attachment link validation - #698
Merged
Conversation
TThanos3000
marked this pull request as ready for review
August 21, 2026 03:32
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Что исправлено
Backend действительно воспроизводил
Invalid pkпри отправкеfiles=[UserFile.link]в News API, даже когдаUserFileсуществовал и принадлежал authenticated user.Root cause: поле
filesобъявлено какPrimaryKeyRelatedField(..., many=True). DRF оборачивает его вManyRelatedField, а фактическая валидация каждого элемента выполняется черезchild_relation. Код менялself.fields[files].queryset, ноchild_relation.querysetоставался исходнымUserFile.objects.none(), поэтому любой URL валидировался как несуществующий pk.Fix минимальный: ownership validation сохранён, queryset текущего пользователя назначается на
self.fields[files].child_relation.queryset.Regression tests
Добавлен
news/tests/test_news_attachment_contract.py:POST /projects/<id>/news/принимаетUserFile.linkтекущего пользователя и прикрепляет именно этотUserFile.POST /auth/users/<id>/news/принимаетUserFile.linkтекущего пользователя и прикрепляет именно этотUserFile.POST /programs/<id>/news/принимаетUserFile.linkтекущего пользователя и прикрепляет именно этотUserFile.POST /files/с замоканным CDN upload создаётUserFile;upload_response.data[url] == UserFile.link;UserFile.user == authenticated_user; затемPOST /projects/<id>/news/сfiles=[url]возвращает 201.Существующий security-case
UserFileдругого пользователя → 400 сохранён и проходит.Проверки
Команда:
DEBUG=True python manage.py test news.tests.test_news_attachment_contract news.tests.test_news_project_api.ProjectScopedNewsAPITests.test_project_news_create_rejects_file_of_another_user --verbosity 1Результат: 6 tests passed.
Также:
python -m black --check news/serializers.py news/tests/test_news_attachment_contract.pyРезультат: passed.
Примечание по локальному окружению
Локально tests запускались во временном venv на Windows. Для обхода отсутствующих native runtime deps были использованы test-env shims только вне репозитория:
webpиweasyprintне выполнялись в этих сценариях, CDN upload замокан. В репозиторий эти shims не добавлялись.Frontend PR #281 не менялся.