From a23db9e97fb7038e90e447d99965498707a5dc0b Mon Sep 17 00:00:00 2001 From: Gregory Koberger Date: Tue, 10 May 2011 15:11:00 -0700 Subject: [PATCH] Show files reviewed in Item History (bug 655256) --- apps/editors/helpers.py | 20 +++++++++++++++---- .../templates/editors/includes/history.html | 16 +++++++++++++++ apps/editors/tests/test_views.py | 15 ++++++++++++++ apps/editors/views.py | 20 +++++++++++++++---- 4 files changed, 63 insertions(+), 8 deletions(-) diff --git a/apps/editors/helpers.py b/apps/editors/helpers.py index 1724add37c..6073dec18d 100644 --- a/apps/editors/helpers.py +++ b/apps/editors/helpers.py @@ -222,7 +222,7 @@ class ReviewHelper: self.actions = self.get_actions() def set_data(self, data): - self.handler.data = data + self.handler.set_data(data) def get_review_type(self, request, addon, version): if self.addon.status in NOMINATED_STATUSES: @@ -333,6 +333,7 @@ class ReviewBase: self.addon = addon self.version = version self.review_type = review_type + self.files = None def set_addon(self, **kw): """Alters addon and sets reviewed timestamp on version.""" @@ -354,10 +355,13 @@ class ReviewBase: file.save() def log_action(self, action): + details = {'comments': self.data['comments'], + 'reviewtype': self.review_type} + if self.files: + details['files'] = [f.id for f in self.files] + amo.log(action, self.addon, self.version, user=self.user.get_profile(), - created=datetime.now(), - details={'comments': self.data['comments'], - 'reviewtype': self.review_type}) + created=datetime.now(), details=details) def notify_email(self, template, subject): """Notify the authors that their addon has been reviewed.""" @@ -407,6 +411,10 @@ class ReviewBase: class ReviewAddon(ReviewBase): + def set_data(self, data): + self.data = data + self.files = self.version.files.all() + def process_public(self): """Set an addon to public.""" if self.review_type == 'preliminary': @@ -472,6 +480,10 @@ class ReviewAddon(ReviewBase): class ReviewFiles(ReviewBase): + def set_data(self, data): + self.data = data + self.files = data.get('addon_files', None) + def process_public(self): """Set an addons files to public.""" if self.review_type == 'preliminary': diff --git a/apps/editors/templates/editors/includes/history.html b/apps/editors/templates/editors/includes/history.html index bd941dd498..873e5fe656 100644 --- a/apps/editors/templates/editors/includes/history.html +++ b/apps/editors/templates/editors/includes/history.html @@ -17,6 +17,22 @@
{{ record.details.comments|nl2br }}
+ {% if record.details.files %} + + {% endif %} {% endif %} diff --git a/apps/editors/tests/test_views.py b/apps/editors/tests/test_views.py index c940ea8724..b40964455a 100644 --- a/apps/editors/tests/test_views.py +++ b/apps/editors/tests/test_views.py @@ -1237,6 +1237,21 @@ class TestReview(ReviewBase): eq_(validation.find('a').length, 3) + def test_files_in_item_history(self): + data = {'action': 'public', 'operating_systems': 'win', + 'applications': 'something', 'comments': 'something', + 'addon_files': [self.version.files.all()[0].pk]} + + self.client.post(self.url, data) + + r = self.client.get(self.url) + doc = pq(r.content) + + eq_(doc('#review-files tbody tr').length, 1) + li = doc('#review-files .history_comment').parent().find('li') + eq_(li.length, 1) + eq_(li.find('strong').text(), "All Platforms") + def test_no_items(self): response = self.client.get(self.url) eq_(pq(response.content).find('#file-history').next().text(), diff --git a/apps/editors/views.py b/apps/editors/views.py index 6c455b396d..ff104a40ce 100644 --- a/apps/editors/views.py +++ b/apps/editors/views.py @@ -26,7 +26,7 @@ from editors.models import (EditorSubscription, ViewPendingQueue, EventLog, CannedResponse, PerformanceGraph) from editors.helpers import (ViewPendingQueueTable, ViewFullReviewQueueTable, ViewPreliminaryQueueTable) -from files.models import Approval +from files.models import Approval, File from reviews.forms import ReviewFlagFormSet from reviews.models import Review, ReviewFlag from users.models import UserProfile @@ -119,6 +119,18 @@ def _editor_progress(): return (progress, percentage) +def _get_history(addon): + files = [] + history = (ActivityLog.objects.for_addons(addon).order_by('created') + .filter(action__in=amo.LOG_REVIEW_QUEUE)) + + for h in history: + if 'files' in h.details: + files.extend(h.details['files']) + + return history, File.objects.in_bulk(files) + + @editor_required def performance(request, user_id=False): user = request.amo_user @@ -429,15 +441,15 @@ def review(request, version_id): # We only allow the user to check/uncheck files for "pending" allow_unchecking_files = form.helper.review_type == "pending" + history, files = _get_history(addon) + ctx = context(version=version, addon=addon, flags=Review.objects.filter(addon=addon, flag=True), form=form, paging=paging, canned=canned, is_admin=is_admin, status_types=amo.STATUS_CHOICES, show_diff=show_diff, allow_unchecking_files=allow_unchecking_files, actions=actions, actions_minimal=actions_minimal, - history=ActivityLog.objects.for_addons(addon) - .order_by('created') - .filter(action__in=amo.LOG_REVIEW_QUEUE)) + history=history, files=files) return jingo.render(request, 'editors/review.html', ctx)