add default rtmp application, filter by rtmp application permissions
This commit is contained in:
		
							parent
							
								
									020393c48b
								
							
						
					
					
						commit
						e92a131e4c
					
				| 
						 | 
				
			
			@ -28,6 +28,7 @@ ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", default="*").split(" ")
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
DEFAULT_GROUP = 'default'
 | 
			
		||||
DEFAULT_RTMP_APPPLICATION = 'live'
 | 
			
		||||
 | 
			
		||||
# Application definition
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
from django.forms import ModelForm
 | 
			
		||||
from guardian.shortcuts import get_objects_for_user
 | 
			
		||||
from . import models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class StreamFilteredApplicationForm(ModelForm):
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = models.Stream
 | 
			
		||||
        fields = ['name', 'application']
 | 
			
		||||
 | 
			
		||||
    def __init__(self, *args, **kwargs):
 | 
			
		||||
        user = kwargs.pop('user', None)
 | 
			
		||||
        super().__init__(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
        # limit the stream selection to user-accessible streams
 | 
			
		||||
        self.fields['application'].queryset = get_objects_for_user(user, 'rtmp.view_application')
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,16 @@
 | 
			
		|||
from django.core.management.base import BaseCommand
 | 
			
		||||
from django.contrib.auth.models import Group
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from guardian.shortcuts import assign_perm
 | 
			
		||||
 | 
			
		||||
from rtmp import models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Command(BaseCommand):
 | 
			
		||||
    help = 'Creates a default RTMP application that is available to all users in the default group'
 | 
			
		||||
 | 
			
		||||
    def handle(self, *args, **options):
 | 
			
		||||
        default_group, _ = Group.objects.get_or_create(name=settings.DEFAULT_GROUP)
 | 
			
		||||
        default_app, _ = models.Application.objects.get_or_create(name=settings.DEFAULT_RTMP_APPPLICATION)
 | 
			
		||||
 | 
			
		||||
        assign_perm('view_application', default_group, default_app)
 | 
			
		||||
| 
						 | 
				
			
			@ -13,6 +13,7 @@ from guardian.decorators import permission_required_or_403
 | 
			
		|||
from guardian.shortcuts import assign_perm
 | 
			
		||||
 | 
			
		||||
from . import models
 | 
			
		||||
from . import forms
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger(__name__)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -70,16 +71,26 @@ class StreamDetail(DetailView):
 | 
			
		|||
                  name='dispatch')
 | 
			
		||||
class StreamChange(UpdateView):
 | 
			
		||||
    model = models.Stream
 | 
			
		||||
    fields = ['application', 'name']
 | 
			
		||||
    form_class = forms.StreamFilteredApplicationForm
 | 
			
		||||
    template_name_suffix = '_update_form'
 | 
			
		||||
 | 
			
		||||
    def get_form_kwargs(self):
 | 
			
		||||
        kwargs = super().get_form_kwargs()
 | 
			
		||||
        kwargs['user'] = self.request.user
 | 
			
		||||
        return kwargs
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@method_decorator(login_required, name='dispatch')
 | 
			
		||||
@method_decorator(permission_required_or_403('rtmp.add_stream'),
 | 
			
		||||
                  name='dispatch')
 | 
			
		||||
class StreamCreate(CreateView):
 | 
			
		||||
    model = models.Stream
 | 
			
		||||
    fields = ["name", "application"]
 | 
			
		||||
    form_class = forms.StreamFilteredApplicationForm
 | 
			
		||||
 | 
			
		||||
    def get_form_kwargs(self):
 | 
			
		||||
        kwargs = super().get_form_kwargs()
 | 
			
		||||
        kwargs['user'] = self.request.user
 | 
			
		||||
        return kwargs
 | 
			
		||||
 | 
			
		||||
    def form_valid(self, form):
 | 
			
		||||
        valid = super().form_valid(form)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue