Class: Trackguard::Admin::VisitorsController

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

Instance Method Summary collapse

Instance Method Details

#flagObject

rubocop:disable Metrics/AbcSize



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

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 after_action_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 after_action_path, alert: @visitor.errors.full_messages.join(", ") }
      format.json { render json: { errors: @visitor.errors.full_messages }, status: :unprocessable_content }
    end
  end
end

#unflagObject

rubocop:enable Metrics/AbcSize



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

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