CAS feature + Cells

This commit is contained in:
did 2011-07-25 23:07:32 +02:00
parent e2b68ba861
commit 4f7312a659
35 changed files with 248 additions and 55 deletions

View File

@ -8,6 +8,7 @@ gem 'rails', '3.0.9'
gem 'warden'
gem 'devise', '1.3.4'
gem 'devise_cas_authenticatable', :git => 'git://github.com/Bushido/devise_cas_authenticatable.git'
gem 'mongoid', '~> 2.0.2'
gem 'bson_ext', '~> 1.3.0'
@ -38,6 +39,7 @@ gem 'delayed_job_mongoid', '1.0.2'
gem 'rubyzip'
gem 'locomotive_jammit-s3', :require => 'jammit-s3'
gem 'SystemTimer', :platforms => :ruby_18
gem 'cells'
# The rest of the dependencies are for use when in the locomotive dev environment

View File

@ -0,0 +1,12 @@
#global-actions-bar
- @list.each_with_index do |item, index|
- i18n_options = item.delete(:i18n_options)
- if index > 0
%span= '|'
- if i18n_options
!= t(i18n_options[:key], i18n_options[:arg] => link_to(i18n_options[:value], item[:url]))
- else
= link_to item[:label], item[:url], item.delete_if { |k, v| %w(label url).include?(k) }

View File

@ -0,0 +1,34 @@
class Admin::GlobalActionsCell < ::Admin::MenuCell
attr_reader :current_admin, :current_site_url
def show(args)
@current_admin = args[:current_admin]
@current_site_url = args[:current_site_url]
super
end
protected
def build_list
add :welcome, :url => edit_admin_my_account_url, :i18n_options => {
:key => 'admin.shared.header.welcome',
:arg => :name,
:value => @current_admin.name
}
add :see, :url => current_site_url, :id => 'viewsite', :target => '_blank'
if Locomotive.config.multi_sites? && current_admin.sites.size > 1
add :switch, :url => '#', :id => 'sites-picker-link'
end
add :help, :url => '#', :class => 'tutorial', :id => 'help'
add :logout, :url => destroy_admin_session_url, :confirm => t('admin.messages.confirm')
end
def localize_label(label, options = {})
I18n.t("admin.shared.header.#{label}", options)
end
end

View File

@ -0,0 +1,9 @@
%ul#menu
- @list.each_with_index do |item, index|
- index += 1
%li{ :class => "item #{'first' if index == 1} item-#{index} #{item[:class]}" }
%span
= link_to item[:url] do
%em &nbsp;
%span= item[:label]
%li.clear

View File

@ -0,0 +1,10 @@
class Admin::MainMenuCell < ::Admin::MenuCell
protected
def build_list
add :contents, :url => admin_pages_url
add :settings, :url => edit_admin_current_site_url
end
end

View File

@ -0,0 +1 @@
%p To be overridden

View File

@ -0,0 +1,95 @@
class Admin::MenuCell < Cell::Base
include ::Rails.application.routes.url_helpers
delegate :sections, :to => :parent_controller
attr_accessor :list
def initialize(*args)
super
self.list = []
end
def show(args = {})
self.build_list
render
end
def url_options
super.reverse_merge(
:host => request.host_with_port,
:protocol => request.protocol,
:_path_segments => request.symbolized_path_parameters
).merge(:script_name => request.script_name)
end
class MenuProxy
def initialize(cell)
@cell = cell
end
def method_missing(meth, *args)
@cell.send(meth, *args)
end
end
def self.update_for(name, &block)
method_name = "build_list_with_#{name}".to_sym
previous_method_name = "build_list_without_#{name}".to_sym
self.send(:define_method, method_name) do
self.send(previous_method_name)
block.call(MenuProxy.new(self))
end
alias_method_chain :build_list, name.to_sym
end
protected
def build_list
raise 'the build_list method must be overridden'
end
def build_item(name, attributes)
unless attributes.key?(:label)
attributes[:label] = localize_label(name)
end
attributes.merge!(:name => name, :class => name.to_s.dasherize.downcase)
end
def add(name, attributes)
self.list << build_item(name, attributes)
end
def add_after(pivot, name, attributes)
index = self.list.index { |i| i[:name] == pivot }
self.list.insert(index + 1, self.build_item(name, attributes))
end
def add_before(pivot, name, attributes)
index = self.list.index { |i| i[:name] == pivot }
self.list.insert(index, self.build_item(name, attributes))
end
def modify(name, attributes)
self.find(name).merge!(attributes)
end
def remove(name)
self.list.delete_if { |i| i[:name] == name }
end
def find(name)
self.list.detect { |i| i[:name] == name }
end
def localize_label(label)
I18n.t("admin.shared.menu.#{label}")
end
end

