-
Notifications
You must be signed in to change notification settings - Fork 19
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
Feature/hide play files #753
Open
FinemechanicPub
wants to merge
15
commits into
develop
Choose a base branch
from
feature/hide_play_files
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2d94f0d
Install django-private-storage
FinemechanicPub c755452
Store plays in a private storage
FinemechanicPub 35d8ab0
Add private media folder to gitignore
FinemechanicPub c753a93
Add protected media location
FinemechanicPub e5147ac
Refactor migrations
FinemechanicPub 92d12a3
Fix nginx config
FinemechanicPub 03cde36
Fix private medoa nginx redirect
FinemechanicPub c9356ea
Add permission control to file download
FinemechanicPub 76de677
Fix protected_media binding
FinemechanicPub 756c58b
Stage and prod config
FinemechanicPub aa7a82a
Update project config
FinemechanicPub 477c7b0
Fix dependencies
FinemechanicPub cf35809
Merge branch 'develop' into feature/hide_play_files
FinemechanicPub 86137eb
Fix migration order
FinemechanicPub 68d5541
Formatting
FinemechanicPub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,6 +131,7 @@ dmypy.json | |
# Media and Static Django | ||
/media | ||
/staticfiles | ||
/protected_media | ||
|
||
# Logs Django | ||
/logs | ||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Сервис контроля доступа к файлам для приложени django-private-storage.""" | ||
|
||
from pathlib import Path | ||
|
||
from django.conf import settings | ||
from private_storage.models import PrivateFile | ||
|
||
from apps.library.models.play import Play | ||
|
||
|
||
def has_download_permission(private_file: PrivateFile) -> bool: | ||
user = private_file.request.user | ||
if user.is_authenticated and user.is_staff: | ||
return True | ||
|
||
relative_path = Path(private_file.full_path).relative_to(settings.PRIVATE_STORAGE_ROOT) | ||
return Play.objects.filter(url_download=relative_path, published=True).exists() |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 3.2.23 on 2024-01-26 13:30 | ||
|
||
import apps.content_pages.utilities | ||
import django.core.validators | ||
from django.conf import settings | ||
from django.db import migrations | ||
import private_storage.fields | ||
import private_storage.storage.files | ||
from shutil import copytree, move | ||
|
||
REGULAR_MEDIA = settings.MEDIA_ROOT / "plays" | ||
PROTECTED_MEDIA = settings.PRIVATE_STORAGE_ROOT / "plays" | ||
|
||
|
||
def move_to_protected_media(apps, schema_editor): | ||
if REGULAR_MEDIA.exists(): | ||
copytree(REGULAR_MEDIA, PROTECTED_MEDIA, copy_function=move, dirs_exist_ok=True) | ||
|
||
|
||
def move_from_protected_media(apps, schema_editor): | ||
if PROTECTED_MEDIA.exists(): | ||
copytree(PROTECTED_MEDIA, REGULAR_MEDIA, copy_function=move, dirs_exist_ok=True) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('library', '0043_alter_socialnetworklink_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='play', | ||
name='url_download', | ||
field=private_storage.fields.PrivateFileField(blank=True, help_text="Файл пьесы должен быть в одном из следующих форматов: ('doc', 'docx', 'txt', 'odt', 'pdf')", max_length=200, null=True, storage=private_storage.storage.files.PrivateFileSystemStorage(), upload_to=apps.content_pages.utilities.path_by_media_and_class_name, validators=[django.core.validators.FileExtensionValidator(('doc', 'docx', 'txt', 'odt', 'pdf'))], verbose_name='Текст пьесы'), | ||
), | ||
migrations.RunPython(move_to_protected_media, move_from_protected_media), | ||
] |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А почему тут конфиг в пути?
в докере указывается
/code/protected_media/
, не знаю пересекаются эти пути или нетThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для swag задано
Для backend задано
Таким образом в одна и так же папка на хосте сопоставлена двум папкам:
в контейнере backend это /code/protected_media/, а в контейнере swag это /config/prod/protected_media/.
Это конфиг Nginx, поэтому тут путь указывается так, как он выглядит из контейнера Nginx (Swag).