Module: Beta::AccessHelpers
- Defined in:
- lib/beta/access_helpers.rb
Overview
AccessHelpers encapsulates the functionality for whitespacing. This will usually be included in ApplicationController and acccessed as before_filters
Instance Method Summary collapse
-
#current_user_on_whitelist? ⇒ Boolean
Uses ‘is_whitelisted?` with the value of `current_user`.
-
#is_whitelisted?(user) ⇒ Boolean
Uses redis whitelist to detect if the given user has beta access.
-
#whitelist(redirection = nil) ⇒ Object
Uses redis whitelist and cookies to detect beta access.
Instance Method Details
#current_user_on_whitelist? ⇒ Boolean
Uses ‘is_whitelisted?` with the value of `current_user`
33 34 35 |
# File 'lib/beta/access_helpers.rb', line 33 def current_user_on_whitelist? is_whitelisted? current_user end |
#is_whitelisted?(user) ⇒ Boolean
Uses redis whitelist to detect if the given user has beta access
28 29 30 |
# File 'lib/beta/access_helpers.rb', line 28 def is_whitelisted? user Beta.redis.sismember("#{Beta.namespace}:#{::Rails.env}:beta", user.try(Beta.uid)) end |
#whitelist(redirection = nil) ⇒ Object
Uses redis whitelist and cookies to detect beta access. Redirects on failure.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/beta/access_helpers.rb', line 8 def whitelist redirection = nil return true unless Beta.environments.include?(::Rails.env) if .signed["#{Beta.namespace}-beta"] == "#{Beta.namespace}-beta-#{request.remote_addr}" return true end return false unless authenticate unless current_user_on_whitelist? redirect_to(redirection || Beta.redirect_url) return end .signed["#{Beta.namespace}-beta"] = "#{Beta.namespace}-beta-#{request.remote_addr}" end |