Skip to content

Commit

Permalink
fix: use disabled as default for posting_restrictions (openedx#33159)
Browse files Browse the repository at this point in the history
  • Loading branch information
AhtishamShahid authored Sep 5, 2023
1 parent 2b5ed92 commit aec8fcd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
6 changes: 5 additions & 1 deletion lms/djangoapps/discussion/rest_api/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
)
from openedx.core.djangoapps.course_groups.models import CourseUserGroupPartitionGroup
from openedx.core.djangoapps.course_groups.tests.helpers import CohortFactory
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider
from openedx.core.djangoapps.discussions.models import DiscussionsConfiguration, DiscussionTopicLink, Provider, \
PostingRestriction
from openedx.core.djangoapps.discussions.tasks import update_discussions_settings_from_course_task
from openedx.core.djangoapps.django_comment_common.models import (
FORUM_ROLE_ADMINISTRATOR,
Expand Down Expand Up @@ -151,6 +152,9 @@ def _set_course_discussion_blackout(course, user_id):
datetime.now(UTC) - timedelta(days=3),
datetime.now(UTC) + timedelta(days=3)
]
configuration = DiscussionsConfiguration.get(course.id)
configuration.posting_restrictions = PostingRestriction.SCHEDULED
configuration.save()
modulestore().update_item(course, user_id)


Expand Down
5 changes: 4 additions & 1 deletion lms/djangoapps/discussion/rest_api/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from common.djangoapps.student.roles import CourseStaffRole, CourseInstructorRole
from lms.djangoapps.discussion.django_comment_client.tests.utils import ForumsEnableMixin
from lms.djangoapps.discussion.rest_api.tests.utils import CommentsServiceMockMixin, ThreadMock
from openedx.core.djangoapps.discussions.models import PostingRestriction
from openedx.core.djangoapps.discussions.models import PostingRestriction, DiscussionsConfiguration
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory

Expand Down Expand Up @@ -43,6 +43,9 @@ def setUp(self):
self.course = CourseFactory.create()
self.course.discussion_blackouts = [datetime.now(UTC) - timedelta(days=3),
datetime.now(UTC) + timedelta(days=3)]
configuration = DiscussionsConfiguration.get(self.course.id)
configuration.posting_restrictions = PostingRestriction.SCHEDULED
configuration.save()
self.student_role = RoleFactory(name='Student', course_id=self.course.id)
self.moderator_role = RoleFactory(name='Moderator', course_id=self.course.id)
self.community_ta_role = RoleFactory(name='Community TA', course_id=self.course.id)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.20 on 2023-09-04 10:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('discussions', '0017_alter_historicaldiscussionsconfiguration_options'),
]

operations = [
migrations.AlterField(
model_name='discussionsconfiguration',
name='posting_restrictions',
field=models.CharField(choices=[('enabled', 'Enabled'), ('disabled', 'Disabled'), ('scheduled', 'Scheduled')], default='disabled', help_text='The Posting availability in discussions whether it will be enabled, scheduled or indefinitely disabled.', max_length=15),
),
migrations.AlterField(
model_name='historicaldiscussionsconfiguration',
name='posting_restrictions',
field=models.CharField(choices=[('enabled', 'Enabled'), ('disabled', 'Disabled'), ('scheduled', 'Scheduled')], default='disabled', help_text='The Posting availability in discussions whether it will be enabled, scheduled or indefinitely disabled.', max_length=15),
),
]
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/discussions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,10 @@ class DiscussionsConfiguration(TimeStampedModel):
)
posting_restrictions = models.CharField(
max_length=15,
default=PostingRestriction.SCHEDULED,
default=PostingRestriction.DISABLED,
choices=PostingRestriction.choices,
help_text=_(
"The Posting availabilty in discussions whether it will be enabled, scheduled or indefinitely disabled."
"The Posting availability in discussions whether it will be enabled, scheduled or indefinitely disabled."
)
)
lti_configuration = models.ForeignKey(
Expand Down
10 changes: 5 additions & 5 deletions openedx/core/djangoapps/discussions/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_get_with_defaults(self):
"""
configuration = DiscussionsConfiguration.objects.get(context_key=self.course_key_with_defaults)
assert configuration is not None
assert configuration.posting_restrictions == PostingRestriction.SCHEDULED
assert configuration.posting_restrictions == PostingRestriction.DISABLED
assert configuration.enabled # by default
assert configuration.lti_configuration is None
assert len(configuration.plugin_configuration.keys()) == 0
Expand All @@ -192,7 +192,7 @@ def test_update_defaults(self):
Assert we can update an existing record
"""
configuration = DiscussionsConfiguration.objects.get(context_key=self.course_key_with_defaults)
configuration.posting_restrictions = PostingRestriction.SCHEDULED
configuration.posting_restrictions = PostingRestriction.DISABLED
configuration.enabled = False
configuration.plugin_configuration = {
'url': 'http://localhost',
Expand All @@ -201,7 +201,7 @@ def test_update_defaults(self):
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 configuration.posting_restrictions == PostingRestriction.DISABLED
assert not configuration.enabled
assert configuration.lti_configuration is None
assert configuration.plugin_configuration['url'] == 'http://localhost'
Expand Down Expand Up @@ -240,7 +240,7 @@ def test_get_nonexistent_defaults(self, new_structure_enabled, default_provider_
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.posting_restrictions == PostingRestriction.DISABLED
assert configuration.enabled == DEFAULT_CONFIG_ENABLED
assert configuration.provider_type == default_provider_type
assert not configuration.lti_configuration
Expand All @@ -252,7 +252,7 @@ def test_get_defaults(self):
"""
configuration = DiscussionsConfiguration.get(self.course_key_with_defaults)
assert configuration is not None
assert configuration.posting_restrictions == PostingRestriction.SCHEDULED
assert configuration.posting_restrictions == PostingRestriction.DISABLED
assert configuration.enabled
assert not configuration.lti_configuration
assert not configuration.plugin_configuration
Expand Down

0 comments on commit aec8fcd

Please sign in to comment.