Skip to content

Commit

Permalink
Merge pull request #293 from hotosm/hotfix/training-graph-view-bypass
Browse files Browse the repository at this point in the history
HOTFIX : Bypass permission for training accuracy graph download
  • Loading branch information
kshitijrajsharma authored Oct 19, 2024
2 parents fea1ae0 + 5bb7074 commit 154d9c0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
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

0 comments on commit 154d9c0

Please sign in to comment.