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

[Fixes #1299] Restore thumbnail data to public channels API. #1367

Merged
merged 1 commit into from
May 17, 2019

Conversation

kollivier
Copy link
Contributor

@kollivier kollivier commented May 14, 2019

Also fix content type value for public JSON endpoints.

Description

The public channel list API gets its thumbnail from the icon_encoding field in the Channel model. However, in Studio, we never set this field. We only ever set it on the Kolibri sqlite db. In Studio, the thumbnail comes from the thumbnail_encoding field instead. As a result, Kolibri import always shows blank thumbnails for Studio content sources available to import.

To fix this, this PR updates the channel public list API serializer to return the thumbnail_encoding thumbnail if the icon_encoding field is not set.

Issue Addressed (if applicable)

Addresses #1299

Steps to Test

  • Try to import a channel from Kolibri, and see if the thumbnail appears

Checklist

  • Is the code clean and well-commented?
  • Are there tests for this change?

Reviewers

If you are looking to assign a reviewer, here are some options:

  • Jordan jayoshih (full stack)
  • Aron aronasorman (back end, devops)
  • Micah micahscopes (full stack)
  • Kevin kollivier (back end)
  • Ivan ivanistheone (Ricecooker)
  • Richard rtibbles (full stack, Kolibri)
  • Radina @radinamatic (documentation)

…ls API. Also fix content type value for public JSON endpoints.
@kollivier kollivier requested review from jayoshih and rtibbles May 14, 2019 23:11
Copy link
Member

@rtibbles rtibbles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a few questions but nothing that would block merge.

information, fall back to the channel thumbnail data if icon_encoding is not set.
"""
if channel.icon_encoding:
return channel.icon_encoding
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it always safe to just return the thumbnail_encoding? If so this could be removed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so that the thumbnail used when the channel was published remains the same despite the user changing the thumbnail after publishing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It currently isn't being set, although from my reading of the code I think that was unintentional and may not have always been the case, so I didn't want to break the old behavior without more discussion about whether or not we want to use this field going forward.

@@ -762,11 +762,27 @@ class PublicChannelSerializer(ChannelFieldMixin, serializers.ModelSerializer):
"""
kind_count = serializers.SerializerMethodField('generate_kind_count')
matching_tokens = serializers.SerializerMethodField('match_tokens')
icon_encoding = serializers.SerializerMethodField('get_thumbnail_encoding')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we decide it is safe to always return thumbnail_encoding, we could simplify this to:
icon_encoding = serializers.JSONField(source='thumbnail_encoding')

@@ -59,7 +58,7 @@ def get_public_channel_list(request, version):
channel_list = _get_channel_list(version, request.query_params)
except LookupError:
return HttpResponseNotFound(_("Api endpoint {} is not available").format(version))
return HttpResponse(json.dumps(PublicChannelSerializer(channel_list, many=True).data))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yep, that would do it!

Copy link
Contributor

@jayoshih jayoshih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just want to do one check before merging

@@ -72,7 +71,7 @@ def get_public_channel_lookup(request, version, identifier):
return HttpResponseNotFound(_("Api endpoint {} is not available").format(version))
if not channel_list.exists():
return HttpResponseNotFound(_("No channel matching {} found").format(identifier))
return HttpResponse(json.dumps(PublicChannelSerializer(channel_list, many=True).data))
return Response(PublicChannelSerializer(channel_list, many=True).data)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to make sure, does this break any versions of Kolibri since the type returned will be different (string vs. array)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output of the endpoint should not be any different, rest_framework.Response serializes the data to JSON internally. It also returns a correct Content-Type header of application/json, unlike HttpResponse, which returns text/html, which is why I made the change.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this affect any front-end code? When I did a similar thing changing HttpResponse to rest_framework.Response, I had to remove any JSON.parse instances from the front end to get it to work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is any Studio frontend code using the Kolibri public channel list API? I wasn't able to find any code paths in the Studio frontend using it.

On a more general note, we should actually look at any places we need to explicitly parse and make fixing those part of our tech debt. It means we're not properly declaring the return type, which will cause problems when writing tests, etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I think it should be fine. Worst case, we just revert back to the json dumps code :)

@kollivier kollivier added the qa-ready Create a demo server for this pull request label May 15, 2019
@jayoshih jayoshih added the changelog Needs to be added to the changelog (remove once added) label May 15, 2019
@kollivier kollivier requested a review from jayoshih May 17, 2019 00:49
@jayoshih jayoshih merged commit 67cea67 into learningequality:develop May 17, 2019
@jayoshih jayoshih removed qa-ready Create a demo server for this pull request changelog Needs to be added to the changelog (remove once added) labels May 17, 2019
@kollivier kollivier deleted the thumb-meet-nail branch June 10, 2019 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants