docbrown/config/application.rb
Andy Zhao 3e89796d9d Add API Analytics Endpoints (#2293)
* Add API endpoints for analytics

* Remove comment and spacing

* Use proper time formatting

* Refactor and clean up some logic

* Add pro and org member traits

* Use shared examples for analytics API spec

* Add analytics authorization specs

* Remove accidental include Pundit

* Raise not_authorized for invalid requests

* Make attributes and time methods private

* Add custom UnauthorizedError

* Raise and use rescue_from to handle 4xx requests

* Enforce date parameters to follow a specific format

* Use current user to allow same origin requests

* Use custom headers and not params for token auth

* Default to current user for same origin requests

* Use correct boolean for choosing user

* Update tests to use request headers and add stricter tests
2019-04-04 10:52:45 -04:00

59 lines
2.5 KiB
Ruby

require_relative "boot"
require "rails/all"
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
module PracticalDeveloper
class Application < Rails::Application
config.load_defaults 5.1
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
config.autoload_paths += Dir["#{config.root}/app/labor/"]
config.autoload_paths += Dir["#{config.root}/app/decorators/"]
config.autoload_paths += Dir["#{config.root}/app/services/"]
config.autoload_paths += Dir["#{config.root}/app/liquid_tags/"]
config.autoload_paths += Dir["#{config.root}/app/observers/"]
config.autoload_paths += Dir["#{config.root}/app/black_box/"]
config.autoload_paths += Dir["#{config.root}/app/sanitizers"]
config.autoload_paths += Dir["#{config.root}/app/facades"]
config.autoload_paths += Dir["#{config.root}/app/errors"]
config.autoload_paths += Dir["#{config.root}/lib/"]
config.active_record.observers = :article_observer, :reaction_observer, :comment_observer
config.active_job.queue_adapter = :delayed_job
config.middleware.use Rack::Deflater
# Globally handle Pundit::NotAuthorizedError by serving 404
config.action_dispatch.rescue_responses["Pundit::NotAuthorizedError"] = :not_found
# After-initialize checker to add routes to reserved words
config.after_initialize do
Rails.application.reload_routes!
top_routes = []
Rails.application.routes.routes.each do |route|
route = route.path.spec.to_s
unless route.starts_with?("/:")
route = route.split("/")[1]
route = route.split("(")[0] if route&.include?("(")
top_routes << route
end
end
ReservedWords.all = [ReservedWords::BASE_WORDS + top_routes].flatten.compact.uniq
end
end
end