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
# 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
after_filter :remove_controller
@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base
# Use this method to call a rake task,,
# e.g. to deliver mails after there are created.
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}'" }
system "/usr/bin/rake #{task} #{args.join(' ')} --trace 2>&1 >> #{Rails.root}/log/rake.log &"
end
@ -60,14 +60,6 @@ class ApplicationController < ActionController::Base
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.
def ensureUTF8
content_type = headers["Content-Type"] || "text/html"
@ -159,7 +151,7 @@ class ApplicationController < ActionController::Base
# Get subdomain
subdomain = request.subdomains.first
# Set Config
Foodsoft.set_env subdomain
Foodsoft.env = subdomain
# Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain))
end

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@
class SharedArticle < ActiveRecord::Base
# 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_table_name :articles

View File

@ -21,7 +21,7 @@
class SharedSupplier < ActiveRecord::Base
# 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_table_name :suppliers

View File

@ -17,7 +17,7 @@
#logo
%a{:href => "/"}
<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'
#main

View File

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

View File

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

View File

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

View File

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

View File

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