2011-06-20 19:05:12 +00:00
|
|
|
require 'bushido'
|
2011-07-26 19:20:03 +00:00
|
|
|
require 'locomotive/hosting/bushido/hooks'
|
2011-06-20 19:05:12 +00:00
|
|
|
require 'locomotive/hosting/bushido/custom_domain'
|
|
|
|
require 'locomotive/hosting/bushido/first_installation'
|
|
|
|
require 'locomotive/hosting/bushido/account_ext'
|
|
|
|
require 'locomotive/hosting/bushido/middleware'
|
|
|
|
require 'locomotive/hosting/bushido/devise'
|
|
|
|
|
|
|
|
module Locomotive
|
|
|
|
module Hosting
|
|
|
|
module Bushido
|
|
|
|
module Enabler
|
|
|
|
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
class << self
|
|
|
|
attr_accessor :bushido_domains
|
|
|
|
attr_accessor :bushido_subdomain
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
|
|
|
|
def bushido_app_claimed?
|
2011-07-25 21:07:32 +00:00
|
|
|
ENV['BUSHIDO_CLAIMED'].present? && Boolean.set(ENV['BUSHIDO_CLAIMED'])
|
2011-06-20 19:05:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def enable_bushido!
|
|
|
|
self.config.domain = ENV['APP_TLD'] unless self.config.multi_sites?
|
|
|
|
|
2011-07-25 21:07:32 +00:00
|
|
|
self.config.devise_modules = [:cas_authenticatable, :rememberable, :trackable]
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
self.enhance_models
|
|
|
|
|
|
|
|
self.disable_authentication_for_not_claimed_app
|
|
|
|
|
2011-07-25 21:07:32 +00:00
|
|
|
self.setup_cas_client
|
|
|
|
|
2011-07-26 19:20:03 +00:00
|
|
|
self.subscribe_to_events
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
self.setup_smtp_settings
|
|
|
|
|
|
|
|
self.add_middlewares
|
|
|
|
|
2011-07-25 21:07:32 +00:00
|
|
|
self.tweak_ui
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
self.config.delayed_job = true # force to use delayed_job
|
|
|
|
|
|
|
|
self.bushido_domains = ::Bushido::App.domains
|
|
|
|
self.bushido_subdomain = ::Bushido::App.subdomain
|
|
|
|
end
|
|
|
|
|
2011-07-25 21:07:32 +00:00
|
|
|
def tweak_ui
|
|
|
|
edit_account_url = 'https://auth.bushi.do/users/edit'
|
|
|
|
|
|
|
|
::Admin::GlobalActionsCell.update_for(:bushido) do |menu|
|
|
|
|
menu.modify :welcome, :url => edit_account_url
|
|
|
|
end
|
|
|
|
|
|
|
|
::Admin::SettingsMenuCell.update_for(:bushido) do |menu|
|
|
|
|
menu.modify :account, :url => edit_account_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
def enhance_models
|
|
|
|
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
|
|
|
|
Site.send :include, Locomotive::Hosting::Bushido::FirstInstallation
|
|
|
|
Account.send :include, Locomotive::Hosting::Bushido::AccountExt
|
|
|
|
end
|
|
|
|
|
|
|
|
def disable_authentication_for_not_claimed_app
|
|
|
|
Admin::BaseController.send :include, Locomotive::Hosting::Bushido::Devise
|
|
|
|
end
|
|
|
|
|
2011-07-25 21:07:32 +00:00
|
|
|
def setup_cas_client
|
|
|
|
::Devise.setup do |config|
|
2011-07-26 19:20:03 +00:00
|
|
|
config.cas_base_url = 'https://auth.bushi.do/cas'
|
|
|
|
config.cas_logout_url = 'https://auth.bushi.do/cas/logout'
|
|
|
|
config.cas_create_user = false
|
2011-11-16 19:32:00 +00:00
|
|
|
config.cas_username_column = :bushido_user_id
|
2011-07-25 21:07:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
Admin::SessionsController.class_eval do
|
|
|
|
def new
|
|
|
|
redirect_to admin_pages_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-06-20 19:05:12 +00:00
|
|
|
def setup_smtp_settings
|
|
|
|
ActionMailer::Base.delivery_method = :smtp
|
|
|
|
ActionMailer::Base.smtp_settings = {
|
|
|
|
:authentication => ENV['SMTP_AUTHENTICATION'],
|
|
|
|
:address => ENV['SMTP_SERVER'],
|
|
|
|
:port => ENV['SMTP_PORT'],
|
|
|
|
:domain => ENV['SMTP_DOMAIN'],
|
|
|
|
:user_name => ENV['SMTP_USER'],
|
|
|
|
:password => ENV['SMTP_PASSWORD'],
|
|
|
|
:enable_starttls_auto => ENV['SMTP_TLS'].to_s == 'true'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_middlewares
|
2011-06-21 00:39:59 +00:00
|
|
|
Rails.application.config.middleware.use '::Locomotive::Hosting::Bushido::Middleware'
|
2011-06-20 19:05:12 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# manage domains
|
|
|
|
|
|
|
|
def add_bushido_domain(name)
|
2011-07-26 19:20:03 +00:00
|
|
|
Locomotive.log "[add bushido domain] #{name}"
|
2011-06-20 19:05:12 +00:00
|
|
|
::Bushido::App.add_domain(name)
|
|
|
|
|
|
|
|
if ::Bushido::Command.last_command_successful?
|
|
|
|
self.bushido_domains << name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_bushido_domain(name)
|
2011-07-26 19:20:03 +00:00
|
|
|
Locomotive.log "[remove bushido domain] #{name}"
|
2011-06-20 19:05:12 +00:00
|
|
|
::Bushido::App.remove_domain(name)
|
|
|
|
|
|
|
|
if ::Bushido::Command.last_command_successful?
|
|
|
|
self.bushido_domains.delete(name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_bushido_subdomain(name)
|
2011-07-26 19:20:03 +00:00
|
|
|
Locomotive.log "[set bushido subdomain] #{name}.bushi.do"
|
2011-06-20 19:05:12 +00:00
|
|
|
::Bushido::App.set_subdomain(name)
|
|
|
|
|
|
|
|
if ::Bushido::Command.last_command_successful?
|
|
|
|
self.bushido_subdomain = name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2011-07-26 02:37:23 +00:00
|
|
|
end
|