Skip to content

Commit

Permalink
fix: correct inconsistent use of camelCase json renderer
Browse files Browse the repository at this point in the history
- remove renderer class overrides on some API views, instead relying on
  the new default CamelCaseJSONRenderer
- fix permissions for peer review list_review_event_log
- correct multi-word values for sort/filtering which mistakenly got
  camelCased
  • Loading branch information
sgfost committed Jun 26, 2023
1 parent 139eae7 commit facc607
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 32 deletions.
4 changes: 0 additions & 4 deletions django/home/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
parsers,
status,
mixins,
renderers,
filters,
)
from rest_framework.decorators import action
from rest_framework.filters import OrderingFilter
from rest_framework.permissions import IsAuthenticated, AllowAny
from rest_framework.renderers import JSONRenderer, TemplateHTMLRenderer
from rest_framework.response import Response
from rest_framework.views import APIView
from taggit.models import Tag
Expand Down Expand Up @@ -83,7 +81,6 @@ def get_redirect_url(self, *args, **kwargs):

class ToggleFollowUser(APIView):
permission_classes = (IsAuthenticated,)
renderer_classes = (TemplateHTMLRenderer, JSONRenderer)

def post(self, request, *args, **kwargs):
logger.debug("POST with request data: %s", request.data)
Expand All @@ -104,7 +101,6 @@ class TagListView(mixins.ListModelMixin, viewsets.GenericViewSet):
serializer_class = TagSerializer
queryset = Tag.objects.all()
pagination_class = SmallResultSetPagination
renderer_classes = (renderers.JSONRenderer,)
permission_classes = (AllowAny,)

def get_queryset(self):
Expand Down
16 changes: 3 additions & 13 deletions django/library/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def has_permission(self, request, view):
class PeerReviewInvitationViewSet(NoDeleteNoUpdateViewSet):
queryset = PeerReviewInvitation.objects.with_reviewer_statistics()
permission_classes = (NestedPeerReviewInvitation,)
renderer_classes = (renderers.JSONRenderer,)
serializer_class = PeerReviewInvitationSerializer
lookup_url_kwarg = "invitation_slug"

Expand Down Expand Up @@ -306,7 +305,6 @@ def get_success_url(self):

class PeerReviewFeedbackViewSet(NoDeleteNoUpdateViewSet):
queryset = PeerReviewerFeedback.objects.all()
renderer_classes = (renderers.JSONRenderer,)
serializer_class = PeerReviewFeedbackEditorSerializer

def get_queryset(self):
Expand Down Expand Up @@ -368,12 +366,8 @@ def get_success_url(self):
@permission_classes([])
def list_review_event_log(request, slug):
review = get_object_or_404(PeerReview, slug=slug)
if (
not MemberProfile.objects.editors()
.filter(pk=request.user.member_profile.pk)
.exists()
):
raise Http404()
if not request.user.has_perm("library.change_peerreview"):
raise PermissionDenied()
queryset = review.event_set.order_by("-date_created")[:10]
serializer = PeerReviewEventLogSerializer(queryset, many=True)
return Response(serializer.data)
Expand Down Expand Up @@ -521,7 +515,6 @@ class CodebaseImageViewSet(mixins.ListModelMixin, viewsets.GenericViewSet):
lookup_value_regex = r"\d+"
queryset = CodebaseImage.objects.all()
serializer_class = CodebaseImageSerializer
renderer_classes = (renderers.JSONRenderer,)
permission_classes = (CodebaseImagePermission,)

def get_queryset(self):
Expand Down Expand Up @@ -897,7 +890,7 @@ def download(self, request, **kwargs):

return response

@action(detail=True, methods=["get"], renderer_classes=(renderers.JSONRenderer,))
@action(detail=True, methods=["get"])
def download_preview(self, request, **kwargs):
codebase_release = self.get_object()
fs_api = codebase_release.get_fs_api()
Expand All @@ -915,7 +908,6 @@ class BaseCodebaseReleaseFilesViewSet(viewsets.GenericViewSet):
NestedCodebaseReleaseUnpublishedFilesPermission,
CodebaseReleaseUnpublishedFilePermissions,
)
renderer_classes = (renderers.JSONRenderer,)

stage = None

Expand Down Expand Up @@ -991,8 +983,6 @@ def get_list_url(self, api):


class CodebaseReleaseFilesOriginalsViewSet(BaseCodebaseReleaseFilesViewSet):
renderer_classes = (renderers.JSONRenderer,)

stage = StagingDirectories.originals

def get_list_url(self, api):
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/apps/codebase_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ createApp(CodebaseListSidebar).mount("#sidebar");
createApp(SortBy, {
sortOptions: [
{ value: "", label: "Relevance" },
{ value: "-firstPublishedAt", label: "Publish date: newest" },
{ value: "firstPublishedAt", label: "Publish date: oldest" },
{ value: "lastModified", label: "Recently Modified" },
{ value: "-first_published_at", label: "Publish date: newest" },
{ value: "first_published_at", label: "Publish date: oldest" },
{ value: "-last_modified", label: "Recently Modified" },
],
}).mount("#sortby");
12 changes: 6 additions & 6 deletions frontend/src/apps/event_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ createApp(EventListSidebar).mount("#sidebar");
createApp(SortBy, {
sortOptions: [
{ label: "Relevance", value: "" },
{ label: "Date posted: newest", value: "-dateCreated" },
{ label: "Date posted: oldest", value: "dateCreated" },
{ label: "Start date", value: "startDate" },
{ label: "Submission deadline", value: "submissionDeadline" },
{ label: "Early reg. deadline", value: "earlyRegistrationDeadline" },
{ label: "Recently modified", value: "lastModified" },
{ label: "Date posted: newest", value: "-date_created" },
{ label: "Date posted: oldest", value: "date_created" },
{ label: "Start date", value: "start_date" },
{ label: "Submission deadline", value: "submission_deadline" },
{ label: "Early reg. deadline", value: "early_registration_deadline" },
{ label: "Recently modified", value: "-last_modified" },
],
}).mount("#sortby");
9 changes: 4 additions & 5 deletions frontend/src/apps/job_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ createApp(JobListSidebar).mount("#sidebar");
createApp(SortBy, {
sortOptions: [
{ label: "Relevance", value: "" },
{ label: "Date posted: newest", value: "-dateCreated" },
{ label: "Date posted: oldest", value: "dateCreated" },
{ label: "Deadline: furthest", value: "-applicationDeadline" },
{ label: "Deadline: nearest", value: "applicationDeadline" },
{ label: "Recently modified ", value: "lastModified" },
{ label: "Date posted: newest", value: "-date_created" },
{ label: "Date posted: oldest", value: "date_created" },
{ label: "Application Deadline", value: "application_deadline" },
{ label: "Recently modified ", value: "-last_modified" },
],
}).mount("#sortby");
2 changes: 1 addition & 1 deletion frontend/src/components/CodebaseListSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { useCodebaseAPI } from "@/composables/api";
const peerReviewOptions = [
{ value: "reviewed", label: "Reviewed" },
{ value: "notReviewed", label: "Not Reviewed" },
{ value: "not_reviewed", label: "Not Reviewed" },
{ value: "", label: "Any" },
];
Expand Down

0 comments on commit facc607

Please sign in to comment.