Merge branch 'routing-filter'

This commit is contained in:
Benjamin Meichsner 2010-05-25 23:16:49 +02:00
commit 00d9f060cc
29 changed files with 282 additions and 260 deletions

View File

@ -1,7 +1,5 @@
class AdminController < ApplicationController
class Admin::BaseController < ApplicationController
before_filter :authenticate_admin
filter_parameter_logging :password, :password_confirmation # do not log passwort parameters
def index
@user = self.current_user

View File

@ -1,5 +1,4 @@
class Admin::OrdergroupsController < ApplicationController
before_filter :authenticate_admin
class Admin::OrdergroupsController < Admin::BaseController
def index
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)

View File

@ -1,6 +1,4 @@
class Admin::UsersController < ApplicationController
before_filter :authenticate_admin
filter_parameter_logging :password, :password_confirmation # do not log passwort parameters
class Admin::UsersController < Admin::BaseController
def index
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)

View File

@ -1,5 +1,4 @@
class Admin::WorkgroupsController < ApplicationController
before_filter :authenticate_admin
class Admin::WorkgroupsController < Admin::BaseController
def index
if (params[:per_page] && params[:per_page].to_i > 0 && params[:per_page].to_i <= 100)

View File

@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
filter_parameter_logging :password, :password_confirmation # do not log passwort parameters
before_filter :select_foodcoop, :authenticate, :store_controller
after_filter :remove_controller
@ -23,128 +24,137 @@ class ApplicationController < ActionController::Base
protected
def current_user
begin
# check if there is a valid session and return the logged-in user (its object)
if session['user_and_subdomain']
id, subdomain = session['user_and_subdomain'].split
# for shared-host installations. check if the cookie-subdomain fits to request.
return User.current_user = User.find(id) if request.subdomains.first == subdomain
end
rescue
reset_session
flash[:error]= _("An error has occurred. Please login again.")
redirect_to :controller => 'login'
def current_user
begin
# check if there is a valid session and return the logged-in user (its object)
if session[:user] and session[:foodcoop]
# for shared-host installations. check if the cookie-subdomain fits to request.
return User.current_user = User.find(session[:user]) if session[:foodcoop] == Foodsoft.env
end
rescue
reset_session
flash[:error]= _("An error has occurred. Please login again.")
redirect_to :controller => 'login'
end
end
def current_user=(user)
session['user_and_subdomain'] = [user.id, request.subdomains.first].join(" ")
end
def current_user=(user)
session[:user], session[:foodcoop] = user.id, Foodsoft.env
end
def return_to
session['return_to']
end
def return_to
session['return_to']
end
def return_to=(uri)
session['return_to'] = uri
end
def return_to=(uri)
session['return_to'] = uri
end
def deny_access
self.return_to = request.request_uri
redirect_to :controller => '/login', :action => 'denied'
return false
end
def deny_access
self.return_to = request.request_uri
redirect_to :controller => '/login', :action => 'denied'
return false
end
private
def authenticate(role = 'any')
# Attempt to retrieve authenticated user from controller instance or session...
if !(user = current_user)
# No user at all: redirect to login page.
self.return_to = request.request_uri
redirect_to :controller => '/login'
return false
def authenticate(role = 'any')
# Attempt to retrieve authenticated user from controller instance or session...
if !(user = current_user)
# No user at all: redirect to login page.
self.return_to = request.request_uri
redirect_to :controller => '/login'
return false
else
# We have an authenticated user, now check role...
# Roles gets the user through his memberships.
hasRole = case role
when "admin" then user.role_admin?
when "finance" then user.role_finance?
when "article_meta" then user.role_article_meta?
when "suppliers" then user.role_suppliers?
when "orders" then user.role_orders?
when "any" then true # no role required
else false # any unknown role will always fail
end
if hasRole
@current_user = user
else
# We have an authenticated user, now check role...
# Roles gets the user through his memberships.
hasRole = case role
when "admin" then user.role_admin?
when "finance" then user.role_finance?
when "article_meta" then user.role_article_meta?
when "suppliers" then user.role_suppliers?
when "orders" then user.role_orders?
when "any" then true # no role required
else false # any unknown role will always fail
end
if hasRole
@current_user = user
else
deny_access
end
end
deny_access
end
end
end
def authenticate_admin
authenticate('admin')
end
def authenticate_admin
authenticate('admin')
end
def authenticate_finance
authenticate('finance')
end
def authenticate_finance
authenticate('finance')
end
def authenticate_article_meta
authenticate('article_meta')
end
def authenticate_article_meta
authenticate('article_meta')
end
def authenticate_suppliers
authenticate('suppliers')
end
def authenticate_suppliers
authenticate('suppliers')
end
def authenticate_orders
authenticate('orders')
end
def authenticate_orders
authenticate('orders')
end
# checks if the current_user is member of given group.
# if fails the user will redirected to startpage
def authenticate_membership_or_admin
@group = Group.find(params[:id])
unless @group.member?(@current_user) or @current_user.role_admin?
flash[:error] = "Diese Aktion ist nur für Mitglieder der Gruppe erlaubt!"
if request.xml_http_request?
render(:update) {|page| page.redirect_to root_path }
else
# checks if the current_user is member of given group.
# if fails the user will redirected to startpage
def authenticate_membership_or_admin
@group = Group.find(params[:id])
unless @group.member?(@current_user) or @current_user.role_admin?
flash[:error] = "Diese Aktion ist nur für Mitglieder der Gruppe erlaubt!"
if request.xml_http_request?
render(:update) {|page| page.redirect_to root_path }
else
redirect_to root_path
end
end
end
# Stores this controller instance as a thread local varibale to be accessible from outside ActionController/ActionView.
def store_controller
Thread.current[:application_controller] = self
end
# Sets the thread local variable that holds a reference to the current controller to nil.
def remove_controller
Thread.current[:application_controller] = nil
end
# Get supplier in nested resources
def find_supplier
@supplier = Supplier.find(params[:supplier_id]) if params[:supplier_id]
end
# Set config and database connection for each request
# It uses the subdomain to select the appropriate section in the config files
# Use this method as a before filter (first filter!) in ApplicationController
def select_foodcoop
if Foodsoft.config[:multi_coop_install]
if !params[:foodcoop].blank?
begin
# Set Config
Foodsoft.env = params[:foodcoop]
# Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database)
rescue => error
flash[:error] = error.to_s
redirect_to root_path
end
else
redirect_to root_path
end
else
# Deactivate routing filter
RoutingFilter::Foodcoop.active = false
end
# Stores this controller instance as a thread local varibale to be accessible from outside ActionController/ActionView.
def store_controller
Thread.current[:application_controller] = self
end
# Sets the thread local variable that holds a reference to the current controller to nil.
def remove_controller
Thread.current[:application_controller] = nil
end
# Get supplier in nested resources
def find_supplier
@supplier = Supplier.find(params[:supplier_id]) if params[:supplier_id]
end
# Set config and database connection for each request
# It uses the subdomain to select the appropriate section in the config files
# Use this method as a before filter (first filter!) in ApplicationController
def select_foodcoop
if Foodsoft.config[:multi_coop_install]
# Get subdomain
subdomain = request.subdomains.first
# Set Config
Foodsoft.env = subdomain
# Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain))
end
end
end
end

