Skip to content

Commit

Permalink
[bug 1094981] Question taken notice
Browse files Browse the repository at this point in the history
  • Loading branch information
rehandalal committed Dec 18, 2014
1 parent 328d156 commit ce7ca9b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion kitsune/questions/api.py
Expand Up @@ -4,6 +4,7 @@
import json
from django.db.models import Q
from rest_framework import serializers, viewsets, permissions, filters, status
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_framework.decorators import action
from rest_framework.response import Response

Expand Down Expand Up @@ -251,7 +252,10 @@ def delete_metadata(self, request, pk=None):
except QuestionMetaData.DoesNotExist:
raise GenericAPIException(404, 'No matching metadata object found.')

@action(methods=['POST'], permission_classes=[permissions.IsAuthenticatedOrReadOnly])
@action(methods=['POST'],
permission_classes=[permissions.IsAuthenticatedOrReadOnly],
# XXX: Fix this to only allow sessions authentication on non-CORS.
authentication_classes=[SessionAuthentication, TokenAuthentication])
def take(self, request, pk=None):
question = self.get_object()
field = serializers.BooleanField()
Expand Down
10 changes: 9 additions & 1 deletion kitsune/questions/templates/questions/question_details.html
Expand Up @@ -29,6 +29,14 @@

{% block above_main %}
<h1>{{ _('Support Forum') }}</h1>

{% if question.is_taken %}
<div class="taken-notice">
{{ _('{user} is currently working on this problem.')|f(user=question.taken_by) }}
<a href="#question-reply">{{ _('Post a reply') }}</a> |
<a href="{{ url('questions.list', question.product.slug) }}">{{ _('View other questions that need attention.') }}</a>
</div>
{% endif %}
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -435,7 +443,7 @@ <h2>{{ _('Installed Plug-ins') }}</h2>
<div class="answer-tools nopadding">
<h3>{{ _('Post a Reply') }}</h3>
</div>
<form action="{{ url('questions.reply', question_id=question.id) }}#question-reply" method="post" enctype="multipart/form-data">
<form action="{{ url('questions.reply', question_id=question.id) }}#question-reply" method="post" enctype="multipart/form-data" data-take-question-url="{{ url('question-take', question.pk) }}">
{{ csrf() }}
{{ errorlist(form) }}

Expand Down
17 changes: 17 additions & 0 deletions kitsune/sumo/static/js/questions.js
Expand Up @@ -38,6 +38,23 @@
$('#support-search input[name=q]')
.val(k.unquote($.cookie('last_search')));

function takeQuestion() {
if ($(this).val().length > 0) {
var $form = $(this).closest('form');
var url = $form.data('take-question-url');
var csrftoken = $('input[name=csrfmiddlewaretoken]').val();
$.ajax({
url: url,
method: 'POST',
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
});
}
}

$('#id_content').on('keyup', _.throttle(takeQuestion, 1000));

$(document).on('click', '#details-edit', function(ev) {
ev.preventDefault();
$('#question-details').addClass('editing');
Expand Down
8 changes: 8 additions & 0 deletions kitsune/sumo/static/less/questions.less
Expand Up @@ -118,6 +118,14 @@ h2 {
}
}

.taken-notice {
background: #fff;
border-left: 3px @textDarkOrange solid;
line-height: 40px;
margin: -15px 0 30px 0;
padding: 0 10px;
}

.main-content {
background: #fff;
margin: 0 0 20px 130px;
Expand Down

0 comments on commit ce7ca9b

Please sign in to comment.