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

HOTFIX : Bypass permission for training accuracy graph download #293

Merged
merged 3 commits into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion backend/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
path(
"feedback-aoi/gpx/<int:feedback_aoi_id>/", GenerateFeedbackAOIGpxView.as_view()
),
path("workspace/", TrainingWorkspaceView.as_view()),
# path("workspace/", TrainingWorkspaceView.as_view()),
path(
"workspace/download/<path:lookup_dir>/", TrainingWorkspaceDownloadView.as_view()
),
Expand Down
29 changes: 26 additions & 3 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,8 +781,21 @@ def get(self, request, feedback_aoi_id: int):


class TrainingWorkspaceView(APIView):
def get(self, request, lookup_dir=None):
"""List out status of training workspace : size in bytes"""
@method_decorator(cache_page(60 * 15))
# @method_decorator(vary_on_headers("access-token"))
def get(self, request, lookup_dir):
"""
List the status of the training workspace.

### Returns:
- **Size**: The total size of the workspace in bytes.
- **dir/file**: The current dir/file on the lookup_dir.

### Workspace Structure:
By default, the training workspace is organized as follows:
- Training files are stored in the directory: `dataset{dataset_id}/output/training_{training}`
"""

# {workspace_dir:{file_name:{size:20,type:file},dir_name:{size:20,len:4,type:dir}}}
base_dir = settings.TRAINING_WORKSPACE
if lookup_dir:
Expand Down Expand Up @@ -814,6 +827,15 @@ class TrainingWorkspaceDownloadView(APIView):
authentication_classes = [OsmAuthentication]
permission_classes = [IsOsmAuthenticated]

def dispatch(self, request, *args, **kwargs):
lookup_dir = kwargs.get("lookup_dir")
if lookup_dir.endswith("training_validation_sparse_categorical_accuracy.png"):
# bypass
self.authentication_classes = []
self.permission_classes = []

return super().dispatch(request, *args, **kwargs)

def get(self, request, lookup_dir):
base_dir = os.path.join(settings.TRAINING_WORKSPACE, lookup_dir)
if not os.path.exists(base_dir):
Expand Down Expand Up @@ -860,6 +882,7 @@ class BannerViewSet(viewsets.ModelViewSet):
authentication_classes = [OsmAuthentication]
permission_classes = [IsAdminUser, IsStaffUser]
public_methods = ["GET"]
pagination_class = None

def get_queryset(self):
now = timezone.now()
Expand All @@ -869,7 +892,7 @@ def get_queryset(self):


@cache_page(60 * 15) ## Cache for 15 mins
# @vary_on_cookie , if you wanna do user specific cache
# @vary_on_cookie
@api_view(["GET"])
def get_kpi_stats(request):
total_models_with_status_published = Model.objects.filter(status=0).count()
Expand Down
Loading