diff --git a/doc/discussion.md b/doc/discussion.md index 5c273842ad..4f8ab9a01a 100644 --- a/doc/discussion.md +++ b/doc/discussion.md @@ -58,6 +58,32 @@ In the discussion service, notifications are handled asynchronously using a thir bundle exec rake jobs:work +## Initialize roles and permissions + +To fully test the discussion forum, you might want to act as a moderator or an administrator. Currently, moderators can manage everything in the forum, and administrator can manage everything plus assigning and revoking moderator status of other users. + +First make sure that the database is up-to-date: + + rake django-admin[syncdb] + rake django-admin[migrate] + +For convenience, add the following environment variables to the terminal (assuming that you're using configuration set lms.envs.dev): + + export DJANGO_SETTINGS_MODULE=lms.envs.dev + export PYTHONPATH=. + +Now initialzie roles and permissions: + + django-admin.py seed_permissions_roles + +To assign yourself as a moderator, use the following command (assuming your username is "test", and the course id is "MITx/6.002x/2012_Fall"): + + django-admin.py assign_role test Moderator "MITx/6.002x/2012_Fall" + +To assign yourself as an administrator, use the following command + + django-admin.py assign_role test Administrator "MITx/6.002x/2012_Fall" + ## Some other useful commands ### generate seeds for a specific forum @@ -104,18 +130,30 @@ We also have a command for generating comments within a forum with the specified bundle exec rake db:generate_comments[type_the_discussion_id_here] -For instance, if you want to generate comments for the general discussion, for which the discussion id is the course id with slashes and dots replaced by underscores (you **should** do this before testing forum view) and you are in 6.002x, use the following command +For instance, if you want to generate comments for a new discussion tab named "lab_3", then use the following command - bundle exec rake db:generate_comments[MITx_6_002x_2012_Fall] + bundle exec rake db:generate_comments[lab_3] ### Running tests for the service bundle exec rspec -Warning: due to an unresolved bug in the test code, testing the service will "flush" the development database. So you need to generate seed again after testing. +Warning: the development and test environments share the same elasticsearch index. After running tests, search may not work in the development environment. You simply need to reindex: + + bundle exec rake db:reindex_search ### debugging the service You can use the following command to launch a console within the service environment: bundle exec rake console + +### show user roles and permissions + +Use the following command to see the roles and permissions of a user in a given course (assuming, again, that the username is "test"): + + django-admin.py show_permissions moderator + +You need to make sure that the environment variables are exported. Otherwise you would need to do + + django-admin.py show_permissions moderator --settings=lms.envs.dev --pythonpath=. diff --git a/lms/djangoapps/django_comment_client/forum/urls.py b/lms/djangoapps/django_comment_client/forum/urls.py index bc6b08b3d6..76957a82d8 100644 --- a/lms/djangoapps/django_comment_client/forum/urls.py +++ b/lms/djangoapps/django_comment_client/forum/urls.py @@ -5,5 +5,5 @@ urlpatterns = patterns('django_comment_client.forum.views', 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+)$', 'forum_form_discussion', name='forum_form_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 44b36d5b72..c5b4a19d3a 100644 --- a/lms/djangoapps/django_comment_client/forum/views.py +++ b/lms/djangoapps/django_comment_client/forum/views.py @@ -24,6 +24,10 @@ import dateutil THREADS_PER_PAGE = 5 PAGES_NEARBY_DELTA = 2 + +def _general_discussion_id(course_id): + return course_id.replace('/', '_').replace('.', '_') + def _should_perform_search(request): return bool(request.GET.get('text', False) or \ request.GET.get('tags', False)) @@ -57,7 +61,7 @@ def render_discussion(request, course_id, threads, *args, **kwargs): base_url = { 'inline': (lambda: reverse('django_comment_client.forum.views.inline_discussion', args=[course_id, discussion_id])), - 'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id, discussion_id])), + 'forum': (lambda: reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id])), 'user': (lambda: reverse('django_comment_client.forum.views.user_profile', args=[course_id, user_id])), }[discussion_type]() @@ -93,11 +97,11 @@ def render_forum_discussion(*args, **kwargs): def render_user_discussion(*args, **kwargs): return render_discussion(discussion_type='user', *args, **kwargs) -def get_threads(request, course_id, discussion_id): +def get_threads(request, course_id, discussion_id=None): query_params = { 'page': request.GET.get('page', 1), 'per_page': THREADS_PER_PAGE, #TODO maybe change this later - 'sort_key': request.GET.get('sort_key', 'date'), + 'sort_key': request.GET.get('sort_key', 'activity'), 'sort_order': request.GET.get('sort_order', 'desc'), 'text': request.GET.get('text', ''), 'tags': request.GET.get('tags', ''), @@ -129,22 +133,19 @@ def render_search_bar(request, course_id, discussion_id=None, text=''): } return render_to_string('discussion/_search_bar.html', context) -def forum_form_discussion(request, course_id, discussion_id): +def forum_form_discussion(request, course_id): course = check_course(request.user, course_id) - threads, query_params = get_threads(request, course_id, discussion_id) - content = render_forum_discussion(request, course_id, threads, discussion_id=discussion_id, \ - query_params=query_params) + threads, query_params = get_threads(request, course_id) + content = render_forum_discussion(request, course_id, threads, discussion_id=_general_discussion_id(course_id), query_params=query_params) recent_active_threads = cc.search_recent_active_threads( course_id, recursive=False, - query_params={'follower_id': request.user.id, - 'commentable_id': discussion_id}, + query_params={'follower_id': request.user.id}, ) trending_tags = cc.search_trending_tags( course_id, - query_params={'commentable_id': discussion_id}, ) if request.is_ajax(): @@ -154,7 +155,6 @@ def forum_form_discussion(request, course_id, discussion_id): 'csrf': csrf(request)['csrf_token'], 'course': course, 'content': content, - 'accordion': render_accordion(request, course, discussion_id), 'recent_active_threads': recent_active_threads, 'trending_tags': trending_tags, } diff --git a/lms/lib/comment_client/thread.py b/lms/lib/comment_client/thread.py index 510432e2f9..4025d15d61 100644 --- a/lms/lib/comment_client/thread.py +++ b/lms/lib/comment_client/thread.py @@ -35,13 +35,17 @@ class Thread(models.Model): url = cls.url(action='search') else: url = cls.url(action='get_all', params=extract(params, 'commentable_id')) - del params['commentable_id'] + if params.get('commentable_id'): + del params['commentable_id'] response = perform_request('get', url, params, *args, **kwargs) return response.get('collection', []), response.get('page', 1), response.get('num_pages', 1) @classmethod def url_for_threads(cls, params={}): - return "{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id']) + if params.get('commentable_id'): + return "{prefix}/{commentable_id}/threads".format(prefix=settings.PREFIX, commentable_id=params['commentable_id']) + else: + return "{prefix}/threads".format(prefix=settings.PREFIX) @classmethod def url_for_search_threads(cls, params={}): diff --git a/lms/static/sass/_discussion.scss b/lms/static/sass/_discussion.scss index 12ec834663..3582240383 100644 --- a/lms/static/sass/_discussion.scss +++ b/lms/static/sass/_discussion.scss @@ -102,10 +102,12 @@ $tag-text-color: #5b614f; li { @include clearfix; margin-bottom: 8px; + border: none; } a { @include standard-discussion-link; + background: none; } } diff --git a/lms/templates/course_navigation.html b/lms/templates/course_navigation.html index 2d259e6d29..f6903d42b6 100644 --- a/lms/templates/course_navigation.html +++ b/lms/templates/course_navigation.html @@ -19,7 +19,7 @@ def url_class(url):
  • Textbook
  • % endif % if settings.MITX_FEATURES.get('ENABLE_DISCUSSION_SERVICE'): -
  • Discussion
  • +
  • Discussion
  • News
  • % endif % endif diff --git a/lms/templates/discussion/_thread.html b/lms/templates/discussion/_thread.html index 45ba3513d3..7975173396 100644 --- a/lms/templates/discussion/_thread.html +++ b/lms/templates/discussion/_thread.html @@ -44,10 +44,10 @@ <%def name="render_content(content, type, **kwargs)">
    -
    +
    ${render_vote(content)} -
    +
      % if type == 'comment':
    • Endorse
    • @@ -96,7 +96,7 @@ <%def name="render_tags(content, type, **kwargs)"> <% def url_for_tags(tags): - return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id, content['commentable_id']]) + '?' + urllib.urlencode({'tags': ",".join(tags)}) + return reverse('django_comment_client.forum.views.forum_form_discussion', args=[course_id]) + '?' + urllib.urlencode({'tags': ",".join(tags)}) %> % if type == "thread":
      diff --git a/lms/templates/discussion/index.html b/lms/templates/discussion/index.html index 965e8e091f..f34152c569 100644 --- a/lms/templates/discussion/index.html +++ b/lms/templates/discussion/index.html @@ -16,10 +16,6 @@
      -
      -

      Discussion Boards

      - close -