Merge pull request #3683 from FinnStutzenstein/addFontsToMediafileServeView

Add fonts to the medifile serve view
This commit is contained in:
Emanuel Schütze 2018-04-04 12:15:07 +02:00 committed by GitHub
commit ef90f55472
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)