Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed creating post based on discussion restrictions settings #34872

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions xmodule/course_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class EmailString(String):
"""
Parse String with email validation
"""

def from_json(self, value):
if value:
validate_email(value)
Expand Down Expand Up @@ -226,6 +227,7 @@ class ProctoringProvider(String):
ProctoringProvider field, which includes validation of the provider
and default that pulls from edx platform settings.
"""

def from_json(self, value):
"""
Return ProctoringProvider as full featured Python type. Perform validation on the provider
Expand Down Expand Up @@ -1457,15 +1459,18 @@ def get_discussion_blackout_datetimes(self):
@property
def forum_posts_allowed(self):
"""
Return whether forum posts are allowed by the discussion_blackouts
setting
Return whether forum posts are allowed by the discussion_blackouts setting
Checks if posting restrictions are enabled or if there's a currently ongoing blackout period.
"""

blackouts = self.get_discussion_blackout_datetimes()
posting_restrictions = self.discussions_settings.get('posting_restrictions', 'disabled')
now = datetime.now(utc)
for blackout in blackouts:
if blackout["start"] <= now <= blackout["end"]:
return False
return True

if posting_restrictions == 'enabled':
return False

return all(not (blackout["start"] <= now <= blackout["end"]) for blackout in blackouts)

@property
def number(self):
Expand Down
3 changes: 3 additions & 0 deletions xmodule/modulestore/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class XModuleFactoryLock(threading.local):
after ensuring that a) the modulestore will be cleaned up, and b) that XModuleFactoryLock.disable
will be called.
"""

def __init__(self):
super().__init__()
self._enabled = False
Expand Down Expand Up @@ -123,6 +124,7 @@ def _create(cls, target_class, **kwargs): # lint-amnesty, pylint: disable=argum
run = kwargs.pop('run', name)
user_id = kwargs.pop('user_id', ModuleStoreEnum.UserID.test)
emit_signals = kwargs.pop('emit_signals', False)

# By default course has enrollment_start in the future which means course is closed for enrollment.
# We're setting the 'enrollment_start' field to None to reduce number of arguments needed to setup course.
# Use the 'default_enrollment_start=True' kwarg to skip this and use the default enrollment_start date.
Expand Down Expand Up @@ -478,6 +480,7 @@ class StackTraceCounter:
"""
A class that counts unique stack traces underneath a particular stack frame.
"""

def __init__(self, stack_depth, include_arguments=True):
"""
Arguments:
Expand Down
Loading