View File

@ -0,0 +1,4 @@
- @list.each do |item|
%li
= link_to item[:url], :class => item[:class] do
%span= item[:label]

View File

@ -0,0 +1,17 @@
class Admin::SettingsMenuCell < ::Admin::MenuCell
protected
def build_list
add :site, :url => edit_admin_current_site_url
add :theme_assets, :url => admin_theme_assets_url
add :account, :url => edit_admin_my_account_url
end
def build_item(name, attributes)
item = super
enhanced_class = "#{'on' if name.to_s == sections(:sub)} #{item[:class]}"
item.merge(:class => enhanced_class)
end
end

View File

@ -9,21 +9,7 @@ module Admin::BaseHelper
end
end
def admin_menu_item(name, url)
index = controller.instance_variable_get(:@menu_index) || 1
controller.instance_variable_set(:@menu_index, index + 1)
label = content_tag(:em, escape_once('&nbsp;')) + content_tag(:span, t("admin.shared.menu.#{name}"))
content_tag(:li, content_tag(:span) + link_to(label, url), :class => "item #{'first' if index == 1} item-#{index} #{name.dasherize}")
end
def admin_button_tag(text, url, options = {})
text = text.is_a?(Symbol) ? t(".#{text}") : text
link_to(url, options) do
content_tag(:em, escape_once('&nbsp;')) + text
end
end
def admin_submenu_item(name, url, options = {}, &block)
def admin_content_menu_item(name, url, options = {}, &block)
default_options = { :i18n => true, :css => name.dasherize.downcase }
default_options.merge!(options)
@ -39,6 +25,13 @@ module Admin::BaseHelper
end
end
def admin_button_tag(text, url, options = {})
text = text.is_a?(Symbol) ? t(".#{text}") : text
link_to(url, options) do
content_tag(:em, escape_once('&nbsp;')) + text
end
end
def admin_item_toggler(object)
image_tag("admin/list/icons/node_#{(cookies["folder-#{object._id}"] != 'none') ? 'open' : 'closed'}.png", :class => 'toggler')
end

View File

@ -45,7 +45,7 @@ module Admin::ContentTypesHelper
url = admin_contents_url(content_type.slug)
css = @content_type && content_type.slug == @content_type.slug ? 'on' : ''
html = admin_submenu_item(label, url, :i18n => false, :css => css) do
html = admin_content_menu_item(label, url, :i18n => false, :css => css) do
yield(content_type)
end

View File

@ -4,8 +4,7 @@ class Account
include Locomotive::Mongoid::Document
# devise modules
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :encryptable, :encryptor => :sha1
devise *Locomotive.config.devise_modules
## attributes ##
field :name

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -1,7 +1,7 @@
- title link_to(@site.name.blank? ? @site.name_was : @site.name, '#', :rel => 'site_name', :title => t('.ask_for_name'), :class => 'editable')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
- if can?(:manage, @site)
- content_for :buttons do

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -4,7 +4,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -4,7 +4,7 @@
= include_javascripts :account
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
- if multi_sites?
- content_for :buttons do

View File

@ -1,18 +1,7 @@
%h1
= link_to current_site.name, admin_pages_url, :class => 'single'
#global-actions-bar
!= t('.welcome', :name => link_to(current_admin.name, edit_admin_my_account_url))
%span= '|'
= link_to t('.see'), current_site_url, :id => 'viewsite', :target => '_blank'
- if multi_sites? && current_admin.sites.size > 1
%span= '|'
= link_to t('.switch'), '#', :id => 'sites-picker-link'
%span= '|'
= link_to 'Help', '#', :class => 'tutorial', :id => 'help'
%span= '|'
= link_to t('.logout'), destroy_admin_session_url, :confirm => t('admin.messages.confirm')
= render_cell 'admin/global_actions', :show, :current_admin => current_admin
- if multi_sites? && current_admin.sites.size > 1
#sites-picker{ :style => 'display: none' }

View File

@ -1,4 +0,0 @@
%ul#menu
= admin_menu_item('contents', admin_pages_url)
= admin_menu_item('settings', edit_admin_current_site_url)
%li.clear

View File

@ -1,4 +1,4 @@
= admin_submenu_item 'pages', admin_pages_url do
= admin_content_menu_item 'pages', admin_pages_url do
- if can? :manage, @page
.header
%p= link_to t('admin.pages.index.new'), new_admin_page_url

View File

@ -1,4 +0,0 @@
= admin_submenu_item 'site', edit_admin_current_site_url
/ = admin_submenu_item 'snippets', admin_snippets_url
= admin_submenu_item 'theme_assets', admin_theme_assets_url
= admin_submenu_item 'account', edit_admin_my_account_url

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
- content_for :buttons do
= admin_button_tag t('admin.snippets.index.new'), new_admin_snippet_url, :class => 'new'

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -1,7 +1,7 @@
- title t('.title', :file => @theme_asset.source_filename)
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
- if can?(:manage, ThemeAsset)
- content_for :buttons do

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
- content_for :buttons do
= admin_button_tag t('admin.snippets.index.new'), new_admin_snippet_url, :class => 'new' if can?(:manage, Snippet)

View File

@ -1,7 +1,7 @@
- title t('.title')
- content_for :submenu do
= render 'admin/shared/menu/settings'
= render_cell 'admin/settings_menu', :show
%p!= t('.help')

View File

@ -16,7 +16,7 @@ module Locomotive
# Add additional load paths for your own custom dirs
# config.load_paths += %W( #{config.root}/extras )
config.autoload_paths += %W( #{config.root}/app/models/extensions #{config.root}/app/models/extensions/site #{config.root}/app/models/extensions/page #{config.root}/app/models/extensions/asset)
config.autoload_paths += %W( #{config.root}/app/models/extensions #{config.root}/app/models/extensions/site #{config.root}/app/models/extensions/page #{config.root}/app/models/extensions/asset #{config.root}/app/cells/admin)
# Only load the plugins named here, in the order given (default is alphabetical).
# :all can be used as a placeholder for all plugins not explicitly named

View File

@ -16,6 +16,7 @@ en:
welcome: Welcome, %{name}
see: See website
switch: Switch to another site
help: Help
logout: Log out
menu:
contents: Contents

View File

@ -26,6 +26,7 @@ fr:
welcome: "Bonjour, %{name}"
see: Voir le site web
switch: Passer à un autre site
help: Aide
logout: Se déconnecter
menu:
contents: Contenu

View File

@ -9,7 +9,8 @@ defaults: &defaults
development:
<<: *defaults
database: locomotive_dev
# database: locomotive_dev
database: locomotive_cas_dev
test:
<<: *defaults

View File

@ -21,7 +21,8 @@ module Locomotive
:verbose => true,
:metastore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/meta"), # URI encoded in case of spaces
:entitystore => URI.encode("file:#{Rails.root}/tmp/dragonfly/cache/body")
}
},
:devise_modules => [:database_authenticatable, :recoverable, :rememberable, :trackable, :validatable, :encryptable, { :encryptor => :sha1 }]
}
cattr_accessor :settings

