mirror of
https://github.com/mediacms-io/mediacms.git
synced 2025-11-20 13:36:05 -05:00
feat: add fily type and max user media uplod limits
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
from django.conf import settings
|
||||
from rest_framework import permissions
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
|
||||
from files.methods import is_mediacms_editor, is_mediacms_manager
|
||||
from files.methods import (
|
||||
is_mediacms_editor,
|
||||
is_mediacms_manager,
|
||||
user_allowed_to_upload,
|
||||
)
|
||||
|
||||
|
||||
class IsAuthorizedToAdd(permissions.BasePermission):
|
||||
def has_permission(self, request, view):
|
||||
if request.method in permissions.SAFE_METHODS:
|
||||
return True
|
||||
return user_allowed_to_upload(request)
|
||||
if not user_allowed_to_upload(request):
|
||||
raise PermissionDenied("You don't have permission to upload media, or have reached max number of media uploads.")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class IsAuthorizedToAddComment(permissions.BasePermission):
|
||||
@@ -55,26 +63,6 @@ class IsUserOrEditor(permissions.BasePermission):
|
||||
return obj.user == request.user
|
||||
|
||||
|
||||
def user_allowed_to_upload(request):
|
||||
"""Any custom logic for whether a user is allowed
|
||||
to upload content lives here
|
||||
"""
|
||||
if request.user.is_anonymous:
|
||||
return False
|
||||
if request.user.is_superuser:
|
||||
return True
|
||||
|
||||
if settings.CAN_ADD_MEDIA == "all":
|
||||
return True
|
||||
elif settings.CAN_ADD_MEDIA == "email_verified":
|
||||
if request.user.email_is_verified:
|
||||
return True
|
||||
elif settings.CAN_ADD_MEDIA == "advancedUser":
|
||||
if request.user.advancedUser:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def user_allowed_to_comment(request):
|
||||
"""Any custom logic for whether a user is allowed
|
||||
to comment lives here
|
||||
|
||||
@@ -226,7 +226,7 @@ POST_UPLOAD_AUTHOR_MESSAGE_UNLISTED_NO_COMMENTARY = ""
|
||||
# only in case where unlisted workflow is used and no commentary
|
||||
# exists
|
||||
|
||||
CANNOT_ADD_MEDIA_MESSAGE = ""
|
||||
CANNOT_ADD_MEDIA_MESSAGE = "User cannot add media, or maximum number of media uploads has been reached."
|
||||
|
||||
# mp4hls command, part of Bento4
|
||||
MP4HLS_COMMAND = "/home/mediacms.io/mediacms/Bento4-SDK-1-6-0-637.x86_64-unknown-linux/bin/mp4hls"
|
||||
@@ -501,9 +501,14 @@ ALLOW_CUSTOM_MEDIA_URLS = False
|
||||
# Whether to allow anonymous users to list all users
|
||||
ALLOW_ANONYMOUS_USER_LISTING = True
|
||||
|
||||
# Maximum number of media a user can upload
|
||||
NUMBER_OF_MEDIA_USER_CAN_UPLOAD = 100
|
||||
|
||||
# ffmpeg options
|
||||
FFMPEG_DEFAULT_PRESET = "medium" # see https://trac.ffmpeg.org/wiki/Encode/H.264
|
||||
|
||||
ALLOWED_MEDIA_UPLOAD_TYPES = ["video", "audio", "image", "pdf"]
|
||||
|
||||
try:
|
||||
# keep a local_settings.py file for local overrides
|
||||
from .local_settings import * # noqa
|
||||
|
||||
Reference in New Issue
Block a user