View File

@ -1,6 +1,5 @@
class LoginController < ApplicationController
skip_before_filter :authenticate # no authentication since this is the login page
filter_parameter_logging "password" # do not log "password" parameter
before_filter :validate_token, :only => [:password, :update_password]
verify :method => :post, :only => [:login, :reset_password, :new], :redirect_to => { :action => :index }

View File

@ -6,7 +6,7 @@ class TasksController < ApplicationController
@groups = Workgroup.all
end
def myTasks
def user
@unaccepted_tasks = @current_user.unaccepted_tasks
@accepted_tasks = @current_user.accepted_tasks
end
@ -78,7 +78,7 @@ class TasksController < ApplicationController
task.assignments.create(:user => current_user, :accepted => true)
end
flash[:notice] = "Du hast die Aufgabe übernommen"
redirect_to my_tasks_path
redirect_to user_tasks_path
end
# deletes assignment between current_user and given task

View File

@ -117,7 +117,7 @@ module ApplicationHelper
end
def tab_is_active?(tab)
tab[:active].detect {|c| c == controller.controller_path }
tab[:active].detect {|c| controller.controller_path.match(c) }
end
def icon(name, options={})

View File

@ -7,9 +7,9 @@ module PagesHelper
def link_to_wikipage(page, text = nil)
if text == nil
link_to page.title, "/wiki/#{page.title}"
link_to page.title, wiki_page_path(page.permalink)
else
link_to text, "/wiki/#{page.title}"
link_to text, wiki_page_path(page.permalink)
end
end

