1# frozen_string_literal: true
2
3class Admin::SpamLogsController < Admin::ApplicationController
4  feature_category :not_owned
5
6  # rubocop: disable CodeReuse/ActiveRecord
7  def index
8    @spam_logs = SpamLog.order(id: :desc).page(params[:page])
9  end
10  # rubocop: enable CodeReuse/ActiveRecord
11
12  def destroy
13    spam_log = SpamLog.find(params[:id])
14
15    if params[:remove_user]
16      spam_log.remove_user(deleted_by: current_user)
17      redirect_to admin_spam_logs_path,
18                  status: :found,
19                  notice: _('User %{username} was successfully removed.') % { username: spam_log.user.username }
20    else
21      spam_log.destroy
22      head :ok
23    end
24  end
25
26  def mark_as_ham
27    spam_log = SpamLog.find(params[:id])
28
29    if Spam::HamService.new(spam_log).execute
30      redirect_to admin_spam_logs_path, notice: _('Spam log successfully submitted as ham.')
31    else
32      redirect_to admin_spam_logs_path, alert: _('Error with Akismet. Please check the logs for more info.')
33    end
34  end
35end
36