Added capability 'encode-video' and role 'video-encoder'.

Both 'video-encoder' and 'admin' roles get 'encode-video' capability,
which allows users to upload video that gets encoded & displayed as a
video. For users without this capability videos are handled as regular
downloads.
This commit is contained in:
Sybren A. Stüvel 2017-12-07 16:51:16 +01:00
parent 5c7f37a100
commit dfc224d8a9
3 changed files with 7 additions and 6 deletions

View File

@ -86,7 +86,7 @@ class PillarServer(BlinkerCompatibleEve):
# The default roles Pillar uses. Will probably all move to extensions at some point. # The default roles Pillar uses. Will probably all move to extensions at some point.
self._user_roles: typing.Set[str] = { self._user_roles: typing.Set[str] = {
'demo', 'admin', 'subscriber', 'homeproject', 'demo', 'admin', 'subscriber', 'homeproject',
'protected', 'org-subscriber', 'protected', 'org-subscriber', 'video-encoder',
'service', 'badger', 'svner', 'urler', 'service', 'badger', 'svner', 'urler',
} }
self._user_roles_indexable: typing.Set[str] = {'demo', 'admin', 'subscriber'} self._user_roles_indexable: typing.Set[str] = {'demo', 'admin', 'subscriber'}

View File

@ -26,7 +26,7 @@ from flask import url_for, helpers
from pillar.api import utils from pillar.api import utils
from pillar.api.file_storage_backends.gcs import GoogleCloudStorageBucket, \ from pillar.api.file_storage_backends.gcs import GoogleCloudStorageBucket, \
GoogleCloudStorageBlob GoogleCloudStorageBlob
from pillar.api.utils import remove_private_keys, authentication from pillar.api.utils import remove_private_keys
from pillar.api.utils.authorization import require_login, user_has_role, \ from pillar.api.utils.authorization import require_login, user_has_role, \
user_matches_roles user_matches_roles
from pillar.api.utils.cdn import hash_file_path from pillar.api.utils.cdn import hash_file_path
@ -291,8 +291,8 @@ def process_file(bucket: Bucket,
# TODO: overrule the content type based on file extention & magic numbers. # TODO: overrule the content type based on file extention & magic numbers.
mime_category, src_file['format'] = src_file['content_type'].split('/', 1) mime_category, src_file['format'] = src_file['content_type'].split('/', 1)
# Prevent video handling for non-admins. # Only allow video encoding when the user has the correct capability.
if not user_has_role('admin') and mime_category == 'video': if not current_user.has_cap('encode-video') and mime_category == 'video':
if src_file['format'].startswith('x-'): if src_file['format'].startswith('x-'):
xified = src_file['format'] xified = src_file['format']
else: else:
@ -300,7 +300,7 @@ def process_file(bucket: Bucket,
src_file['content_type'] = 'application/%s' % xified src_file['content_type'] = 'application/%s' % xified
mime_category = 'application' mime_category = 'application'
log.info('Not processing video file %s for non-admin user', file_id) log.info('Not processing video file %s for non-video-encoding user', file_id)
# Run the required processor, based on the MIME category. # Run the required processor, based on the MIME category.
processors: typing.Mapping[str, typing.Callable] = { processors: typing.Mapping[str, typing.Callable] = {

View File

@ -205,8 +205,9 @@ CELERY_BEAT_SCHEDULE = {
USER_CAPABILITIES = defaultdict(**{ USER_CAPABILITIES = defaultdict(**{
'subscriber': {'subscriber', 'home-project'}, 'subscriber': {'subscriber', 'home-project'},
'demo': {'subscriber', 'home-project'}, 'demo': {'subscriber', 'home-project'},
'admin': {'video-encoding', 'admin', 'admin': {'encode-video', 'admin',
'view-pending-nodes', 'edit-project-node-types', 'create-organization'}, 'view-pending-nodes', 'edit-project-node-types', 'create-organization'},
'video-encoder': {'encode-video'},
'org-subscriber': {'subscriber', 'home-project'}, 'org-subscriber': {'subscriber', 'home-project'},
}, default_factory=frozenset) }, default_factory=frozenset)