fix cohorts in create, and read, and update regular expressions to fix courses with periods not working in General commentable
This commit is contained in:
@@ -84,21 +84,13 @@ def get_opt_course_with_access(user, course_id, action):
|
||||
return get_course_with_access(user, course_id, action)
|
||||
|
||||
|
||||
|
||||
|
||||
def is_course_cohorted(course_id):
|
||||
"""
|
||||
given a course id, return a boolean for whether or not the course is cohorted
|
||||
|
||||
"""
|
||||
|
||||
def get_cohort_id(user, course_id):
|
||||
"""
|
||||
given a course id and a user, return the id of the cohort that user is assigned to
|
||||
and if the course is not cohorted or the user is an instructor, return None
|
||||
|
||||
"""
|
||||
return 101
|
||||
return 127
|
||||
|
||||
def is_commentable_cohorted(course_id,commentable_id):
|
||||
"""
|
||||
|
||||
@@ -39,6 +39,7 @@ log = logging.getLogger("mitx.courseware")
|
||||
template_imports = {'urllib': urllib}
|
||||
|
||||
|
||||
|
||||
def user_groups(user):
|
||||
"""
|
||||
TODO (vshnayder): This is not used. When we have a new plan for groups, adjust appropriately.
|
||||
|
||||
@@ -24,9 +24,9 @@ urlpatterns = patterns('django_comment_client.base.views',
|
||||
url(r'comments/(?P<comment_id>[\w\-]+)/downvote$', 'vote_for_comment', {'value': 'down'}, name='downvote_comment'),
|
||||
url(r'comments/(?P<comment_id>[\w\-]+)/unvote$', 'undo_vote_for_comment', name='undo_vote_for_comment'),
|
||||
|
||||
url(r'(?P<commentable_id>[\w\-]+)/threads/create$', 'create_thread', name='create_thread'),
|
||||
url(r'^(?P<commentable_id>[\w\-.]+)/threads/create$', 'create_thread', name='create_thread'),
|
||||
# TODO should we search within the board?
|
||||
url(r'(?P<commentable_id>[\w\-]+)/threads/search_similar$', 'search_similar_threads', name='search_similar_threads'),
|
||||
url(r'(?P<commentable_id>[\w\-]+)/follow$', 'follow_commentable', name='follow_commentable'),
|
||||
url(r'(?P<commentable_id>[\w\-]+)/unfollow$', 'unfollow_commentable', name='unfollow_commentable'),
|
||||
url(r'^(?P<commentable_id>[\w\-.]+)/threads/search_similar$', 'search_similar_threads', name='search_similar_threads'),
|
||||
url(r'^(?P<commentable_id>[\w\-.]+)/follow$', 'follow_commentable', name='follow_commentable'),
|
||||
url(r'^(?P<commentable_id>[\w\-.]+)/unfollow$', 'unfollow_commentable', name='unfollow_commentable'),
|
||||
)
|
||||
|
||||
@@ -21,11 +21,11 @@ from django.contrib.auth.models import User
|
||||
|
||||
from mitxmako.shortcuts import render_to_response, render_to_string
|
||||
from courseware.courses import get_course_with_access
|
||||
from courseware.courses import get_cohort_id
|
||||
from courseware.courses import get_cohort_id,is_commentable_cohorted
|
||||
|
||||
from django_comment_client.utils import JsonResponse, JsonError, extract, get_courseware_context
|
||||
|
||||
from django_comment_client.permissions import check_permissions_by_view
|
||||
from django_comment_client.permissions import check_permissions_by_view, cached_has_permission
|
||||
from django_comment_client.models import Role
|
||||
|
||||
def permitted(fn):
|
||||
@@ -59,10 +59,17 @@ def ajax_content_response(request, course_id, content, template_name):
|
||||
'annotated_content_info': annotated_content_info,
|
||||
})
|
||||
|
||||
|
||||
|
||||
def is_moderator(user, course_id):
|
||||
cached_has_permission(user, "see_all_cohorts", course_id)
|
||||
|
||||
@require_POST
|
||||
@login_required
|
||||
@permitted
|
||||
def create_thread(request, course_id, commentable_id):
|
||||
print "\n\n\n\n\n*******************"
|
||||
print commentable_id
|
||||
course = get_course_with_access(request.user, course_id, 'load')
|
||||
post = request.POST
|
||||
|
||||
@@ -85,23 +92,28 @@ def create_thread(request, course_id, commentable_id):
|
||||
'user_id' : request.user.id,
|
||||
})
|
||||
|
||||
#now cohort id
|
||||
|
||||
#now cohort the thread if the commentable is cohorted
|
||||
#if the group id came in from the form, set it there, otherwise,
|
||||
#see if the user and the commentable are cohorted
|
||||
print post
|
||||
if is_commentable_cohorted(course_id,commentable_id):
|
||||
if 'group_id' in post: #if a group id was submitted in the form
|
||||
posted_group_id = post['group_id']
|
||||
else:
|
||||
post_group_id = None
|
||||
|
||||
group_id = None
|
||||
|
||||
if 'group_id' in post:
|
||||
group_id = post['group_id']
|
||||
|
||||
|
||||
if group_id is None:
|
||||
group_id = get_cohort_id(request.user, course_id)
|
||||
user_group_id = get_cohort_id(request.user, course_id)
|
||||
|
||||
if group_id is not None:
|
||||
if is_moderator(request.user,course_id):
|
||||
if post_group_id is None:
|
||||
group_id = user_group_id
|
||||
else:
|
||||
group_id = post_group_id
|
||||
else:
|
||||
group_id = user_group_id
|
||||
|
||||
thread.update_attributes(**{'group_id' :group_id})
|
||||
|
||||
|
||||
thread.save()
|
||||
if post.get('auto_subscribe', 'false').lower() == 'true':
|
||||
user = cc.User.from_django_user(request.user)
|
||||
|
||||
@@ -4,7 +4,7 @@ import django_comment_client.forum.views
|
||||
urlpatterns = patterns('django_comment_client.forum.views',
|
||||
url(r'users/(?P<user_id>\w+)/followed$', 'followed_threads', name='followed_threads'),
|
||||
url(r'users/(?P<user_id>\w+)$', 'user_profile', name='user_profile'),
|
||||
url(r'(?P<discussion_id>[\w\-]+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'),
|
||||
url(r'(?P<discussion_id>[\w\-]+)/inline$', 'inline_discussion', name='inline_discussion'),
|
||||
url(r'^(?P<discussion_id>[\w\-.]+)/threads/(?P<thread_id>\w+)$', 'single_thread', name='single_thread'),
|
||||
url(r'^(?P<discussion_id>[\w\-.]+)/inline$', 'inline_discussion', name='inline_discussion'),
|
||||
url(r'', 'forum_form_discussion', name='forum_form_discussion'),
|
||||
)
|
||||
|
||||
@@ -34,7 +34,6 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
|
||||
This may raise cc.utils.CommentClientError or
|
||||
cc.utils.CommentClientUnknownError if something goes wrong.
|
||||
"""
|
||||
|
||||
default_query_params = {
|
||||
'page': 1,
|
||||
'per_page': per_page,
|
||||
@@ -64,6 +63,8 @@ def get_threads(request, course_id, discussion_id=None, per_page=THREADS_PER_PAG
|
||||
group_id = get_cohort_id(user,course_id);
|
||||
if group_id:
|
||||
default_query_params["group_id"] = group_id;
|
||||
print("\n\n\n\n\n****************GROUP ID IS ")
|
||||
print group_id
|
||||
|
||||
query_params = merge_dict(default_query_params,
|
||||
strip_none(extract(request.GET, ['page', 'sort_key', 'sort_order', 'text', 'tags', 'commentable_ids'])))
|
||||
|
||||
@@ -23,7 +23,7 @@ class Command(BaseCommand):
|
||||
student_role.add_permission(per)
|
||||
|
||||
for per in ["edit_content", "delete_thread", "openclose_thread",
|
||||
"endorse_comment", "delete_comment"]:
|
||||
"endorse_comment", "delete_comment", "see_all_cohorts"]:
|
||||
moderator_role.add_permission(per)
|
||||
|
||||
for per in ["manage_moderator"]:
|
||||
|
||||
Reference in New Issue
Block a user