feat: adds ability to disable posting in discussions indefinitely (#32171)
* feat: adds ability to disable posting in discussions indefinitely * test: fixed ffailing test cases * test: added new model field in test cases * refactor: removes unnecessary migrations * refactor: removed previous migrations and adds new field in discussions api * refactor: added docstring and changed method name --------- Co-authored-by: ayesha waris <73840786+ayeshoali@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.2.19 on 2023-05-18 09:35
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('discussions', '0015_discussiontopiclink_context'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='discussionsconfiguration',
|
||||
name='posting_restrictions',
|
||||
field=models.CharField(choices=[('enabled', 'Enabled'), ('disabled', 'Disabled'), ('scheduled', 'Scheduled')], default='scheduled', help_text='The Posting availabilty in discussions whether it will be enabled, scheduled or indefinitely disabled.', max_length=15),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='historicaldiscussionsconfiguration',
|
||||
name='posting_restrictions',
|
||||
field=models.CharField(choices=[('enabled', 'Enabled'), ('disabled', 'Disabled'), ('scheduled', 'Scheduled')], default='scheduled', help_text='The Posting availabilty in discussions whether it will be enabled, scheduled or indefinitely disabled.', max_length=15),
|
||||
),
|
||||
]
|
||||
@@ -46,6 +46,15 @@ class Provider:
|
||||
OPEN_EDX = 'openedx'
|
||||
|
||||
|
||||
class PostingRestriction(models.TextChoices):
|
||||
"""
|
||||
Discussions Restrictions choices
|
||||
"""
|
||||
ENABLED = 'enabled'
|
||||
DISABLED = 'disabled'
|
||||
SCHEDULED = 'scheduled'
|
||||
|
||||
|
||||
DEFAULT_CONFIG_ENABLED = True
|
||||
|
||||
|
||||
@@ -413,6 +422,14 @@ class DiscussionsConfiguration(TimeStampedModel):
|
||||
default=True,
|
||||
help_text=_("If disabled, the discussions in the associated learning context/course will be disabled.")
|
||||
)
|
||||
posting_restrictions = models.CharField(
|
||||
max_length=15,
|
||||
default=PostingRestriction.SCHEDULED,
|
||||
choices=PostingRestriction.choices,
|
||||
help_text=_(
|
||||
"The Posting availabilty in discussions whether it will be enabled, scheduled or indefinitely disabled."
|
||||
)
|
||||
)
|
||||
lti_configuration = models.ForeignKey(
|
||||
LtiConfiguration,
|
||||
on_delete=models.SET_NULL,
|
||||
|
||||
@@ -176,6 +176,7 @@ class DiscussionsConfigurationSerializer(serializers.ModelSerializer):
|
||||
'enable_in_context',
|
||||
'enable_graded_units',
|
||||
'unit_level_visibility',
|
||||
'posting_restrictions',
|
||||
]
|
||||
fields = [
|
||||
'enabled',
|
||||
|
||||
@@ -16,6 +16,8 @@ from ..config.waffle import ENABLE_NEW_STRUCTURE_DISCUSSIONS
|
||||
from ..models import DEFAULT_CONFIG_ENABLED, Provider, get_default_provider_type
|
||||
from ..models import DiscussionsConfiguration
|
||||
from ..models import ProviderFilter
|
||||
from ..models import PostingRestriction
|
||||
|
||||
|
||||
SUPPORTED_PROVIDERS = [
|
||||
'legacy',
|
||||
@@ -141,6 +143,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
self.configuration_with_defaults.save()
|
||||
self.configuration_with_values = DiscussionsConfiguration(
|
||||
context_key=self.course_key_with_values,
|
||||
posting_restrictions=PostingRestriction.ENABLED,
|
||||
enabled=False,
|
||||
provider_type=Provider.LEGACY,
|
||||
plugin_configuration={
|
||||
@@ -164,6 +167,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
"""
|
||||
configuration = DiscussionsConfiguration.objects.get(context_key=self.course_key_with_defaults)
|
||||
assert configuration is not None
|
||||
assert configuration.posting_restrictions == PostingRestriction.SCHEDULED
|
||||
assert configuration.enabled # by default
|
||||
assert configuration.lti_configuration is None
|
||||
assert len(configuration.plugin_configuration.keys()) == 0
|
||||
@@ -175,6 +179,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
"""
|
||||
configuration = DiscussionsConfiguration.objects.get(context_key=self.course_key_with_values)
|
||||
assert configuration is not None
|
||||
assert configuration.posting_restrictions == PostingRestriction.ENABLED
|
||||
assert not configuration.enabled
|
||||
assert configuration.lti_configuration is None
|
||||
actual_url = configuration.plugin_configuration.get('url')
|
||||
@@ -187,6 +192,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
Assert we can update an existing record
|
||||
"""
|
||||
configuration = DiscussionsConfiguration.objects.get(context_key=self.course_key_with_defaults)
|
||||
configuration.posting_restrictions = PostingRestriction.SCHEDULED
|
||||
configuration.enabled = False
|
||||
configuration.plugin_configuration = {
|
||||
'url': 'http://localhost',
|
||||
@@ -195,6 +201,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
configuration.save()
|
||||
configuration = DiscussionsConfiguration.objects.get(context_key=self.course_key_with_defaults)
|
||||
assert configuration is not None
|
||||
assert configuration.posting_restrictions == PostingRestriction.SCHEDULED
|
||||
assert not configuration.enabled
|
||||
assert configuration.lti_configuration is None
|
||||
assert configuration.plugin_configuration['url'] == 'http://localhost'
|
||||
@@ -233,6 +240,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
with override_waffle_flag(ENABLE_NEW_STRUCTURE_DISCUSSIONS, active=new_structure_enabled):
|
||||
configuration = DiscussionsConfiguration.get(self.course_key_without_config)
|
||||
assert configuration is not None
|
||||
assert configuration.posting_restrictions == PostingRestriction.SCHEDULED
|
||||
assert configuration.enabled == DEFAULT_CONFIG_ENABLED
|
||||
assert configuration.provider_type == default_provider_type
|
||||
assert not configuration.lti_configuration
|
||||
@@ -244,6 +252,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
"""
|
||||
configuration = DiscussionsConfiguration.get(self.course_key_with_defaults)
|
||||
assert configuration is not None
|
||||
assert configuration.posting_restrictions == PostingRestriction.SCHEDULED
|
||||
assert configuration.enabled
|
||||
assert not configuration.lti_configuration
|
||||
assert not configuration.plugin_configuration
|
||||
@@ -255,6 +264,7 @@ class DiscussionsConfigurationModelTest(TestCase):
|
||||
"""
|
||||
configuration = DiscussionsConfiguration.get(self.course_key_with_values)
|
||||
assert configuration is not None
|
||||
assert configuration.posting_restrictions == PostingRestriction.ENABLED
|
||||
assert not configuration.enabled
|
||||
assert not configuration.lti_configuration
|
||||
assert configuration.plugin_configuration
|
||||
|
||||
Reference in New Issue
Block a user