From def2d8adf22eea0e941deb615b6543e1c531ab5d Mon Sep 17 00:00:00 2001 From: Kevin Chugh Date: Thu, 24 Jan 2013 14:20:18 -0500 Subject: [PATCH] fix cohorts in create, and read, and update regular expressions to fix courses with periods not working in General commentable --- lms/djangoapps/courseware/courses.py | 10 +---- lms/djangoapps/courseware/views.py | 1 + .../django_comment_client/base/urls.py | 8 ++-- .../django_comment_client/base/views.py | 40 ++++++++++++------- .../django_comment_client/forum/urls.py | 4 +- .../django_comment_client/forum/views.py | 3 +- .../commands/seed_permissions_roles.py | 2 +- 7 files changed, 37 insertions(+), 31 deletions(-) diff --git a/lms/djangoapps/courseware/courses.py b/lms/djangoapps/courseware/courses.py index b4e8da2633..74f5e4c54f 100644 --- a/lms/djangoapps/courseware/courses.py +++ b/lms/djangoapps/courseware/courses.py @@ -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): """ diff --git a/lms/djangoapps/courseware/views.py b/lms/djangoapps/courseware/views.py index b1c4a5e9a9..f170f3fb86 100644 --- a/lms/djangoapps/courseware/views.py +++ b/lms/djangoapps/courseware/views.py @@ -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. diff --git a/lms/djangoapps/django_comment_client/base/urls.py b/lms/djangoapps/django_comment_client/base/urls.py index f2cb4ccb15..23f2afa037 100644 --- a/lms/djangoapps/django_comment_client/base/urls.py +++ b/lms/djangoapps/django_comment_client/base/urls.py @@ -24,9 +24,9 @@ urlpatterns = patterns('django_comment_client.base.views', url(r'comments/(?P[\w\-]+)/downvote$', 'vote_for_comment', {'value': 'down'}, name='downvote_comment'), url(r'comments/(?P[\w\-]+)/unvote$', 'undo_vote_for_comment', name='undo_vote_for_comment'), - url(r'(?P[\w\-]+)/threads/create$', 'create_thread', name='create_thread'), + url(r'^(?P[\w\-.]+)/threads/create$', 'create_thread', name='create_thread'), # TODO should we search within the board? - url(r'(?P[\w\-]+)/threads/search_similar$', 'search_similar_threads', name='search_similar_threads'), - url(r'(?P[\w\-]+)/follow$', 'follow_commentable', name='follow_commentable'), - url(r'(?P[\w\-]+)/unfollow$', 'unfollow_commentable', name='unfollow_commentable'), + url(r'^(?P[\w\-.]+)/threads/search_similar$', 'search_similar_threads', name='search_similar_threads'), + url(r'^(?P[\w\-.]+)/follow$', 'follow_commentable', name='follow_commentable'), + url(r'^(?P[\w\-.]+)/unfollow$', 'unfollow_commentable', name='unfollow_commentable'), ) diff --git a/lms/djangoapps/django_comment_client/base/views.py b/lms/djangoapps/django_comment_client/base/views.py index d1948c3fc7..c1e188ff1a 100644 --- a/lms/djangoapps/django_comment_client/base/views.py +++ b/lms/djangoapps/django_comment_client/base/views.py @@ -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) diff --git a/lms/djangoapps/django_comment_client/forum/urls.py b/lms/djangoapps/django_comment_client/forum/urls.py index 526ae3e582..1e676dee87 100644 --- a/lms/djangoapps/django_comment_client/forum/urls.py +++ b/lms/djangoapps/django_comment_client/forum/urls.py @@ -4,7 +4,7 @@ import django_comment_client.forum.views urlpatterns = patterns('django_comment_client.forum.views', url(r'users/(?P\w+)/followed$', 'followed_threads', name='followed_threads'), url(r'users/(?P\w+)$', 'user_profile', name='user_profile'), - url(r'(?P[\w\-]+)/threads/(?P\w+)$', 'single_thread', name='single_thread'), - url(r'(?P[\w\-]+)/inline$', 'inline_discussion', name='inline_discussion'), + url(r'^(?P[\w\-.]+)/threads/(?P\w+)$', 'single_thread', name='single_thread'), + url(r'^(?P[\w\-.]+)/inline$', 'inline_discussion', name='inline_discussion'), url(r'', 'forum_form_discussion', name='forum_form_discussion'), ) diff --git a/lms/djangoapps/django_comment_client/forum/views.py b/lms/djangoapps/django_comment_client/forum/views.py index 0e8a044097..443329ec1f 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -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']))) diff --git a/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py b/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py index 3faa846033..958b67cdb3 100644 --- a/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py +++ b/lms/djangoapps/django_comment_client/management/commands/seed_permissions_roles.py @@ -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"]: