Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable soft-locking functionality for media reports to assist simultaneous moderators #4374

Closed
wants to merge 23 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
12b7190
Create a lock manager class to encapsulate locking utilities
dhruvkb May 23, 2024
a9c976c
Create admin endpoints for soft locking/unlocking
dhruvkb May 23, 2024
6bc0e6b
Highlight works that are in-moderation in the list view
dhruvkb May 23, 2024
385690d
Add a message if another moderator is looking at the same report
dhruvkb May 23, 2024
b97ef4e
Call the lock/unlock endpoints based on client events
dhruvkb May 23, 2024
2168445
Fix case of "API" in the Django Admin UI
dhruvkb May 23, 2024
d97dbc5
Handle failure to connect to Redis
dhruvkb May 23, 2024
88f9863
Add function to get score for a username-object pair
dhruvkb May 23, 2024
c2e373a
Add tests for `LockManager`
dhruvkb May 23, 2024
2d08af0
Use singular lock from usernames to report IDs
dhruvkb May 24, 2024
9a9ffad
Create a function to get all moderators
dhruvkb May 24, 2024
58ba5f7
Avoid using `KEYS` because of bad performance
dhruvkb May 24, 2024
a5632e9
Use very short TTL for locks
dhruvkb May 24, 2024
2e7c59e
Remove `self.redis` in favour of getting connections when needed
dhruvkb May 24, 2024
53368df
Remove need for unlocking as TTL is very short
dhruvkb May 24, 2024
26cd1c6
Simplify the Redis handler decorator
dhruvkb May 24, 2024
5562bbb
Send the expiration timestamp in the lock endpoint response
dhruvkb May 24, 2024
7db9145
Highlight soft-locks in single Redis query
dhruvkb May 24, 2024
00b9999
Cleanup code in `change_view`
dhruvkb May 24, 2024
e4bee71
Undo frivolous change
dhruvkb May 24, 2024
48783cc
Fix punctuation
dhruvkb May 24, 2024
a705df6
Update `soft_lock_view` API endpoint docstring
dhruvkb May 24, 2024
157457d
Merge branch 'main' into 'soft_lock'
dhruvkb May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Highlight works that are in-moderation in the list view
dhruvkb committed May 23, 2024

Verified

This commit was signed with the committer’s verified signature.
strider Gaël Chamoulaud
commit 6bc0e6ba7c591f79d33d11b75dd77f5ad73c8eb5
25 changes: 24 additions & 1 deletion api/api/admin/media_report.py
Original file line number Diff line number Diff line change
@@ -138,8 +138,17 @@ def get_changelist(self, request, **kwargs):


class MediaReportAdmin(admin.ModelAdmin):
change_list_template = "admin/api/media_report/change_list.html"
change_form_template = "admin/api/media_report/change_form.html"
list_display = ("id", "reason", "is_pending", "description", "created_at", "url")
list_display = (
"id",
"reason",
"is_pending",
"description",
"created_at",
"url",
"get_is_soft_locked",
)
list_filter = (
("decision", admin.EmptyFieldListFilter), # ~status, i.e. pending or moderated
"reason",
@@ -151,6 +160,20 @@ class MediaReportAdmin(admin.ModelAdmin):
actions = None
media_type = None

@admin.display(boolean=True, description="Soft locked")
def get_is_soft_locked(self, obj):
"""
Get whether this particular report is soft-locked.
This field is hidden from the rendered table, but the alt-text
the field helps to highlight the soft-locked rows.
:param obj: the report object
:return bool: whether the report is soft-locked
"""

return len(self.lock_manager.moderator_set(obj.id)) != 0

def __init__(self, *args, **kwargs):
self.lock_manager = LockManager(self.media_type)
super().__init__(*args, **kwargs)
23 changes: 23 additions & 0 deletions api/api/templates/admin/api/media_report/change_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{% extends "admin/change_list.html" %}
{% load i18n admin_urls static admin_list %}

{% block extrastyle %}
{{ block.super }}
<style>
th.column-get_is_soft_locked,td.field-get_is_soft_locked {
display: none;
}

tr:has(td.field-get_is_soft_locked>img[alt="True"]) {
background-color: var(--message-warning-bg);
}
</style>
{% endblock %}

{% block result_list %}
<p>
<strong>Note:</strong>
Reports that are being moderated by another user are highlighted in yellow.
</p>
{{ block.super }}
{% endblock %}