Class: BeetleReporter::ReportsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/beetle_reporter/reports_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#current_user

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 23

def create
  # authorize Report
  
  create_params = report_params.to_hash.deep_symbolize_keys
  @report = report_scope.new(create_params)
  @report.user = current_user
  
  respond_to do |format|
    if @report.save
      format.turbo_stream { render turbo_stream: turbo_stream.replace(dom_id(@report), partial: "report", locals: {report: @report}) }
      format.html { redirect_to reports_path, notice: "report was successfully created." }
    else
      format.html { render :edit, status: :unprocessable_entity }
    end
  end
end

#destroyObject



59
60
61
62
63
64
65
66
67
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 59

def destroy
  # authorize @report
  
  @report.discard
  
  respond_to do |format|
    format.turbo_stream
  end
end

#editObject



40
41
42
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 40

def edit
  # authorize @report
end

#forbidObject



115
116
117
118
119
120
121
122
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 115

def forbid
  @report.beetle_forbid(params[:reason])

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully forbiden.' }
  end
end

#hideObject



87
88
89
90
91
92
93
94
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 87

def hide
  @report.beetle_hide(params[:reason])

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully hidden.' }
  end
end

#ignoreObject



69
70
71
72
73
74
75
76
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 69

def ignore
  @report.ignore!

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully ignored.' }
  end
end

#indexObject



5
6
7
8
9
10
11
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 5

def index
  # authorize Report
  
  load_reports
  
  # skip_policy_scope
end

#muteObject



105
106
107
108
109
110
111
112
113
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 105

def mute
  # TODO: 禁言时间
  @report.beetle_mute(params[:reason])

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully muted.' }
  end
end

#newObject



17
18
19
20
21
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 17

def new
  # authorize Report
  
  @report = Report.new
end

#removeObject



96
97
98
99
100
101
102
103
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 96

def remove
  @report.beetle_remove(params[:reason])

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully removed.' }
  end
end

#showObject



13
14
15
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 13

def show
  # authorize @report
end

#suspendObject



78
79
80
81
82
83
84
85
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 78

def suspend
  @report.suspend!

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully suspended.' }
  end
end

#undoObject



124
125
126
127
128
129
130
131
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 124

def undo
  @report.undo!

  respond_to do |format|
    format.turbo_stream { render turbo_stream: turbo_stream.remove(dom_id(@report)) }
    format.html { redirect_to reports_url, notice: 'report was successfully undo.' }
  end
end

#updateObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/beetle_reporter/reports_controller.rb', line 44

def update
  # authorize @report
  
  update_params = report_params.to_hash.deep_symbolize_keys
  
  respond_to do |format|
    if @report.update(update_params)
      format.turbo_stream { render turbo_stream: turbo_stream.replace(dom_id(@report), partial: "report", locals: {report: @report}) }
      format.html { redirect_to reports_path, notice: "report was successfully updated." }
    else
      format.html { render :edit, status: :unprocessable_entity }
    end
  end
end