Implement basic ability to close off a forum for a given course such that Students can no longer post or edit, but can still view.
This commit is contained in:
@@ -276,6 +276,22 @@ class CourseDescriptor(SequenceDescriptor):
|
||||
more sensible framework later."""
|
||||
return self.metadata.get('discussion_link', None)
|
||||
|
||||
@property
|
||||
def forum_posts_allowed(self):
|
||||
try:
|
||||
blackout_periods = [(parse_time(start), parse_time(end))
|
||||
for start, end
|
||||
in self.metadata.get('discussion_blackouts', [])]
|
||||
now = time.gmtime()
|
||||
for start, end in blackout_periods:
|
||||
if start <= now <= end:
|
||||
return False
|
||||
except:
|
||||
log.exception("Error parsing discussion_blackouts for course {0}".format(self.id))
|
||||
raise
|
||||
|
||||
return True
|
||||
|
||||
@property
|
||||
def hide_progress_tab(self):
|
||||
"""TODO: same as above, intended to let internal CS50 hide the progress tab
|
||||
|
||||
@@ -2,6 +2,7 @@ from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
import logging
|
||||
|
||||
from courseware.courses import get_course_by_id
|
||||
|
||||
class Role(models.Model):
|
||||
name = models.CharField(max_length=30, null=False, blank=False)
|
||||
@@ -23,6 +24,12 @@ class Role(models.Model):
|
||||
self.permissions.add(Permission.objects.get_or_create(name=permission)[0])
|
||||
|
||||
def has_permission(self, permission):
|
||||
course = get_course_by_id(self.course_id)
|
||||
if self.name == "Student" and \
|
||||
(permission.startswith('edit') or permission.startswith('update') or permission.startswith('create')) and \
|
||||
(not course.forum_posts_allowed):
|
||||
return False
|
||||
|
||||
return self.permissions.filter(name=permission).exists()
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
<%! from django_comment_client.permissions import has_permission %>
|
||||
<%inherit file="../courseware/course_navigation.html" />
|
||||
|
||||
<%block name="extratabs">
|
||||
% if has_permission(user, 'create_thread', course.id):
|
||||
<li class="right"><a href="#" class="new-post-btn"><span class="new-post-icon"></span>New Post</a></li>
|
||||
% endif
|
||||
</%block>
|
||||
@@ -3,4 +3,6 @@
|
||||
<div class="discussion-module" data-discussion-id="${discussion_id | h}">
|
||||
<a class="discussion-show control-button" href="javascript:void(0)" data-discussion-id="${discussion_id | h}"><span class="show-hide-discussion-icon"></span><span class="button-text">Show Discussion</span></a>
|
||||
<a href="#" class="new-post-btn"><span class="new-post-icon"></span>New Post</a>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
<%! from django_comment_client.permissions import has_permission %>
|
||||
|
||||
<script type="text/template" id="thread-template">
|
||||
<article class="discussion-article" data-id="${'<%- id %>'}">
|
||||
<div class="thread-content-wrapper"></div>
|
||||
@@ -7,6 +9,7 @@
|
||||
<div class="post-status-closed bottom-post-status" style="display: none">
|
||||
This thread is closed.
|
||||
</div>
|
||||
% if course is UNDEFINED or has_permission(user, 'create_comment', course.id):
|
||||
<form class="discussion-reply-new" data-id="${'<%- id %>'}">
|
||||
<h4>Post a response:</h4>
|
||||
<ul class="discussion-errors"></ul>
|
||||
@@ -15,6 +18,7 @@
|
||||
<a class="discussion-submit-post control-button" href="#">Submit</a>
|
||||
</div>
|
||||
</form>
|
||||
% endif
|
||||
</article>
|
||||
</script>
|
||||
|
||||
@@ -75,6 +79,7 @@
|
||||
<div class="discussion-response"></div>
|
||||
<ol class="comments">
|
||||
<li class="new-comment response-local">
|
||||
% if course is UNDEFINED or has_permission(user, 'create_sub_comment', course.id):
|
||||
<form class="comment-form" data-id="${'<%- wmdId %>'}">
|
||||
<ul class="discussion-errors"></ul>
|
||||
<div class="comment-body" data-id="${'<%- wmdId %>'}"
|
||||
@@ -83,6 +88,7 @@
|
||||
<a class="discussion-submit-comment control-button" href="#">Submit</a>
|
||||
</div>
|
||||
</form>
|
||||
% endif
|
||||
</li>
|
||||
</ol>
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user