Skip to content

Commit

Permalink
suggestions: Allow to specify rejection reason
Browse files Browse the repository at this point in the history
Fixes #1661
  • Loading branch information
nijel committed Apr 25, 2023
1 parent ae32bbc commit 6d503c0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 4 deletions.
1 change: 1 addition & 0 deletions weblate/static/icons/comment-remove.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions weblate/static/loader-bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,15 @@ $(function () {
$(this).closest("tr").toggleClass("warning", this.checked);
});

/* Suggestion rejection */
$(".rejection-reason").on("keydown", function (event) {
if (event.key === "Enter") {
$(this).closest("form").find("[name='delete']").click();
event.preventDefault();
return false;
}
});

/* Warn users that they do not want to use developer console in most cases */
console.log(
"%c" +
Expand Down
8 changes: 8 additions & 0 deletions weblate/templates/last-changes-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@
{% if details %}
{{ details }}
{% elif change.show_content and change.unit %}
{% if change.details.rejection_reason %}
<label>{% trans "Rejection reason" %}</label>
<div class="list-group">
<div class="list-group-item sidebar-button">
{{ change.details.rejection_reason }}
</div>
</div>
{% endif %}
<label>{{ change.unit.translation.component.source_language }}</label>
{% format_translation change.get_source change.unit.translation.component.source_language %}
<label>
Expand Down
3 changes: 2 additions & 1 deletion weblate/templates/snippets/suggestions.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
{% if has_antispam and suggestion.user != user %}
<button type="submit" class="btn btn-link red" name="spam" value="{{ suggestion.id }}" title="{% trans "Mark as spam" %}">{% icon "spam.svg" %}</button>
{% endif %}
<button type="submit" class="btn btn-link red" name="delete" value="{{ suggestion.id }}" title="{% trans "Delete" %}">{% icon "delete.svg" %}</button>
<input type="text" name="rejection" class="rejection-reason" placeholder="{% trans "Rejection reason" %}" >
<button type="submit" class="btn btn-link red" name="delete" value="{{ suggestion.id }}" title="{% trans "Reject suggestion" %}">{% icon "comment-remove.svg" %}</button>
{% endif %}
{% if suggestion.user and not suggestion.user.is_anonymous %}
{% perm 'project.permissions' suggestion.unit.translation as user_can_edit_permissions %}
Expand Down
15 changes: 13 additions & 2 deletions weblate/trans/models/suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,25 @@ def accept(self, request, permission="suggestion.accept"):
# Delete the suggestion
self.delete()

def delete_log(self, user, change=Change.ACTION_SUGGESTION_DELETE, is_spam=False):
def delete_log(
self,
user,
change=Change.ACTION_SUGGESTION_DELETE,
is_spam: bool = False,
rejection_reason: str = "",
):
"""Delete with logging change."""
if is_spam and self.userdetails:
report_spam(
self.userdetails["address"], self.userdetails["agent"], self.target
)
Change.objects.create(
unit=self.unit, action=change, user=user, target=self.target, author=user
unit=self.unit,
action=change,
user=user,
target=self.target,
author=user,
details={"rejection_reason": rejection_reason},
)
self.delete()

Expand Down
6 changes: 5 additions & 1 deletion weblate/trans/views/edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,11 @@ def handle_suggestions(request, unit, this_unit_url, next_unit_url):
if "accept" in request.POST:
redirect_url = next_unit_url
elif "delete" in request.POST or "spam" in request.POST:
suggestion.delete_log(request.user, is_spam="spam" in request.POST)
suggestion.delete_log(
request.user,
is_spam="spam" in request.POST,
rejection_reason=request.POST.get("rejection", ""),
)
elif "upvote" in request.POST:
suggestion.add_vote(request, Vote.POSITIVE)
redirect_url = next_unit_url
Expand Down

0 comments on commit 6d503c0

Please sign in to comment.