Add fonts to the medifile serve view

This commit is contained in:
FinnStutzenstein 2018-04-04 11:25:45 +02:00
parent 209ea70d75
commit df531b8747
2 changed files with 11 additions and 3 deletions

View File

@ -101,3 +101,9 @@ class Mediafile(RESTModelMixin, models.Model):
if config[key]['path'] == self.mediafile.url:
return True
return False
def is_font(self):
for key in config['fonts_available']:
if config[key]['path'] == self.mediafile.url:
return True
return False

View File

@ -77,9 +77,11 @@ def protected_serve(request, path, document_root=None, show_indexes=False):
except Mediafile.DoesNotExist:
return HttpResponseNotFound(content="Not found.")
if ((not has_perm(request.user, 'mediafiles.can_see') or
(mediafile.hidden and not has_perm(request.user, 'mediafiles.can_see_hidden'))) and
not mediafile.is_logo()):
can_see = has_perm(request.user, 'mediafiles.can_see')
is_special_file = mediafile.is_logo() or mediafile.is_font()
is_hidden_but_no_perms = mediafile.hidden and not has_perm(request.user, 'mediafiles.can_see_hidden')
if not can_see or (is_hidden_but_no_perms and not is_special_file):
return HttpResponseForbidden(content="Forbidden.")
else:
return serve(request, path, document_root, show_indexes)