Skip to content

Commit

Permalink
fix: fixed creating post based on discussion restrictions settings
Browse files Browse the repository at this point in the history
  • Loading branch information
ayesha-waris committed May 29, 2024
1 parent b264988 commit 5cdda11
Showing 1 changed file with 11 additions and 6 deletions.
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['posting_restrictions']
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

0 comments on commit 5cdda11

Please sign in to comment.