diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 659e4b31..3933f5d6 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -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 diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 15369ef4..4b41a16e 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -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 diff --git a/app/models/article.rb b/app/models/article.rb index cc1d794d..a3f70392 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -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) diff --git a/app/models/article_price.rb b/app/models/article_price.rb index c9e4f220..1a63a456 100644 --- a/app/models/article_price.rb +++ b/app/models/article_price.rb @@ -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 diff --git a/app/models/mailer.rb b/app/models/mailer.rb index bab5eaf2..55fa7991 100644 --- a/app/models/mailer.rb +++ b/app/models/mailer.rb @@ -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 diff --git a/app/models/shared_article.rb b/app/models/shared_article.rb index 5fe90129..3606e77c 100644 --- a/app/models/shared_article.rb +++ b/app/models/shared_article.rb @@ -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 diff --git a/app/models/shared_supplier.rb b/app/models/shared_supplier.rb index fd4d8f0a..e907ec26 100644 --- a/app/models/shared_supplier.rb +++ b/app/models/shared_supplier.rb @@ -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 diff --git a/app/views/layouts/application.haml b/app/views/layouts/application.haml index e7f08e6d..1d2659cc 100644 --- a/app/views/layouts/application.haml +++ b/app/views/layouts/application.haml @@ -17,7 +17,7 @@ #logo %a{:href => "/"} foodsoft - %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 diff --git a/app/views/layouts/email.html.erb b/app/views/layouts/email.html.erb index d789db3f..78af305d 100644 --- a/app/views/layouts/email.html.erb +++ b/app/views/layouts/email.html.erb @@ -2,5 +2,5 @@ -- FoodSoft: <%= @foodsoftUrl %> -Foodcoop-Homepage: <%= APP_CONFIG[:base_url] %> -Hilfe/Help: <%= APP_CONFIG[:help_url] %> \ No newline at end of file +Foodcoop-Homepage: <%= Foodsoft.config[:base_url] %> +Hilfe/Help: <%= Foodsoft.config[:help_url] %> \ No newline at end of file diff --git a/app/views/layouts/login.haml b/app/views/layouts/login.haml index 8bc89297..068ac036 100644 --- a/app/views/layouts/login.haml +++ b/app/views/layouts/login.haml @@ -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] diff --git a/app/views/login/invite.haml b/app/views/login/invite.haml index ef4c99c9..15c82043 100644 --- a/app/views/login/invite.haml +++ b/app/views/login/invite.haml @@ -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 diff --git a/app/views/mailer/negative_balance.html.erb b/app/views/mailer/negative_balance.html.erb index 4d6a405e..f44aea6e 100644 --- a/app/views/mailer/negative_balance.html.erb +++ b/app/views/mailer/negative_balance.html.erb @@ -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] %> \ No newline at end of file +Viele Grüße von <%= Foodsoft.config[:name] %> \ No newline at end of file diff --git a/app/views/mailer/order_result.html.erb b/app/views/mailer/order_result.html.erb index f1633c91..1b0bbc6b 100644 --- a/app/views/mailer/order_result.html.erb +++ b/app/views/mailer/order_result.html.erb @@ -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] %> \ No newline at end of file +Viele Grüße von <%= Foodsoft.config[:name] %> \ No newline at end of file diff --git a/app/views/mailer/upcoming_tasks.html.erb b/app/views/mailer/upcoming_tasks.html.erb index 793a1ee9..b310b710 100644 --- a/app/views/mailer/upcoming_tasks.html.erb +++ b/app/views/mailer/upcoming_tasks.html.erb @@ -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] %> \ No newline at end of file +Viele Grüße von <%= Foodsoft.config[:name] %> \ No newline at end of file diff --git a/app/views/messages/new.haml b/app/views/messages/new.haml index 4af2e9e5..72939eea 100644 --- a/app/views/messages/new.haml +++ b/app/views/messages/new.haml @@ -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 diff --git a/app/views/orders/faxPdf.pdf.prawn b/app/views/orders/faxPdf.pdf.prawn index 6f056c13..5294b0b6 100644 --- a/app/views/orders/faxPdf.pdf.prawn +++ b/app/views/orders/faxPdf.pdf.prawn @@ -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 diff --git a/app/views/shared/_loginInfo.haml b/app/views/shared/_loginInfo.haml index ad2db31f..ce5c4830 100644 --- a/app/views/shared/_loginInfo.haml +++ b/app/views/shared/_loginInfo.haml @@ -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' \ No newline at end of file diff --git a/config/initializers/load_app_config.rb b/config/initializers/load_app_config.rb index 2ba8c728..904ce9cb 100644 --- a/config/initializers/load_app_config.rb +++ b/config/initializers/load_app_config.rb @@ -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'] \ No newline at end of file +ExceptionNotifier.exception_recipients = Foodsoft.config[:notification]['error_recipients'] +ExceptionNotifier.sender_address = Foodsoft.config[:notification]['sender_address'] +ExceptionNotifier.email_prefix = Foodsoft.config[:notification]['email_prefix'] \ No newline at end of file