View File

@ -22,26 +22,44 @@ module Locomotive
module ClassMethods
def bushido_app_claimed?
ENV['BUSHIDO_CLAIMED'].present? && ENV['BUSHIDO_CLAIMED'].to_s.downcase == 'true'
ENV['BUSHIDO_CLAIMED'].present? && Boolean.set(ENV['BUSHIDO_CLAIMED'])
end
def enable_bushido!
self.config.domain = ENV['APP_TLD'] unless self.config.multi_sites?
self.config.devise_modules = [:cas_authenticatable, :rememberable, :trackable]
self.enhance_models
self.disable_authentication_for_not_claimed_app
self.setup_cas_client
self.setup_smtp_settings
self.add_middlewares
self.tweak_ui
self.config.delayed_job = true # force to use delayed_job
self.bushido_domains = ::Bushido::App.domains
self.bushido_subdomain = ::Bushido::App.subdomain
end
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
def enhance_models
Site.send :include, Locomotive::Hosting::Bushido::CustomDomain
Site.send :include, Locomotive::Hosting::Bushido::FirstInstallation
@ -52,6 +70,19 @@ module Locomotive
Admin::BaseController.send :include, Locomotive::Hosting::Bushido::Devise
end
def setup_cas_client
::Devise.setup do |config|
config.cas_base_url = 'https://auth.bushi.do/cas'
config.cas_logout_url = 'https://auth.bushi.do/cas/logout'
end
Admin::SessionsController.class_eval do
def new
redirect_to admin_pages_url
end
end
end
def setup_smtp_settings
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {

View File

@ -30,6 +30,7 @@ Gem::Specification.new do |s|
s.add_dependency "locomotive_liquid", "2.2.2"
s.add_dependency "formtastic", "~> 1.2.3"
s.add_dependency "inherited_resources", "~> 1.1.2"
s.add_dependency "cells"
s.add_dependency "json_pure", "1.5.1"
s.add_dependency "bushido"