Class: ClientBlacklist::BlacklistFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/kill_switch/client_blacklist.rb

Overview

Rails Before Filter Class Implementation

Class Method Summary collapse

Class Method Details

.before(controller) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/kill_switch/client_blacklist.rb', line 80

def self.before(controller)
  user_agent = controller.request.user_agent
  unless ClientBlacklist.user_agent_valid?(user_agent)
    controller.render(
      json: {
        data: {
          message: "User agent string is missing or invalid. Received [#{user_agent}]" },
          metadata: nil,
      },
      status: 400,
    )
    return false
  end

  if ClientBlacklist.agent_blacklisted?(user_agent)
    controller.render(
      json: {
        data: {
            message: "This version [#{user_agent}] is no longer supported. Please visit the App Store to upgrade to the most recent version."
        },
        metadata: nil,
      },
      status: 403,
    )
    return false
  end
  return true # All checks passed
end