Class: Trackguard::Admin::VisitorsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/trackguard/admin/visitors_controller.rb

Instance Method Summary collapse

Instance Method Details

#flagObject

rubocop:disable Metrics/AbcSize



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/trackguard/admin/visitors_controller.rb', line 15

def flag
  if @visitor.update(
    flagged_at: Time.current,
    flag_reason: params[:flag_reason].presence,
    flagged_by: params[:flagged_by].presence || Visitor::FLAGGED_BY.first,
    name: params[:name].presence || BlockedUserAgent.matching_pattern(@visitor.user_agent)
  )
    respond_to do |format|
      format.html { redirect_back_or_to dashboard_path }
      format.json { render json: { status: "ok", ip: @visitor.ip, flagged_at: @visitor.flagged_at } }
    end
  else
    respond_to do |format|
      format.html { redirect_back_or_to dashboard_path, alert: @visitor.errors.full_messages.join(", ") }
      format.json { render json: { errors: @visitor.errors.full_messages }, status: :unprocessable_entity }
    end
  end
end

#unflagObject

rubocop:enable Metrics/AbcSize



35
36
37
38
39
40
41
# File 'app/controllers/trackguard/admin/visitors_controller.rb', line 35

def unflag
  @visitor.update!(flagged_at: nil, flag_reason: nil, flagged_by: nil)
  respond_to do |format|
    format.html { redirect_back_or_to dashboard_path }
    format.json { render json: { status: "ok", ip: @visitor.ip } }
  end
end