This commit is contained in:
Jeff Balogh 2010-06-30 15:01:05 -07:00
Родитель a536eac150
Коммит 6019803fb9
7 изменённых файлов: 103 добавлений и 8 удалений

Просмотреть файл

@ -47,5 +47,23 @@
"modified": "2010-01-12 17:01:41",
"notifyevents": 1
}
},
{
"pk": 1,
"model": "access.group",
"fields": {
"rules": "*:*",
"modified": null,
"name": "Admins",
"created": "2007-03-05 16:06:55"
}
},
{
"pk": 10,
"model": "access.groupuser",
"fields": {
"group": 1,
"user": 4043307
}
}
]

Просмотреть файл

@ -45,14 +45,19 @@
{% if is_flagged %}
<li>{{ _('Flagged for review') }}</li>
{% else %}
<li class="review-wrapper"><a class="flag-review" href="{{ url('reviews.flag', addon.id, review.id) }}">
{{ _('Report this review') }}</a></li>
<li class="review-wrapper">
<a class="flag-review" href="{{ url('reviews.flag', addon.id, review.id) }}">
{{ _('Report this review') }}</a>
</li>
{% endif %}
{% if perms.is_author or perms.is_admin %}
<li><a href="#TODO">{{ _('Reply to review') }}</a></li>
{% endif %}
{% if perms.can_delete %}
<li><a href="#TODO">{{ _('Delete review') }}</a></li>
<li>
<a class="delete-review" href="{{ url('reviews.delete', addon.id, review.id) }}">
{{ _('Delete review') }}</a>
</li>
{% endif %}
</ul>
{% endif %}

Просмотреть файл

@ -4,6 +4,7 @@ from nose.tools import eq_
import test_utils
from amo.urlresolvers import reverse
from access.models import GroupUser
from reviews.models import Review, ReviewFlag
@ -12,7 +13,7 @@ class TestViews(test_utils.TestCase):
def test_dev_reply(self):
url = reverse('reviews.detail', args=[1865, 218468])
r = self.client.get(url)
self.client.get(url)
class TestFlag(test_utils.TestCase):
@ -59,3 +60,40 @@ class TestFlag(test_utils.TestCase):
response = self.client.post(self.url, {'flag': 'xxx'})
eq_(response.status_code, 400)
eq_(Review.objects.filter(editorreview=True).count(), 0)
class TestDelete(test_utils.TestCase):
fixtures = ['reviews/dev-reply.json', 'base/admin']
def setUp(self):
self.url = reverse('reviews.delete', args=[1865, 218207])
self.client.login(username='jbalogh@mozilla.com', password='password')
def test_no_login(self):
self.client.logout()
response = self.client.post(self.url)
assert isinstance(response, http.HttpResponseRedirect)
def test_no_perms(self):
GroupUser.objects.all().delete()
response = self.client.post(self.url)
eq_(response.status_code, 403)
def test_404(self):
url = reverse('reviews.delete', args=[1865, 0])
response = self.client.post(url)
eq_(response.status_code, 404)
def test_delete_review_with_dev_reply(self):
cnt = Review.objects.count()
response = self.client.post(self.url)
eq_(response.status_code, 200)
# Two are gone since we deleted a review with a reply.
eq_(Review.objects.count(), cnt - 2)
def test_delete_success(self):
Review.objects.update(reply_to=None)
cnt = Review.objects.count()
response = self.client.post(self.url)
eq_(response.status_code, 200)
eq_(Review.objects.count(), cnt - 1)

Просмотреть файл

@ -1,10 +1,17 @@
from django.conf.urls.defaults import patterns, url
from django.conf.urls.defaults import patterns, url, include
from . import views
# These all start with /addon/:id/reviews/:review_id/.
detail_patterns = patterns('',
url('^$', views.review_list, name='reviews.detail'),
url('^flag$', views.flag, name='reviews.flag'),
url('^delete$', views.delete, name='reviews.delete'),
)
urlpatterns = patterns('',
url('^$', views.review_list, name='reviews.list'),
url('^(?P<review_id>\d+)$', views.review_list, name='reviews.detail'),
url('^(?P<review_id>\d+)/flag$', views.flag, name='reviews.flag'),
url('^(?P<review_id>\d+)/', include(detail_patterns)),
url('^user:(?P<user_id>\d+)$', views.review_list, name='reviews.user'),
)

Просмотреть файл

@ -1,6 +1,8 @@
from django import http
from django.contrib.auth.decorators import login_required
from django.shortcuts import get_object_or_404
import commonware.log
import jingo
from tower import ugettext as _
@ -12,6 +14,8 @@ from addons.models import Addon
from .models import Review, ReviewFlag
from .forms import ReviewFlagForm
log = commonware.log.getLogger('z.reviews')
def review_list(request, addon_id, review_id=None, user_id=None):
addon = get_object_or_404(Addon.objects.valid(), id=addon_id)
@ -81,3 +85,17 @@ def flag(request, addon_id, review_id):
'for editor approval.')}
else:
return json_view.error(unicode(form.errors))
@post_required
@login_required
def delete(request, addon_id, review_id):
if not acl.action_allowed(request, 'Editors', 'DeleteReview'):
return http.HttpResponseForbidden()
review = get_object_or_404(Review.objects, pk=review_id, addon=addon_id)
review.delete()
log.info('DELETE: %s deleted %s by %s ("%s": "%s")' %
(request.amo_user.display_name, review_id,
review.user.display_name, review.title, review.body))
# TODO: Insert into event log.
return http.HttpResponse()

Просмотреть файл

@ -117,6 +117,6 @@ form.go button {
display: inherit;
}
.flag-review {
.flag-review, .delete-review {
display: none;
}

Просмотреть файл

@ -37,4 +37,13 @@ $(document).ready(function() {
dataType: 'json'
});
};
$('.delete-review').click(function(e) {
e.preventDefault();
var target = $(e.target);
$.post(target.attr('href'), function() {
target.replaceWith(gettext('Marked for deletion'));
});
target.closest('.review').addClass('deleted');
});
});