Commit 3761b02c by Rocky Duan

hide reply button after closing thread

parent 575a91e2
...@@ -156,7 +156,11 @@ def openclose_thread(request, course_id, thread_id): ...@@ -156,7 +156,11 @@ def openclose_thread(request, course_id, thread_id):
thread = cc.Thread.find(thread_id) thread = cc.Thread.find(thread_id)
thread.closed = request.POST.get('closed', 'false').lower() == 'true' thread.closed = request.POST.get('closed', 'false').lower() == 'true'
thread.save() thread.save()
return JsonResponse(thread.to_dict()) thread = thread.to_dict()
return JsonResponse({
'content': thread,
'ability': utils.get_ability(course_id, thread, request.user),
})
@require_POST @require_POST
@login_required @login_required
......
...@@ -164,6 +164,16 @@ class QueryCountDebugMiddleware(object): ...@@ -164,6 +164,16 @@ class QueryCountDebugMiddleware(object):
logging.info('%s queries run, total %s seconds' % (len(connection.queries), total_time)) logging.info('%s queries run, total %s seconds' % (len(connection.queries), total_time))
return response return response
def get_ability(course_id, content, user):
return {
'editable': check_permissions_by_view(user, course_id, content, "update_thread" if content['type'] == 'thread' else "update_comment"),
'can_reply': check_permissions_by_view(user, course_id, content, "create_comment" if content['type'] == 'thread' else "create_sub_comment"),
'can_endorse': check_permissions_by_view(user, course_id, content, "endorse_comment") if content['type'] == 'comment' else False,
'can_delete': check_permissions_by_view(user, course_id, content, "delete_thread" if content['type'] == 'thread' else "delete_comment"),
'can_openclose': check_permissions_by_view(user, course_id, content, "openclose_thread") if content['type'] == 'thread' else False,
'can_vote': check_permissions_by_view(user, course_id, content, "vote_for_thread" if content['type'] == 'thread' else "vote_for_comment"),
}
def get_annotated_content_info(course_id, content, user, user_info): def get_annotated_content_info(course_id, content, user, user_info):
voted = '' voted = ''
if content['id'] in user_info['upvoted_ids']: if content['id'] in user_info['upvoted_ids']:
...@@ -173,14 +183,7 @@ def get_annotated_content_info(course_id, content, user, user_info): ...@@ -173,14 +183,7 @@ def get_annotated_content_info(course_id, content, user, user_info):
return { return {
'voted': voted, 'voted': voted,
'subscribed': content['id'] in user_info['subscribed_thread_ids'], 'subscribed': content['id'] in user_info['subscribed_thread_ids'],
'ability': { 'ability': get_ability(course_id, content, user),
'editable': check_permissions_by_view(user, course_id, content, "update_thread" if content['type'] == 'thread' else "update_comment"),
'can_reply': check_permissions_by_view(user, course_id, content, "create_comment" if content['type'] == 'thread' else "create_sub_comment"),
'can_endorse': check_permissions_by_view(user, course_id, content, "endorse_comment") if content['type'] == 'comment' else False,
'can_delete': check_permissions_by_view(user, course_id, content, "delete_thread" if content['type'] == 'thread' else "delete_comment"),
'can_openclose': check_permissions_by_view(user, course_id, content, "openclose_thread") if content['type'] == 'thread' else False,
'can_vote': check_permissions_by_view(user, course_id, content, "vote_for_thread" if content['type'] == 'thread' else "vote_for_comment"),
},
} }
def get_annotated_content_infos(course_id, thread, user, user_info): def get_annotated_content_infos(course_id, thread, user, user_info):
......
...@@ -90,7 +90,9 @@ if Backbone? ...@@ -90,7 +90,9 @@ if Backbone?
ability: (ability) -> ability: (ability) ->
for action, elemSelector of @model.actions for action, elemSelector of @model.actions
if not ability[action] if not ability[action]
@$(elemSelector).parent().remove() @$(elemSelector).parent().hide()
else
@$(elemSelector).parent().show()
$discussionContent: -> $discussionContent: ->
@_discussionContent ||= @$el.children(".discussion-content") @_discussionContent ||= @$el.children(".discussion-content")
...@@ -271,6 +273,7 @@ if Backbone? ...@@ -271,6 +273,7 @@ if Backbone?
data: data data: data
success: (response, textStatus) => success: (response, textStatus) =>
@model.set('closed', not closed) @model.set('closed', not closed)
@model.set('ability', response.ability)
edit: (event) -> edit: (event) ->
@$(".discussion-content-wrapper").hide() @$(".discussion-content-wrapper").hide()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment