Second (last) part of multiple foodcoop installation.

* When before_filter select_foodcoop is activated,
  the database and configs will be loaded on each request.
* Replaced APP_CONFIG with new Foodsoft.config method.
This commit is contained in:
Benjamin Meichsner 2009-03-24 17:25:33 +01:00
parent 1c24127928
commit ffc3adf907
18 changed files with 51 additions and 57 deletions

View File

@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base class ApplicationController < ActionController::Base
# If you wanna run multiple foodcoops on one installation uncomment next line. # If you wanna run multiple foodcoops on one installation uncomment next line.
before_filter :select_foodcoop #before_filter :select_foodcoop
before_filter :authenticate, :store_controller before_filter :authenticate, :store_controller
after_filter :remove_controller after_filter :remove_controller
@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base
# Use this method to call a rake task,, # Use this method to call a rake task,,
# e.g. to deliver mails after there are created. # e.g. to deliver mails after there are created.
def call_rake(task, options = {}) def call_rake(task, options = {})
options[:rails_env] ||= Rails.env options[:rails_env] ||= Foodsoft.env
args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" } args = options.map { |n, v| "#{n.to_s.upcase}='#{v}'" }
system "/usr/bin/rake #{task} #{args.join(' ')} --trace 2>&1 >> #{Rails.root}/log/rake.log &" system "/usr/bin/rake #{task} #{args.join(' ')} --trace 2>&1 >> #{Rails.root}/log/rake.log &"
end end
@ -60,14 +60,6 @@ class ApplicationController < ActionController::Base
private private
# selects the foodcoop depending on the subdomain
# def select_foodcoop
# # get subdomain and set FoodSoft-class-variable (for later config-requests)
# FoodSoft.subdomain = request.subdomains.first
# # set database-connection
# ActiveRecord::Base.establish_connection(FoodSoft.get_database)
# end
# Ensures the HTTP content-type encoding is set to "UTF-8" for "text/html" contents. # Ensures the HTTP content-type encoding is set to "UTF-8" for "text/html" contents.
def ensureUTF8 def ensureUTF8
content_type = headers["Content-Type"] || "text/html" content_type = headers["Content-Type"] || "text/html"
@ -159,7 +151,7 @@ class ApplicationController < ActionController::Base
# Get subdomain # Get subdomain
subdomain = request.subdomains.first subdomain = request.subdomains.first
# Set Config # Set Config
Foodsoft.set_env subdomain Foodsoft.env = subdomain
# Set database-connection # Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain)) ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain))
end end

View File

@ -127,13 +127,13 @@ class OrdersController < ApplicationController
def text_fax_template def text_fax_template
order = Order.find(params[:id]) order = Order.find(params[:id])
supplier = order.supplier supplier = order.supplier
contact = APP_CONFIG[:contact].symbolize_keys contact = Foodsoft.config[:contact].symbolize_keys
text = "Bestellung für" + " #{APP_CONFIG[:name]}" text = "Bestellung für" + " #{Foodsoft.config[:name]}"
text += "\n" + "Kundennummer" + ": #{supplier.customer_number}" unless supplier.customer_number.blank? text += "\n" + "Kundennummer" + ": #{supplier.customer_number}" unless supplier.customer_number.blank?
text += "\n" + "Liefertag" + ": " text += "\n" + "Liefertag" + ": "
text += "\n\n#{supplier.name}\n#{supplier.address}\nFAX: #{supplier.fax}\n\n" text += "\n\n#{supplier.name}\n#{supplier.address}\nFAX: #{supplier.fax}\n\n"
text += "****** " + "Versandadresse" + "\n\n" text += "****** " + "Versandadresse" + "\n\n"
text += "#{APP_CONFIG[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n" text += "#{Foodsoft.config[:name]}\n#{contact[:street]}\n#{contact[:zip_code]} #{contact[:city]}\n\n"
text += "****** " + "Artikel" + "\n\n" text += "****** " + "Artikel" + "\n\n"
text += "Nummer" + " " + "Menge" + " " + "Name" + "\n" text += "Nummer" + " " + "Menge" + " " + "Name" + "\n"
# now display all ordered articles # now display all ordered articles

View File

@ -70,7 +70,7 @@ class Article < ActiveRecord::Base
# The price for the foodcoop-member. # The price for the foodcoop-member.
def fc_price def fc_price
(gross_price * (APP_CONFIG[:price_markup] / 100 + 1)).round(2) (gross_price * (Foodsoft.config[:price_markup] / 100 + 1)).round(2)
end end
# Returns true if article has been updated at least 2 days ago # Returns true if article has been updated at least 2 days ago
@ -157,8 +157,8 @@ class Article < ActiveRecord::Base
false false
end end
else # get factors for fc and supplier else # get factors for fc and supplier
fc_unit_factor = APP_CONFIG[:units][self.unit] fc_unit_factor = Foodsoft.config[:units][self.unit]
supplier_unit_factor = APP_CONFIG[:units][self.shared_article.unit] supplier_unit_factor = Foodsoft.config[:units][self.shared_article.unit]
if fc_unit_factor and supplier_unit_factor if fc_unit_factor and supplier_unit_factor
convertion_factor = fc_unit_factor / supplier_unit_factor convertion_factor = fc_unit_factor / supplier_unit_factor
new_price = BigDecimal((convertion_factor * shared_article.price).to_s).round(2) new_price = BigDecimal((convertion_factor * shared_article.price).to_s).round(2)

View File

@ -39,6 +39,6 @@ class ArticlePrice < ActiveRecord::Base
# The price for the foodcoop-member. # The price for the foodcoop-member.
def fc_price def fc_price
(gross_price * (APP_CONFIG[:price_markup] / 100 + 1)).round(2) (gross_price * (Foodsoft.config[:price_markup] / 100 + 1)).round(2)
end end
end end

View File

@ -5,39 +5,39 @@ class Mailer < ActionMailer::Base
# Sends an email copy of the given internal foodsoft message. # Sends an email copy of the given internal foodsoft message.
def message(message, recipient) def message(message, recipient)
headers 'Sender' => APP_CONFIG[:email_sender], 'Errors-To' => APP_CONFIG[:email_sender] headers 'Sender' => Foodsoft.config[:email_sender], 'Errors-To' => Foodsoft.config[:email_sender]
subject "[#{APP_CONFIG[:name]}] " + message.subject subject "[#{Foodsoft.config[:name]}] " + message.subject
recipients recipient.email recipients recipient.email
from "#{message.sender.nick} <#{message.sender.email}>" from "#{message.sender.nick} <#{message.sender.email}>"
body :body => message.body, body :body => message.body,
:sender => message.sender.nick, :sender => message.sender.nick,
:recipients => recipient.nick, :recipients => recipient.nick,
:reply => "#{APP_CONFIG[:base_url]}/messages/reply/#{message.id}", :reply => "#{Foodsoft.config[:base_url]}/messages/reply/#{message.id}",
:link => "#{APP_CONFIG[:base_url]}/messages/show/#{message.id}", :link => "#{Foodsoft.config[:base_url]}/messages/show/#{message.id}",
:profile => "#{APP_CONFIG[:base_url]}/home/profile" :profile => "#{Foodsoft.config[:base_url]}/home/profile"
end end
# Sends an email with instructions on how to reset the password. # Sends an email with instructions on how to reset the password.
# Assumes user.setResetPasswordToken has been successfully called already. # Assumes user.setResetPasswordToken has been successfully called already.
def reset_password(user) def reset_password(user)
prepare_system_message(user) prepare_system_message(user)
subject "[#{APP_CONFIG[:name]}] Neues Passwort für/ New password for #{user.nick}" subject "[#{Foodsoft.config[:name]}] Neues Passwort für/ New password for #{user.nick}"
body :user => user, body :user => user,
:link => "#{APP_CONFIG[:base_url]}/login/password/#{user.id}?token=#{user.reset_password_token}" :link => "#{Foodsoft.config[:base_url]}/login/password/#{user.id}?token=#{user.reset_password_token}"
end end
# Sends an invite email. # Sends an invite email.
def invite(invite) def invite(invite)
prepare_system_message(invite) prepare_system_message(invite)
subject "Einladung in die Foodcoop #{APP_CONFIG[:name]} - Invitation to the Foodcoop" subject "Einladung in die Foodcoop #{Foodsoft.config[:name]} - Invitation to the Foodcoop"
body :invite => invite, body :invite => invite,
:link => "#{APP_CONFIG[:base_url]}/login/invite/#{invite.token}" :link => "#{Foodsoft.config[:base_url]}/login/invite/#{invite.token}"
end end
# Notify user of upcoming task. # Notify user of upcoming task.
def upcoming_tasks(user, task) def upcoming_tasks(user, task)
prepare_system_message(user) prepare_system_message(user)
subject "[#{APP_CONFIG[:name]}] Aufgaben werden fällig!" subject "[#{Foodsoft.config[:name]}] Aufgaben werden fällig!"
body :user => user, body :user => user,
:task => task :task => task
end end
@ -45,7 +45,7 @@ class Mailer < ActionMailer::Base
# Sends order result for specific Ordergroup # Sends order result for specific Ordergroup
def order_result(user, group_order) def order_result(user, group_order)
prepare_system_message(user) prepare_system_message(user)
subject "[#{APP_CONFIG[:name]}] Bestellung beendet: #{group_order.order.name}" subject "[#{Foodsoft.config[:name]}] Bestellung beendet: #{group_order.order.name}"
body :order => group_order.order, body :order => group_order.order,
:group_order => group_order :group_order => group_order
end end
@ -53,7 +53,7 @@ class Mailer < ActionMailer::Base
# Notify user if account balance is less than zero # Notify user if account balance is less than zero
def negative_balance(user,transaction) def negative_balance(user,transaction)
prepare_system_message(user) prepare_system_message(user)
subject "[#{APP_CONFIG[:name]}] Gruppenkonto im Minus" subject "[#{Foodsoft.config[:name]}] Gruppenkonto im Minus"
body :group => user.ordergroup, body :group => user.ordergroup,
:transaction => transaction :transaction => transaction
end end
@ -62,7 +62,7 @@ class Mailer < ActionMailer::Base
def prepare_system_message(recipient) def prepare_system_message(recipient)
recipients recipient.email recipients recipient.email
from "FoodSoft <#{APP_CONFIG[:email_sender]}>" from "FoodSoft <#{Foodsoft.config[:email_sender]}>"
end end
end end

View File

@ -25,7 +25,7 @@
class SharedArticle < ActiveRecord::Base class SharedArticle < ActiveRecord::Base
# connect to database from sharedLists-Application # connect to database from sharedLists-Application
SharedArticle.establish_connection(APP_CONFIG[:shared_lists]) SharedArticle.establish_connection(Foodsoft.config[:shared_lists])
# set correct table_name in external DB # set correct table_name in external DB
set_table_name :articles set_table_name :articles

View File

@ -21,7 +21,7 @@
class SharedSupplier < ActiveRecord::Base class SharedSupplier < ActiveRecord::Base
# connect to database from sharedLists-Application # connect to database from sharedLists-Application
SharedSupplier.establish_connection(APP_CONFIG[:shared_lists]) SharedSupplier.establish_connection(Foodsoft.config[:shared_lists])
# set correct table_name in external DB # set correct table_name in external DB
set_table_name :suppliers set_table_name :suppliers

View File

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

View File

@ -2,5 +2,5 @@
-- --
FoodSoft: <%= @foodsoftUrl %> FoodSoft: <%= @foodsoftUrl %>
Foodcoop-Homepage: <%= APP_CONFIG[:base_url] %> Foodcoop-Homepage: <%= Foodsoft.config[:base_url] %>
Hilfe/Help: <%= APP_CONFIG[:help_url] %> Hilfe/Help: <%= Foodsoft.config[:help_url] %>

View File

@ -12,4 +12,4 @@
= yield = yield
#meta #meta
Foodcoop Foodcoop
= link_to_if APP_CONFIG[:homepage], APP_CONFIG[:name], APP_CONFIG[:homepage] = link_to_if Foodsoft.config[:homepage], Foodsoft.config[:name], Foodsoft.config[:homepage]

View File

@ -1,4 +1,4 @@
- title "Einladung in die #{APP_CONFIG[:name]}" - title "Einladung in die #{Foodsoft.config[:name]}"
%p %p
Du bist eingeladen worden in der Foodcoop Du bist eingeladen worden in der Foodcoop
%b= @invite.group.name %b= @invite.group.name

View File

@ -6,4 +6,4 @@ Es wurden <%= @transaction.amount %> für "<%= @transaction.note %>" abgebucht,
Bitte zahlt so bald wie möglich wieder Geld ein, um das Gruppenkonto auszugleichen. Bitte zahlt so bald wie möglich wieder Geld ein, um das Gruppenkonto auszugleichen.
Viele Grüße von <%= APP_CONFIG[:name] %> Viele Grüße von <%= Foodsoft.config[:name] %>

View File

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

View File

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

View File

