Undo an Official Warning

:bookmark: This guide explains how to remove an official warning in Discourse via the console, particularly aimed at self-hosting users.

:person_raising_hand: Required user level: System Administrator
:desktop_computer: Console access required

In certain situations, a warning issued to a user may need to be retracted. This action involves removing the warning through the console, which is accessible for those with server access. If you are a hosted customer, please contact the Discourse team (team@discourse.org) for assistance with this process.

Understanding user warnings

Official warnings involve two pieces of data in the Discourse database:

  1. A record in the user_warnings table linking the warning to a user and topic.
  2. The associated private message topic has its subtype set to "moderator_warning".

To fully undo a warning, both need to be addressed: the user_warnings record must be deleted, and the topic’s subtype must be reset.

Removing an official warning

To remove a warning, follow these steps:

  1. Access the server console:

    • Use SSH to connect to your Discourse server.
    • Enter the console with the following commands:
      cd /var/discourse/
      ./launcher enter app
      rails console
      
  2. Remove the latest warning:
    If the warning you want to delete is the most recent one, execute:

    warning = UserWarning.last
    warning.topic.update(subtype: TopicSubtype.user_to_user)
    warning.destroy
    
  3. Find and remove a specific warning:
    If the warning wasn’t the last one, search for the specific warning using the user_id:

    UserWarning.where(user_id: the_user_id)
    

    This will return an array of warnings related to the user. Once you find the correct id, remove it using:

    warning = UserWarning.find(3)
    warning.topic.update(subtype: TopicSubtype.user_to_user)
    warning.destroy
    

Destroying the warning record and resetting the topic subtype will remove the warning from the user’s warning count and unmark the PM as an official warning. The private message itself will not be deleted.

Last edited by @SaraDev 2024-11-13T00:51:26Z

Check documentPerform check on document:
20 лайков

Есть ли возможность поделиться шагами, которые мне нужно предпринять для входа в консоль? Я пытался найти информацию в Google, но все руководства, похоже, предполагают, что пользователь уже знает, как это сделать.

Предполагая, что вы следовали стандартному руководству по установке, вам нужно будет подключиться к серверу по SSH и выполнить:

cd /var/discourse/
./launcher enter app
rails console
3 лайка

Привет, @JammyDodger. Возможно, стоит добавить магическую ссылку, которая будет вести на «консоль» и/или «rails» (или, возможно, «rails console»), например:

2 лайка

Хм, это идея. :thinking: Хотя меня уже обжигали на таких вещах. :slight_smile:

Давайте я буду внимательнее следить за этим, раз вы об этом сказали, и посмотрю, как часто это будет встречаться. :+1:


Сейчас мы пересматриваем документацию, поэтому, возможно, в данном случае будет хорошо добавить полные инструкции в руководство.

3 лайка

Или, может быть, раздел будет называться «Что можно сделать в Rails», и информации из раздела «О проекте» или аналогичного будет достаточно.

Разве не было бы гораздо проще обрабатывать это как штрафы и вести журнал всех официальных предупреждений, чтобы администраторы и модераторы могли управлять ими в любой момент? Это создаёт большие трудности, когда модератор случайно выносит предупреждение пользователю с похожим именем, после чего вынужден обращаться к администратору сайта для решения проблемы.

1 лайк

Думаю, здесь есть запрос на #фичу:

2 лайка

Есть ли способ сделать это также через API, а не только через консоль Rails?