PROD-202: Add per-course flag to block access to youtube videos. Can be set
for courses that have lost access to their youtube channels.
This commit is contained in:
@@ -8,10 +8,12 @@ from django.contrib import admin
|
||||
|
||||
from openedx.core.djangoapps.video_config.forms import (
|
||||
CourseHLSPlaybackFlagAdminForm,
|
||||
CourseYoutubeBlockedFlagAdminForm,
|
||||
CourseVideoTranscriptFlagAdminForm,
|
||||
)
|
||||
from openedx.core.djangoapps.video_config.models import (
|
||||
CourseHLSPlaybackEnabledFlag, HLSPlaybackEnabledFlag,
|
||||
CourseYoutubeBlockedFlag,
|
||||
CourseVideoTranscriptEnabledFlag, VideoTranscriptEnabledFlag,
|
||||
TranscriptMigrationSetting, MigrationEnqueuedCourse,
|
||||
VideoThumbnailSetting, UpdatedCourseVideos,
|
||||
@@ -44,6 +46,14 @@ class CourseHLSPlaybackEnabledFlagAdmin(CourseSpecificEnabledFlagBaseAdmin):
|
||||
form = CourseHLSPlaybackFlagAdminForm
|
||||
|
||||
|
||||
class CourseYoutubeBlockedFlagAdmin(CourseSpecificEnabledFlagBaseAdmin):
|
||||
"""
|
||||
Admin of youtube blocking feature on course-by-course basis.
|
||||
Allows searching by course id.
|
||||
"""
|
||||
form = CourseYoutubeBlockedFlagAdminForm
|
||||
|
||||
|
||||
class CourseVideoTranscriptEnabledFlagAdmin(CourseSpecificEnabledFlagBaseAdmin):
|
||||
"""
|
||||
Admin of Video Transcript feature on course-by-course basis.
|
||||
@@ -79,7 +89,7 @@ class UpdatedCourseVideosAdmin(admin.ModelAdmin):
|
||||
|
||||
admin.site.register(HLSPlaybackEnabledFlag, ConfigurationModelAdmin)
|
||||
admin.site.register(CourseHLSPlaybackEnabledFlag, CourseHLSPlaybackEnabledFlagAdmin)
|
||||
|
||||
admin.site.register(CourseYoutubeBlockedFlag, CourseYoutubeBlockedFlagAdmin)
|
||||
admin.site.register(VideoTranscriptEnabledFlag, ConfigurationModelAdmin)
|
||||
admin.site.register(CourseVideoTranscriptEnabledFlag, CourseVideoTranscriptEnabledFlagAdmin)
|
||||
admin.site.register(TranscriptMigrationSetting, ConfigurationModelAdmin)
|
||||
|
||||
@@ -8,6 +8,7 @@ from django import forms
|
||||
|
||||
from openedx.core.djangoapps.video_config.models import (
|
||||
CourseHLSPlaybackEnabledFlag,
|
||||
CourseYoutubeBlockedFlag,
|
||||
CourseVideoTranscriptEnabledFlag,
|
||||
)
|
||||
from openedx.core.lib.courses import clean_course_id
|
||||
@@ -41,6 +42,16 @@ class CourseHLSPlaybackFlagAdminForm(CourseSpecificFlagAdminBaseForm):
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class CourseYoutubeBlockedFlagAdminForm(CourseSpecificFlagAdminBaseForm):
|
||||
"""
|
||||
Form for course-specific youtube blocking configuration.
|
||||
"""
|
||||
|
||||
class Meta(object):
|
||||
model = CourseYoutubeBlockedFlag
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class CourseVideoTranscriptFlagAdminForm(CourseSpecificFlagAdminBaseForm):
|
||||
"""
|
||||
Form for course-specific Video Transcript configuration.
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.23 on 2019-08-25 16:11
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import opaque_keys.edx.django.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('video_config', '0007_videothumbnailsetting_offset'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='CourseYoutubeBlockedFlag',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('change_date', models.DateTimeField(auto_now_add=True, verbose_name='Change date')),
|
||||
('enabled', models.BooleanField(default=False, verbose_name='Enabled')),
|
||||
('course_id', opaque_keys.edx.django.models.CourseKeyField(db_index=True, max_length=255)),
|
||||
('changed_by', models.ForeignKey(editable=False, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Changed by')),
|
||||
],
|
||||
options={
|
||||
'ordering': ('-change_date',),
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
||||
@@ -78,6 +78,41 @@ class CourseHLSPlaybackEnabledFlag(ConfigurationModel):
|
||||
)
|
||||
|
||||
|
||||
class CourseYoutubeBlockedFlag(ConfigurationModel):
|
||||
"""
|
||||
Disables the playback of youtube videos for a given course.
|
||||
If the flag is present for the course, and set to "enabled",
|
||||
then youtube is disabled for that course.
|
||||
.. no_pii
|
||||
"""
|
||||
KEY_FIELDS = ('course_id',)
|
||||
|
||||
course_id = CourseKeyField(max_length=255, db_index=True)
|
||||
|
||||
@classmethod
|
||||
def feature_enabled(cls, course_id):
|
||||
"""
|
||||
Determine if the youtube blocking feature is enabled for the specified course id.
|
||||
Argument:
|
||||
course_id (CourseKey): course id for whom feature will be checked
|
||||
"""
|
||||
feature = (CourseYoutubeBlockedFlag.objects
|
||||
.filter(course_id=course_id)
|
||||
.order_by('-change_date')
|
||||
.first())
|
||||
return feature.enabled if feature else False
|
||||
|
||||
def __unicode__(self):
|
||||
not_en = "Not "
|
||||
if self.enabled:
|
||||
not_en = ""
|
||||
|
||||
return u"Course '{course_key}': Youtube Block {not_enabled}Enabled".format(
|
||||
course_key=six.text_type(self.course_id),
|
||||
not_enabled=not_en
|
||||
)
|
||||
|
||||
|
||||
class VideoTranscriptEnabledFlag(ConfigurationModel):
|
||||
"""
|
||||
Enables Video Transcript across the platform.
|
||||
|
||||
Reference in New Issue
Block a user