Skip to content

Commit d9a1987

Browse files
aaxelbchrisseto
authored andcommitted
[SHARE-511][Feature] Store user favicons as a blob (#565)
* Store user favicons in database * Move provider favicons to their app root * Allow loading favicons in robot migrations * Generate all robot favicon migrations * Fix migration dependencies * 404 on missing favicon, not 500 * Change favicon path in graphql endpoint * Change harvester favicon location in docs * Add favicon url to /sources endpoint * Fix requirements typo * Add favicon migrations for disabled harvesters * Reorder docs a little * Responding to review * Update migrations * Add missing favicons * Add forgotten import * Resolve multiple leaf migrations * Fix some favicon migrations * Require GET at favicon endpoint, and don't 500.
1 parent bdb0519 commit d9a1987

306 files changed

Lines changed: 3116 additions & 12 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/serializers.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,14 @@ def get_token(self, obj):
125125
def is_superuser(self, obj):
126126
return obj.is_superuser
127127

128+
def get_favicon(self, obj):
129+
return obj.favicon.url if obj.favicon else None
130+
128131
class Meta:
129132
model = models.ShareUser
130133
fields = (
131134
'username', 'first_name', 'last_name', 'email', 'date_joined', 'last_login',
132-
'is_active', 'gravatar', 'locale', 'time_zone'
135+
'is_active', 'gravatar', 'locale', 'time_zone', 'favicon'
133136
)
134137

135138

@@ -146,7 +149,7 @@ def provider_name(self, obj):
146149

147150
class Meta:
148151
model = models.ShareUser
149-
fields = ('home_page', 'long_title', 'date_joined', 'gravatar')
152+
fields = ('home_page', 'long_title', 'date_joined', 'gravatar', 'favicon')
150153

151154

152155
class SiteBannerSerializer(ShareModelSerializer):

api/views/share.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
from rest_framework_json_api import serializers
66

77
from django import http
8+
from django.views.decorators.http import require_GET
89
from django.views.generic.base import RedirectView
910
from django.shortcuts import get_object_or_404
1011

1112
from api.filters import ShareObjectFilterSet
1213
from api import serializers as api_serializers
1314

1415
from share.util import IDObfuscator, InvalidID
16+
from share.models import ShareUser
1517

1618

1719
class VersionsViewSet(viewsets.ReadOnlyModelViewSet):
@@ -107,6 +109,16 @@ def get(self, request, *args, **kwargs):
107109
return Response(ser.data)
108110

109111

112+
@require_GET
113+
def user_favicon_view(request, username):
114+
user = get_object_or_404(ShareUser, username=username)
115+
if not user.favicon:
116+
raise http.Http404('Favicon for user {} does not exist'.format(user.username))
117+
response = http.FileResponse(user.favicon)
118+
response['Content-Type'] = 'image/x-icon'
119+
return response
120+
121+
110122
class HttpSmartResponseRedirect(http.HttpResponseRedirect):
111123
status_code = 307
112124

docs/harvesters_and_normalizers.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ Adding a new provider
149149
- See :ref:`Best practices for writing a non-OAI Harvester <writing-harvesters>`
150150
- Writing the normalizer
151151
- See :ref:`Best practices for writing a non-OAI Normalizer <writing-normalizers>`
152-
- Adding the migration
153-
- Finally, run ``./manage.py makeprovidermigrations`` in the terminal
154-
- Include only the relevant migration in the PR
155152
- Adding a provider's favicon
156153
- visit ``www.domain.com/favicon.ico`` and download the ``favicon.ico`` file
157-
- place ``favicon.ico`` in ``providers/domain/provider_name/static/domain.provider_name/img/``
154+
- place ``favicon.ico`` in the ``providers/`` specific folder
155+
- Adding the migration
156+
- Finally, run ``./manage.py makeprovidermigrations`` in the terminal
157+
- Include only the relevant migrations in the PR
158158

159159
.. _OAI-PMH: http://www.openarchives.org/OAI/openarchivesprotocol.html
160160

project/urls.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
from osf_oauth2_adapter import views as osf_oauth2_adapter_views
2424

25-
from api.views import APIVersionRedirectView
25+
from api.views import APIVersionRedirectView, user_favicon_view
2626

2727
urlpatterns = [
2828
url(r'^admin/', admin.site.urls),
@@ -38,7 +38,8 @@
3838
url(r'^favicon.ico$', RedirectView.as_view(
3939
url=staticfiles_storage.url('favicon.ico'),
4040
permanent=False
41-
), name="favicon"),
41+
), name='favicon'),
42+
url(r'^favicons/(?P<username>[^/]+).ico$', user_favicon_view, name='user_favicon'),
4243
]
4344

4445
if settings.DEBUG:
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.7 on 2017-02-01 21:23
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
import share.robot
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('au.uow', '0001_initial'),
13+
('share', '0018_store_favicons'),
14+
]
15+
16+
operations = [
17+
migrations.RunPython(
18+
code=share.robot.RobotFaviconMigration('au.uow'),
19+
),
20+
]
File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.7 on 2017-02-01 21:23
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
import share.robot
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('be.ghent', '0001_initial'),
13+
('share', '0018_store_favicons'),
14+
]
15+
16+
operations = [
17+
migrations.RunPython(
18+
code=share.robot.RobotFaviconMigration('be.ghent'),
19+
),
20+
]

providers/br/pcurio/static/br.pcurio/img/favicon.ico renamed to providers/br/pcurio/favicon.ico

File renamed without changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.9.7 on 2017-02-01 21:23
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations
6+
import share.robot
7+
8+
9+
class Migration(migrations.Migration):
10+
11+
dependencies = [
12+
('br.pcurio', '0001_initial'),
13+
('share', '0018_store_favicons'),
14+
]
15+
16+
operations = [
17+
migrations.RunPython(
18+
code=share.robot.RobotFaviconMigration('br.pcurio'),
19+
),
20+
]

0 commit comments

Comments
 (0)