View File

@ -12,9 +12,9 @@ class Mailer < ActionMailer::Base
body :body => message.body,
:sender => message.sender.nick,
:recipients => recipient.nick,
:reply => "#{Foodsoft.config[:base_url]}/messages/reply/#{message.id}",
:link => "#{Foodsoft.config[:base_url]}/messages/show/#{message.id}",
:profile => "#{Foodsoft.config[:base_url]}/home/profile"
:reply => url_for(:controller => "messages", :action => "reply", :id => message.id),
:link => url_for(:controller => "messages", :action => "show", :id => message.id),
:profile => url_for(:controller => "home", :action => "profile")
end
# Sends an email with instructions on how to reset the password.
@ -23,7 +23,7 @@ class Mailer < ActionMailer::Base
prepare_system_message(user)
subject "[#{Foodsoft.config[:name]}] Neues Passwort für/ New password for #{user.nick}"
body :user => user,
:link => "#{Foodsoft.config[:base_url]}/login/password/#{user.id}?token=#{user.reset_password_token}"
:link => url_for(:controller => "login", :action => "password", :id => user.id, :token => user.reset_password_token)
end
# Sends an invite email.
@ -31,7 +31,7 @@ class Mailer < ActionMailer::Base
prepare_system_message(invite)
subject "Einladung in die Foodcoop #{Foodsoft.config[:name]} - Invitation to the Foodcoop"
body :invite => invite,
:link => "#{Foodsoft.config[:base_url]}/login/invite/#{invite.token}"
:link => url_for(:controller => "login", :action => "invite", :id => invite.token)
end
# Notify user of upcoming task.
@ -71,7 +71,7 @@ class Mailer < ActionMailer::Base
prepare_system_message(user)
subject "[#{Foodsoft.config[:name]}] #{task.name} braucht noch Leute!"
body :task => task, :user => user,
:task_url => File.join(Foodsoft.config[:base_url], "tasks/workgroup", task.workgroup_id.to_s)
:task_url => url_for(:controller => "tasks", :action => "workgroup", :id => task.workgroup_id)
end
protected

View File

@ -4,7 +4,7 @@
Foodcoop
%ul
%li= link_to "Mitglieder", foodcoop_users_path
%li= link_to "Meine Aufgaben", :controller => "home", :action => "tasks"
%li= link_to "Meine Aufgaben", user_tasks_path
%li= link_to "Nachricht schreiben", :controller => "messages", :action => "new"
// Orders

View File

@ -21,11 +21,11 @@
- unless @unaccepted_tasks.empty?
%h3 Aufgaben übernehmen
Du bis für Aufgaben verantwortlich.
= link_to "Aufgaben übernehmen/ablehnen", my_tasks_path
= link_to "Aufgaben übernehmen/ablehnen", user_tasks_path
- unless @unassigned_tasks_number == 0
%h3 Offene Aufgaben
= "Es gibt #{@unassigned_tasks_number} #{link_to 'offene Aufgabe(n)', :controller => 'tasks'}"
%p{:style => "clear:both"}= link_to "Meine Aufgaben", my_tasks_path
%p{:style => "clear:both"}= link_to "Meine Aufgaben", user_tasks_path
- if @ordergroup
// Current orders

View File