@ -6,19 +6,19 @@
%p %p
Empfängerinnen Empfängerinnen
%fieldset %fieldset
- if APP_CONFIG[:mailing_list].blank? - if Foodsoft.config[:mailing_list].blank?
= f.check_box :sent_to_all, :onchange => "Element.toggle('recipients')" = f.check_box :sent_to_all, :onchange => "Element.toggle('recipients')"
gesamte Foodcoop gesamte Foodcoop
- else - else
%b Nachrichten an alle %b Nachrichten an alle
verschickst Du bitte über den Verteiler: verschickst Du bitte über den Verteiler:
= mail_to APP_CONFIG[:mailing_list] = mail_to Foodsoft.config[:mailing_list]
%br/ %br/
%small{:style => "color:grey"} %small{:style => "color:grey"}
Eventuell musst Du Dich dem Verteiler erst bekannt machen. Eventuell musst Du Dich dem Verteiler erst bekannt machen.
%br/ %br/
z.b. mit einer Mail an z.b. mit einer Mail an
= mail_to APP_CONFIG[:mailing_list_subscribe] = mail_to Foodsoft.config[:mailing_list_subscribe]
%table#recipients %table#recipients
%tr %tr
%td %td

View File

@ -1,5 +1,5 @@
# Get ActiveRecord objects # Get ActiveRecord objects
contact = APP_CONFIG[:contact].symbolize_keys contact = Foodsoft.config[:contact].symbolize_keys
# Define header and footer # Define header and footer
#pdf.header [pdf.margin_box.left,pdf.margin_box.top+30] do #pdf.header [pdf.margin_box.left,pdf.margin_box.top+30] do
@ -12,7 +12,7 @@ end
# From paragraph # From paragraph
pdf.bounding_box [pdf.margin_box.right-200,pdf.margin_box.top], :width => 200 do pdf.bounding_box [pdf.margin_box.right-200,pdf.margin_box.top], :width => 200 do
pdf.text APP_CONFIG[:name], :align => :right pdf.text Foodsoft.config[:name], :align => :right
pdf.move_down 5 pdf.move_down 5
pdf.text contact[:street], :align => :right pdf.text contact[:street], :align => :right
pdf.move_down 5 pdf.move_down 5

View File

@ -2,7 +2,7 @@
%li %li
= image_tag 'b_user.png' , :size => '7x10', :border => 0, :alt => _("User") = image_tag 'b_user.png' , :size => '7x10', :border => 0, :alt => _("User")
= link_to h(@current_user.nick), my_profile_path, { :title => _("User Settings") } = link_to h(@current_user.nick), my_profile_path, { :title => _("User Settings") }
- if APP_CONFIG[:homepage] - if Foodsoft.config[:homepage]
%li= link_to APP_CONFIG[:name], APP_CONFIG[:homepage], { :title => _("Go to your FoodCoop-Hompage") } %li= link_to Foodsoft.config[:name], Foodsoft.config[:homepage], { :title => _("Go to your FoodCoop-Hompage") }
%li= link_to _("Hilfe"), 'http://dev.foodcoops.net/wiki/FoodsoftDoku' %li= link_to _("Hilfe"), 'http://dev.foodcoops.net/wiki/FoodsoftDoku'
%li= link_to _("Logout"), :controller => '/login', :action => 'logout' %li= link_to _("Logout"), :controller => '/login', :action => 'logout'

View File

@ -1,15 +1,17 @@
raw_config = File.read(RAILS_ROOT + "/config/app_config.yml") # Loads and returns config and databases for selected foodcoop.
APP_CONFIG = YAML.load(raw_config)[RAILS_ENV].symbolize_keys
module Foodsoft module Foodsoft
@@configs = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml")) @@configs = YAML.load(File.read(RAILS_ROOT + "/config/app_config.yml"))
@@databases = YAML.load(File.read(RAILS_ROOT + "/config/database.yml")) @@databases = YAML.load(File.read(RAILS_ROOT + "/config/database.yml"))
@@env = RAILS_ENV @@env = RAILS_ENV
def set_env(env) def env=(env)
@@env = env @@env = env
end end
def env
@@env
end
def config(rails_env = @@env) def config(rails_env = @@env)
@@configs[rails_env].symbolize_keys @@configs[rails_env].symbolize_keys
end end
@ -24,6 +26,6 @@ end
# Configuration of the exception_notification plugin # Configuration of the exception_notification plugin
# Mailadresses are set in config/foodsoft.yaml # Mailadresses are set in config/foodsoft.yaml
ExceptionNotifier.exception_recipients = APP_CONFIG[:notification]['error_recipients'] ExceptionNotifier.exception_recipients = Foodsoft.config[:notification]['error_recipients']
ExceptionNotifier.sender_address = APP_CONFIG[:notification]['sender_address'] ExceptionNotifier.sender_address = Foodsoft.config[:notification]['sender_address']
ExceptionNotifier.email_prefix = APP_CONFIG[:notification]['email_prefix'] ExceptionNotifier.email_prefix = Foodsoft.config[:notification]['email_prefix']