From 7f9b49e403758ca29172cea1229f779c095755f6 Mon Sep 17 00:00:00 2001 From: Christian Pointner <equinox@helsinki.at> Date: Thu, 25 Jun 2020 18:41:50 +0200 Subject: [PATCH] Public Shows --- manage.sh | 4 ++++ program/admin.py | 6 +++--- program/migrations/0022_show_is_public.py | 20 ++++++++++++++++++++ program/models.py | 1 + program/serializers.py | 3 ++- program/views.py | 10 ++++++++++ pv/oidc_provider_settings.py | 11 +++++++++-- 7 files changed, 49 insertions(+), 6 deletions(-) create mode 100755 manage.sh create mode 100644 program/migrations/0022_show_is_public.py diff --git a/manage.sh b/manage.sh new file mode 100755 index 00000000..3ab48636 --- /dev/null +++ b/manage.sh @@ -0,0 +1,4 @@ +#!/bin/bash +BASE_D=$(realpath "${BASH_SOURCE%/*}/") + +exec sudo docker run --rm -it -u $UID:$GID -p 127.0.0.1:8000:8000 -v "$BASE_D":/srv aura/pv /srv/manage.py $@ diff --git a/program/admin.py b/program/admin.py index 9db5ccc8..f69de36f 100644 --- a/program/admin.py +++ b/program/admin.py @@ -224,14 +224,14 @@ class ShowAdmin(admin.ModelAdmin): filter_horizontal = ('hosts', 'owners', 'musicfocus', 'category', 'topic', 'language') inlines = (ScheduleInline,) list_display = ('name', 'short_description') - list_filter = (ActiveShowsFilter, 'type', 'category', 'topic', 'musicfocus', 'language', 'fundingcategory') + list_filter = (ActiveShowsFilter, 'type', 'category', 'topic', 'musicfocus', 'language', 'fundingcategory', 'is_public') ordering = ('slug',) prepopulated_fields = {'slug': ('name',)} search_fields = ('name', 'short_description', 'description') fields = ( 'predecessor', 'type', 'name', 'slug', 'image', 'logo', 'short_description', 'description', 'email', 'website', 'hosts', 'owners', 'language', 'category', 'fundingcategory', 'topic', - 'musicfocus', 'fallback_id', 'cba_series_id', 'is_active' + 'musicfocus', 'fallback_id', 'cba_series_id', 'is_active', 'is_public' ) @@ -598,4 +598,4 @@ admin.site.register(Host, HostAdmin) admin.site.register(Note, NoteAdmin) admin.site.register(Schedule, ScheduleAdmin) admin.site.register(TimeSlot, TimeSlotAdmin) -admin.site.register(Show, ShowAdmin) \ No newline at end of file +admin.site.register(Show, ShowAdmin) diff --git a/program/migrations/0022_show_is_public.py b/program/migrations/0022_show_is_public.py new file mode 100644 index 00000000..51136dd1 --- /dev/null +++ b/program/migrations/0022_show_is_public.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.3 on 2019-09-18 12:48 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('program', '0021_show_is_active'), + ] + + operations = [ + migrations.AddField( + model_name='show', + name='is_public', + field=models.BooleanField(default=False, help_text='Files and Playlists of Public Shows can only be changed by owners but may be used by everyone.', verbose_name='Is Public?'), + ), + ] diff --git a/program/models.py b/program/models.py index def5d0b6..f687a8c0 100644 --- a/program/models.py +++ b/program/models.py @@ -326,6 +326,7 @@ class Show(models.Model): created = models.DateTimeField(auto_now_add=True, editable=False) last_updated = models.DateTimeField(auto_now=True, editable=False) is_active = models.BooleanField(_("Is active?"), default=True) + is_public = models.BooleanField(_("Is Public?"), default=False, help_text=_("Files and Playlists of Public Shows can only be changed by owners but may be used by everyone.")) class Meta: ordering = ('slug',) diff --git a/program/serializers.py b/program/serializers.py index 779316f4..6f6c5c3a 100644 --- a/program/serializers.py +++ b/program/serializers.py @@ -256,7 +256,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): fields = ('id', 'name', 'slug', 'image', 'ppoi', 'logo', 'short_description', 'description', 'email', 'website', 'created', 'last_updated', 'type', 'fundingcategory', 'predecessor', 'cba_series_id', 'fallback_id', 'category', 'hosts', - 'owners', 'language', 'topic', 'musicfocus', 'thumbnails', 'is_active') + 'owners', 'language', 'topic', 'musicfocus', 'thumbnails', 'is_active', 'is_public') def create(self, validated_data): @@ -316,6 +316,7 @@ class ShowSerializer(serializers.HyperlinkedModelSerializer): instance.fundingcategory = validated_data.get('fundingcategory', instance.fundingcategory) instance.predecessor = validated_data.get('predecessor', instance.predecessor) instance.is_active = validated_data.get('is_active', instance.is_active) + instance.is_public = validated_data.get('is_public', instance.is_public) instance.save() return instance diff --git a/program/views.py b/program/views.py index 4b139d16..48a7c45c 100644 --- a/program/views.py +++ b/program/views.py @@ -443,6 +443,8 @@ class APIShowViewSet(viewsets.ModelViewSet): /api/v1/shows/ Returns all shows (GET, POST) /api/v1/shows/?active=true Returns all active shows (= currently running) (GET) /api/v1/shows/?active=false Returns all inactive shows (= past or upcoming) (GET) + /api/v1/shows/?public=true Returns all public shows (GET) + /api/v1/shows/?public=false Returns all non-public shows (GET) /api/v1/shows/?host=1 Returns shows assigned to a given host (GET) /api/v1/shows/?owner=1 Returns shows of a given owner (GET) /api/v1/shows/1 Used for retrieving a single show or update (if owned) (GET, PUT) - DELETE is not allowed via API. Set is_active to False instead. @@ -489,6 +491,14 @@ class APIShowViewSet(viewsets.ModelViewSet): '''Return all shows except those which are running''' shows = Show.objects.exclude(id__in=show_ids,is_active=True) + if self.request.GET.get('public') == 'true': + '''Return all public shows''' + shows = shows.filter(is_public=True) + + if self.request.GET.get('public') == 'false': + '''Return all public shows''' + shows = shows.filter(is_public=False) + if self.request.GET.get('owner') != None: '''Filter shows by owner''' shows = shows.filter(owners__in=[int(self.request.GET.get('owner'))]) diff --git a/pv/oidc_provider_settings.py b/pv/oidc_provider_settings.py index e1b96998..a3e2465b 100644 --- a/pv/oidc_provider_settings.py +++ b/pv/oidc_provider_settings.py @@ -11,7 +11,9 @@ class AuraScopeClaims(ScopeClaims): def scope_username(self): dic = { - 'username': self.user.username + 'username': self.user.username, + #'privileged': (self.user.is_staff or self.user.is_superuser) + 'privileged': (self.user.is_superuser) } return dic @@ -22,9 +24,14 @@ class AuraScopeClaims(ScopeClaims): ) def scope_aura_shows(self): + from program.models import Show + + # TODO: should add filter `is_active=True` ? + public_show_slugs = list(Show.objects.filter(is_public=True).values_list('slug', flat=True)) show_slugs = list(self.user.shows.all().values_list('slug', flat=True)) dic = { - 'shows': show_slugs + 'shows': show_slugs, + 'public-shows': public_show_slugs } return dic -- GitLab