@ -3,56 +3,56 @@
tabs = [
{ :name => "Start", :url => root_path, :active => ["index", "home"],
:subnav => [
{ :name => "Meine Aufgaben", :url => "/home/tasks" },
{ :name => "Meine Bestellgruppe", :url => "/home/ordergroup", :access_denied? => (!u.ordergroup)},
{ :name => "Mein Profil", :url => "/home/profile"}
{ :name => "Meine Aufgaben", :url => user_tasks_path },
{ :name => "Meine Bestellgruppe", :url => my_ordergroup_path, :access_denied? => (!u.ordergroup)},
{ :name => "Mein Profil", :url => my_profile_path}
]
},
{ :name => "Foodcoop", :url => "/tasks",
{ :name => "Foodcoop", :url => tasks_path,
:active => ["foodcoop", "tasks", "messages", "foodcoop/ordergroups", "foodcoop/workgroups", "foodcoop/users"],
:subnav => [
{ :name => "Mitglieder", :url => "/foodcoop/users"},
{ :name => "Abeitsgruppen", :url => "/foodcoop/workgroups"},
{ :name => "Bestellgruppen", :url => "/foodcoop/ordergroups"},
{ :name => "Nachrichten", :url => "/messages"},
{ :name => "Aufgaben", :url => "/tasks"}
{ :name => "Mitglieder", :url => foodcoop_users_path},
{ :name => "Abeitsgruppen", :url => foodcoop_workgroups_path},
{ :name => "Bestellgruppen", :url => foodcoop_ordergroups_path},
{ :name => "Nachrichten", :url => messages_path},
{ :name => "Aufgaben", :url => tasks_path}
]
},
{ :name => "Wiki", :url => "/wiki", :active => ["pages", "wiki"],
{ :name => "Wiki", :url => wiki_path, :active => ["pages", "wiki"],
:subnav => [
{ :name => "Startseite", :url => "/wiki" },
{ :name => "Alle Seiten", :url => "/pages/all" }
{ :name => "Startseite", :url => wiki_path },
{ :name => "Alle Seiten", :url => all_pages_path }
]
},
{ :name => "Bestellungen", :url => u.ordergroup ? "/ordering/" : "/orders",
{ :name => "Bestellungen", :url => u.ordergroup ? ordering_path : orders_path,
:active => ["orders", "ordering"],
:subnav => [
{ :name => "Bestellen!", :url => "/ordering" },
{ :name => "Meine Bestellungen", :url => "/ordering/myOrders" },
{ :name => "Bestellverwaltung", :url => "/orders", :access_denied? => (!u.role_orders?) }
{ :name => "Bestellen!", :url => ordering_path },
{ :name => "Meine Bestellungen", :url => my_orders_path },
{ :name => "Bestellverwaltung", :url => orders_path, :access_denied? => (!u.role_orders?) }
]
},
{ :name => "Artikel", :url => "/suppliers",
{ :name => "Artikel", :url => suppliers_path,
:active => ["articles", "suppliers", "deliveries", "article_categories", "stockit", "stock_takings"],
:access_denied? => (!u.role_article_meta? && !u.role_suppliers?),
:subnav => [
{ :name => "Artikel", :url => supplier_articles_path(Supplier.first) },
{ :name => "Lager", :url => "/stockit" },
{ :name => "Lager", :url => stock_articles_path },
{ :name => "Lieferantinnen", :url => suppliers_path, :access_denied? => (!u.role_suppliers?) },
{ :name => "Kategorien", :url => "/article_categories"}
{ :name => "Kategorien", :url => article_categories_path }
]
},
{ :name => "Finanzen", :url => "/finance",
{ :name => "Finanzen", :url => finance_root_path,
:active => ["finance/invoices", "finance/transactions", "finance/balancing"],
:access_denied? => (!u.role_finance?),
:subnav => [
{ :name => "Konten verwalten", :url => "/finance/transactions" },
{ :name => "Bestellungen abrechnen", :url => "/finance/balancing/list" },
{ :name => "Konten verwalten", :url => finance_transactions_path },
{ :name => "Bestellungen abrechnen", :url => finance_balancing_path },
{ :name => "Rechnungen", :url => finance_invoices_path }
]
},
{ :name => "Administration", :url => "/admin",
:active => ["admin", "admin/users", "admin/ordergroups", "admin/workgroups"],
{ :name => "Administration", :url => admin_root_path,
:active => ["admin/"],
:access_denied? => (!u.role_admin?),
:subnav => [
{ :name => "Benutzerinnen", :url => admin_users_path },
@ -77,4 +77,4 @@
</li>
<% end -%>
<% end -%>
</ul>
</ul>

View File

@ -15,7 +15,7 @@
#header
#logo
%a{:href => "/"}
- link_to root_path do
<span>food</span>soft
%span{:style => "color:white; font-size:45%; letter-spacing: -1px;"}= Foodsoft.config[:name]
#nav= render :partial => 'layouts/main_tabnav'

View File

@ -1,6 +1,6 @@
<%= yield %>
--
FoodSoft: <%= @foodsoftUrl %>
Foodcoop-Homepage: <%= Foodsoft.config[:base_url] %>
Hilfe/Help: <%= Foodsoft.config[:help_url] %>
FoodSoft: <%= url_for(:controller => "home", :action => "index", :only_path => false) %>
Foodcoop-Homepage: <%= Foodsoft.config[:homepage] %>
Hilfe/Help: <%= Foodsoft.config[:help_url] %>

View File

@ -15,4 +15,4 @@
= text_field 'login', 'email'
= submit_tag 'Neues Passwort anfordern'
|
= link_to 'Abbrechen', :action => 'login'
= link_to 'Abbrechen', login_path

View File

@ -13,4 +13,4 @@
= form.password_field :password_confirmation
= form.submit 'Speichern'
|
= link_to 'Abbrechen', :action => 'login'
= link_to 'Abbrechen', login_path

View File

@ -7,5 +7,5 @@ Sofern Du Dich noch nicht für diese Aufgabe eingetragen hast ist das jetzt die
<%= @task_url %>
--
Deine Aufgaben: <%= Foodsoft.config[:base_url] %>/home/tasks
Deine Aufgaben: <%= url_for(:controller => "home", :actions => "user") %>

View File

@ -9,6 +9,6 @@ Für Euch wurden die folgenden Artikel bestellt:
<% end -%>
Gesamtpreis: <%= @group_order.price %>
Bestellung online einsehen: <%= "#{Foodsoft.config[:base_url]}/ordering/my_order_result/#{@order.id}" %>
Bestellung online einsehen: <%= url_for(:controller => "ordering", :action => "my_order_result", :id => @order.id) %>
Viele Grüße von <%= Foodsoft.config[:name] %>

View File

@ -11,6 +11,6 @@ Aufgaben für die nächste Woche:
<% end -%>
<% end -%>
Meine Aufgaben: <%= Foodsoft.config[:base_url] %>/home/tasks
Meine Aufgaben: <%= url_for(:controller => "home", :actions => "user") %>
Viele Grüße von <%= Foodsoft.config[:name] %>

View File

@ -8,7 +8,7 @@
%li
Seiten
%ul
%li= link_to "Meine Aufgaben", my_tasks_path
%li= link_to "Meine Aufgaben", user_tasks_path
%li= link_to "Alle Aufgaben", :action => "index"
%li= link_to "Erledigt Aufgaben (Archiv)", :action => "archive"

View File

@ -5,6 +5,12 @@ development: &defaults
# Don't forget to setup databases for each foodcoop. See also MULTI_COOP_INSTALL
multi_coop_install: false
# http config for this host
# Required for action mailer
protocol: http
host: localhost
port: 3000
# name of this foodcoop
name: FC Test
# foodcoop contact information (used for FAX messages)
@ -16,9 +22,6 @@ development: &defaults
email: foodsoft@myfoodcoop.org
phone: "030 323 23249"
# base URL for this installation
base_url: http://foodsoft.fctest.de
# Homepage
homepage: http://www.fctest.de

View File

@ -59,6 +59,7 @@ Rails::Initializer.run do |config|
config.gem "fastercsv"
config.gem "prawn", :version => '<=0.6.3'
config.gem "haml", :version => '>=2.0.6'
config.gem "routing-filter", :lib => "routing_filter"
# The internationalization framework can be changed to have another default locale (standard is :en) or more load paths.
# All files from config/locales/*.rb,yml are added automatically.

View File

@ -1,33 +1,33 @@
# Loads and returns config and databases for selected foodcoop.
# TODO: When to use class or module. It seems this could also be a Foodsoft-class?
module Foodsoft
@@configs = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
@@databases = YAML.load(File.read(RAILS_ROOT + "/config/database.yml"))
@@env = RAILS_ENV
mattr_accessor :env, :config, :database
CONFIGS = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
DATABASES = YAML.load(File.read(RAILS_ROOT + "/config/database.yml"))
def env=(env)
@@env = env
class << self
def env=(env)
raise "No config or database for this environment (#{env}) available!" if CONFIGS[env].nil? or DATABASES[env].nil?
@@config = CONFIGS[env].symbolize_keys
@@database = DATABASES[env].symbolize_keys
@@env = env
end
end
def env
@@env
end
def config(rails_env = @@env)
raise "No config for this environment (or subdomain) available!" if @@configs[rails_env].nil?
@@configs[rails_env].symbolize_keys
end
def database(rails_env = @@env)
raise "No database for this environment (or subdomain) available!" if @@databases[rails_env].nil?
@@databases[rails_env].symbolize_keys
end
extend self
end
# Initial load the default config and database from rails environment
Foodsoft.env = RAILS_ENV
# Set action mailer default host for url generating
url_options = {
:host => Foodsoft.config[:host],
:protocol => Foodsoft.config[:protocol]
}
url_options.merge!({:port => Foodsoft.config[:port]}) if Foodsoft.config[:port]
ActionMailer::Base.default_url_options = url_options
# Configuration of the exception_notification plugin
# Mailadresses are set in config/foodsoft.yaml
ExceptionNotifier.exception_recipients = Foodsoft.config[:notification]['error_recipients']
ExceptionNotifier.sender_address = Foodsoft.config[:notification]['sender_address']
ExceptionNotifier.email_prefix = Foodsoft.config[:notification]['email_prefix']
ExceptionNotifier.email_prefix = Foodsoft.config[:notification]['email_prefix']

View File

@ -1,20 +1,36 @@
ActionController::Routing::Routes.draw do |map|
# Use routing filter to select foodcoop config and datbase
map.filter 'foodcoop', :file => File.join(RAILS_ROOT, "lib", "foodcoop_filter")
# Root path
map.root :controller => 'home', :action => 'index'
# User specific
map.login "/login", :controller => 'login', :action => 'index'
map.logout '/logout', :controller => 'login', :action => 'logout'
map.my_profile '/home/profile', :controller => 'home', :action => 'profile'
map.my_ordergroup '/home/ordergroup', :controller => 'home', :action => 'ordergroup'
# Wiki
map.resources :pages, :collection => { :all => :get }, :member => {:version => :get, :revert => :get}
map.wiki_page "/wiki/:permalink", :controller => 'pages', :action => 'show', :permalink => /[^\s]+/
map.wiki "/wiki", :controller => 'pages', :action => 'show', :permalink => 'Home'
map.logout '/logout', :controller => 'login', :action => 'logout'
map.my_profile '/home/profile', :controller => 'home', :action => 'profile'
map.my_ordergroup '/home/ordergroup', :controller => 'home', :action => 'ordergroup'
map.my_tasks '/home/tasks', :controller => 'tasks', :action => 'myTasks'
# Orders, ordering
map.resources :orders, :member => { :finish => :post, :add_comment => :post }
map.with_options :controller => "ordering" do |ordering|
ordering.ordering "/ordering", :action => "index"
ordering.my_orders "/ordering/myOrders", :action => "myOrders"
end
# Foodcoop orga
map.resources :invites, :only => [:new, :create]
map.resources :tasks,
:collection => {:user => :get}
map.resources :messages, :only => [:index, :show, :new, :create],
:member => { :reply => :get, :user => :get, :group => :get }
map.resources :invites, :only => [:new, :create]
map.namespace :foodcoop do |foodcoop|
foodcoop.root :controller => "users", :action => "index"
foodcoop.resources :users, :only => [:index]
@ -23,23 +39,13 @@ ActionController::Routing::Routes.draw do |map|
:member => {:memberships => :get}
end
map.namespace :admin do |admin|
admin.resources :users
admin.resources :workgroups, :member => { :memberships => :get }
admin.resources :ordergroups, :member => { :memberships => :get }
end
map.namespace :finance do |finance|
finance.root :controller => 'balancing'
finance.resources :invoices
end
# Article management
map.resources :stock_takings,
:collection => {:fill_new_stock_article_form => :get, :add_stock_article => :post}
map.resources :stock_articles,
:controller => 'stockit', :as => 'stockit',
:collection => {:auto_complete_for_article_name => :get, :fill_new_stock_article_form => :get}
map.resources :suppliers,
:collection => { :shared_suppliers => :get } do |suppliers|
suppliers.resources :deliveries,
@ -52,47 +58,21 @@ ActionController::Routing::Routes.draw do |map|
end
map.resources :article_categories
map.root :controller => 'home', :action => 'index'
# The priority is based upon order of creation: first created -> highest priority.
# Finance
map.namespace :finance do |finance|
finance.root :controller => 'balancing'
finance.balancing "balancing/list", :controller => 'balancing', :action => 'list'
finance.resources :invoices
finance.resources :transactions
end
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products
# Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
# Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
# Sample resource route with more complex sub-resources
# map.resources :products do |products|
# products.resources :comments
# products.resources :sales, :collection => { :recent => :get }
# end
# Sample resource route within a namespace:
# map.namespace :admin do |admin|
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
# admin.resources :products
# end
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
# map.root :controller => "welcome"
# See how all your routes lay out with "rake routes"
# Install the default routes as the lowest priority.
# Note: These default routes make all actions in every controller accessible via GET requests. You should
# consider removing the them or commenting them out if you're using named routes and resources.
# Administration
map.namespace :admin do |admin|
admin.root :controller => "base", :action => "index"
admin.resources :users
admin.resources :workgroups, :member => { :memberships => :get }
admin.resources :ordergroups, :member => { :memberships => :get }
end
# Install the default route as the lowest priority.
map.connect ':controller/:action/:id'

37
lib/foodcoop_filter.rb Normal file
View File

@ -0,0 +1,37 @@
require 'routing_filter/base'
module RoutingFilter
class Foodcoop < Base
def around_recognize(path, env, &block)
token = extract_token!(path) # remove the token from the beginning of the path
returning yield do |params| # invoke the given block (calls more filters and finally routing)
params[:foodcoop] = token if token # set recognized token to the resulting params hash
end
end
def around_generate(*args, &block)
token = args.extract_options!.delete(:foodcoop) # extract the passed :token option
token = Foodsoft.env if token.nil? # default to Foodsoft.env
returning yield do |result|
if token
url = result.is_a?(Array) ? result.first : result
prepend_token!(url, token)
end
end
end
protected
def extract_token!(path)
foodcoop = nil
path.sub! %r(^/([a-zA-Z0-9]*)(?=/|$)) do foodcoop = $1; '' end
foodcoop
end
def prepend_token!(url, token)
url.sub!(%r(^(http.?://[^/]*)?(.*))) { "#{$1}/#{token}#{$2}" }
end
end
end

View File

@ -1,23 +1,21 @@
class Wikilink < WikiCloth::WikiLinkHandler
def url_for(page, parent = nil)
if parent
"/pages/new?title=#{page}&parent=#{parent}"
else
"/wiki/#{page}"
end
end
include ActionController::UrlWriter # To use named routes
def link_attributes_for(page)
permalink = Page.permalink(page)
url_options = {:host => Foodsoft.config[:host], :protocol => Foodsoft.config[:protocol]}
url_options.merge!({:port => Foodsoft.config[:port]}) if Foodsoft.config[:port]
if Page.exists?(:permalink => permalink)
{ :href => url_for(permalink) }
{ :href => url_for(url_options.merge({:controller => "pages", :action => "show",
:permalink => permalink, :use_route => :wiki_page})) }
else
{ :href => url_for(page, params[:referer]), :class => "new_wiki_link"}
{ :href => url_for(url_options.merge({:controller => "pages", :action => "new",
:title => page, :parent => params[:referer]})), :class => "new_wiki_link"}
end
end
def section_link(section)
""
end
end
end