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

ENG-6733 fix the issue of sorting for gitlab is related to Serializer source=‘modified’ in comparison to dropbox it failed so have added the possibility. #10956

Open
wants to merge 1 commit into
base: feature/gravy_valet_integration
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions api/base/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,12 @@ def bulk_get_file_nodes_from_wb_resp(self, files_list):

try:
file_obj = base_class.objects.get(**query)
# it is needed to update modified attribute explicitly in case
# there will be another commit for the file so it will have another update date
# somehow it is not updated for gitlab implicitly using .
if attrs.get('provider') == 'gitlab' and attrs.get('modified_utc'):
file_obj.modified = attrs.get('modified_utc')

except base_class.DoesNotExist:
# create method on BaseFileNode appends provider, bulk_create bypasses this step so it is added here
file_obj = base_class(target=node, _path=_path, provider=base_class._provider)
Expand Down
10 changes: 10 additions & 0 deletions api/files/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,16 @@ def get_target_type(self, obj):
raise NotImplementedError()


class GitlabFileSerializer(FileSerializer):
date_modified = VersionedDateTimeField(
source='modified',
read_only=True,
help_text='Timestamp when the file was last modified',
required=False,
allow_null=True,
)


class OsfStorageFileSerializer(FileSerializer):
""" Overrides `filterable_fields` to make `last_touched` non-filterable
"""
Expand Down
5 changes: 4 additions & 1 deletion api/nodes/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
)
from api.draft_registrations.serializers import DraftRegistrationSerializer, DraftRegistrationDetailSerializer
from api.draft_registrations.permissions import DraftRegistrationPermission
from api.files.serializers import FileSerializer, OsfStorageFileSerializer
from api.files.serializers import FileSerializer, OsfStorageFileSerializer, GitlabFileSerializer
from api.files import annotations as file_annotations
from api.identifiers.serializers import NodeIdentifierSerializer
from api.identifiers.views import IdentifierList
Expand Down Expand Up @@ -1130,6 +1130,9 @@ class NodeFilesList(JSONAPIBaseView, generics.ListAPIView, WaterButlerMixin, Lis
def serializer_class(self):
if self.kwargs[self.provider_lookup_url_kwarg] == 'osfstorage':
return OsfStorageFileSerializer
if self.kwargs[self.provider_lookup_url_kwarg] == 'gitlab':
# use source='modified' explicitly for gitlab sorting
return GitlabFileSerializer
return FileSerializer

def get_resource(self):
Expand Down