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: if config[key]['path'] == self.mediafile.url:
return True return True
return False 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: except Mediafile.DoesNotExist:
return HttpResponseNotFound(content="Not found.") return HttpResponseNotFound(content="Not found.")
if ((not has_perm(request.user, 'mediafiles.can_see') or can_see = has_perm(request.user, 'mediafiles.can_see')
(mediafile.hidden and not has_perm(request.user, 'mediafiles.can_see_hidden'))) and is_special_file = mediafile.is_logo() or mediafile.is_font()
not mediafile.is_logo()): 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.") return HttpResponseForbidden(content="Forbidden.")
else: else:
return serve(request, path, document_root, show_indexes) return serve(request, path, document_root, show_indexes)