Refactor approval queue to display last meaningful status #94

Merged
Oleg-Komarov merged 13 commits from approval-queue into main 2024-04-30 10:48:38 +02:00
3 changed files with 44 additions and 20 deletions
Showing only changes of commit 60f514df11 - Show all commits

View File

@ -6,27 +6,23 @@
{{ extension.name }} {{ extension.name }}
</a> </a>
</td> </td>
<td> <td>{% include "extensions/components/authors.html" %}</td>
{% if extension.authors.count %}
{% include "extensions/components/authors.html" %}
{% endif %}
</td>
<td title="{{ extension.date_created }}">{{ extension.date_created|naturaltime_compact }}</td> <td title="{{ extension.date_created }}">{{ extension.date_created|naturaltime_compact }}</td>
<td class="d-flex"> <td class="d-flex">
<a href="{{ extension.get_review_url }}#activity"> <a href="{{ extension.get_review_url }}#activity">
<span>{{ extension.review_activity.all|length }}</span> <span>{{ stats.count }}</span>
</a> </a>
<a href="{{ extension.get_review_url }}#activity-{{ stats.last_activity.id }}" class="ml-3">
{% if extension.review_activity.all %} <span>{{ stats.last_activity.date_created|naturaltime_compact }}</span>
<a href="{{ extension.get_review_url }}#activity-{{ extension.review_activity.all.last.id }}" class="ml-3">
<span>{{ extension.review_activity.all.last.date_created|naturaltime_compact }}</span>
</a> </a>
{% endif %}
{% include "files/components/scan_details_flag.html" with file=extension.latest_version.file %} {% include "files/components/scan_details_flag.html" with file=extension.latest_version.file %}
</td> </td>
<td> <td>
<a href="{{ extension.get_review_url }}" class="text-decoration-none"> <a href="{{ extension.get_review_url }}" class="text-decoration-none">
{% include "common/components/status.html" with object=extension class="d-block" %} <div class="d-block badge badge-status-{{ stats.last_type_display|slugify }}">
<i class="i-eye"></i>
<span>{{ stats.last_type_display }}</span>
</div>
</a> </a>
</td> </td>
</tr> </tr>

View File

@ -34,12 +34,10 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for extension in object_list %} {% for stats in object_list %}
{% if user.is_moderator %} {% with extension=stats.extension%}
{% include 'reviewers/components/review_list_item.html' %} {% include 'reviewers/components/review_list_item.html' with extension=extension stats=stats %}
{% elif extension.status_slug == 'awaiting-review' %} {% endwith %}
{% include 'reviewers/components/review_list_item.html' %}
{% endif %}
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>

View File

@ -19,9 +19,39 @@ class ApprovalQueueView(ListView):
paginate_by = 100 paginate_by = 100
def get_queryset(self): def get_queryset(self):
return Extension.objects.exclude(status=Extension.STATUSES.APPROVED).order_by( qs = (
'-date_created' ApprovalActivity.objects.prefetch_related(
'extension',
'extension__authors',
'extension__versions',
'extension__versions__file',
'extension__versions__file__validation',
)
Review

For already existing extensions without activity records ApprovalActivity will have to be created (with the Extension.date_status_changed dates as date_created) to ensure they still show up in the approval queue.

For already existing extensions without activity records `ApprovalActivity` will have to be created (with the `Extension.date_status_changed` dates as `date_created`) to ensure they still show up in the approval queue.
Review

running in shell

from extensions.models import Extension
from reviewers.models import ApprovalActivity

to_create = []
for ext in Extension.objects.filter(status=2).all():
    if ext.review_activity.count() == 0:
        to_create.append(ApprovalActivity(
            type=ApprovalActivity.ActivityType.AWAITING_REVIEW,
            extension=ext,
            user=ext.authors.all()[0],
            date_created=ext.date_status_changed,
            message='Extension is ready for initial review',
        ))

ApprovalActivity.objects.bulk_create(to_create)

for at in to_create:
    at.date_created = at.extension.date_status_changed

ApprovalActivity.objects.bulk_update(to_create, ['date_created'])
running in shell ``` from extensions.models import Extension from reviewers.models import ApprovalActivity to_create = [] for ext in Extension.objects.filter(status=2).all(): if ext.review_activity.count() == 0: to_create.append(ApprovalActivity( type=ApprovalActivity.ActivityType.AWAITING_REVIEW, extension=ext, user=ext.authors.all()[0], date_created=ext.date_status_changed, message='Extension is ready for initial review', )) ApprovalActivity.objects.bulk_create(to_create) for at in to_create: at.date_created = at.extension.date_status_changed ApprovalActivity.objects.bulk_update(to_create, ['date_created']) ```
.order_by('-date_created')
.all()
) )
by_extension = {}
result = []
for item in qs:
extension = item.extension
stats = by_extension.get(extension, None)
if not stats:
# this check guarantees that we add a record only once per extension,
# and iterating over qs we get result also ordered by item.date_created
stats = {
'count': 0,
'extension': extension,
'last_activity': None,
'last_type_display': None,
}
by_extension[extension] = stats
result.append(stats)
stats['count'] += 1
if not stats.get('last_activity', None):
stats['last_activity'] = item
if not stats.get('last_type_display', None):
stats['last_type_display'] = item.get_type_display
return result
template_name = 'reviewers/extensions_review_list.html' template_name = 'reviewers/extensions_review_list.html'