Skip to content

Commit

Permalink
[hotfix]: screenshots permissions checked without considering the fil…
Browse files Browse the repository at this point in the history
…e extension
  • Loading branch information
a8081 committed Sep 13, 2023
1 parent e279e83 commit 6267198
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion experiments/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from experiments.models import Screenshot
from django.contrib.auth.models import User
from rest_framework.authtoken.models import Token
from .utils import seleccionar_anterior_al_ultimo_punto


def allow_staff(private_file):
Expand All @@ -17,7 +18,7 @@ def allow_staff(private_file):
if "GUI_components" in private_file.relative_name:
guicomponent=GUIComponent.objects.filter(path=private_file.relative_name)
else:
screenshot=Screenshot.objects.filter(relative_path=private_file.relative_name)
screenshot=Screenshot.objects.filter(relative_path=seleccionar_anterior_al_ultimo_punto(private_file.relative_name))
if screenshot:
screenshot=screenshot[0]
res=user == screenshot.experiment.user
Expand Down
10 changes: 9 additions & 1 deletion experiments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,12 @@ def compress_experiment(path, file_name):
zip_path = zip_file + ".zip"
if not os.path.exists(zip_path):
zip_path = shutil.make_archive(zip_file, 'zip', abs_path)
return zip_path
return zip_path

def seleccionar_anterior_al_ultimo_punto(cadena):
posicion_ultimo_punto = cadena.rfind('.')
if posicion_ultimo_punto != -1:
resultado = cadena[:posicion_ultimo_punto]
return resultado
else:
return cadena
9 changes: 5 additions & 4 deletions experiments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.shortcuts import get_object_or_404
import datetime
from django.utils import timezone
from .utils import compress_experiment, upload_mockups
from .utils import compress_experiment, upload_mockups, seleccionar_anterior_al_ultimo_punto
from PIL import Image

def json_attributes_load(att):
Expand Down Expand Up @@ -350,6 +350,7 @@ def associate_experiment(user):
screenshots = data['screenshots']
screenshots_path = data['screenshots_path']
special_colnames = data['special_colnames']
seed_log = data['seed_log']
screenshot_name_generation_function = data['screenshot_name_generation_function']
foldername = data['foldername']
scenarios_conf = data['scenarios_conf']
Expand All @@ -366,6 +367,7 @@ def associate_experiment(user):
variability_conf=variability_conf,
special_colnames=special_colnames,
screenshots=screenshots,
seed_log=seed_log,
foldername=foldername,
is_being_processed=100,
is_active=True,
Expand Down Expand Up @@ -395,15 +397,14 @@ def associate_experiment(user):
# # This overrides PRIVATE_STORAGE_AUTH_FUNCTION
# return True


def associate_screenshots_files(experiment):
for root, directories, file in os.walk(experiment.screenshots_path):
for file in file:
if(file.endswith(".png") or file.endswith(".jpg")):
if(file.endswith(".png") or file.endswith(".jpg") or file.endswith(".PNG") or file.endswith(".JPG") or file.endswith(".jpeg") or file.endswith(".JPEG")):
image = Image.open(os.path.join(root, file))
aux = experiment.screenshots_path.split(sep)
width, height = image.size
relative_path = aux[len(aux)-1]+sep+file
relative_path = aux[len(aux)-1]+sep+seleccionar_anterior_al_ultimo_punto(file)
screenshot = Screenshot(
relative_path=relative_path, width=width, height=height, image=file, experiment=experiment)
screenshot.save()

0 comments on commit 6267198

Please sign in to comment.