Merge branch 'master' of git://github.com/bennibu/foodsoft

This commit is contained in:
sandoz 2009-03-24 21:55:26 +01:00
commit 1ec3c08157
22 changed files with 112 additions and 76 deletions

View file

@ -1,5 +1,6 @@
class ApplicationController < ActionController::Base
# If you wanna run multiple foodcoops on one installation uncomment next line.
#before_filter :select_foodcoop
before_filter :authenticate, :store_controller
after_filter :remove_controller
@ -16,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
@ -57,23 +58,7 @@ class ApplicationController < ActionController::Base
return false
end
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"
if /^text\//.match(content_type)
headers["Content-Type"] = "#{content_type}; charset=utf-8"
end
end
private
def authenticate(role = 'any')
# Attempt to retrieve authenticated user from controller instance or session...
@ -150,4 +135,16 @@ class ApplicationController < ActionController::Base
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
# Get subdomain
subdomain = request.subdomains.first
# Set Config
Foodsoft.env = subdomain
# Set database-connection
ActiveRecord::Base.establish_connection(Foodsoft.database(subdomain))
end
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

@ -25,7 +25,6 @@ class Invoice < ActiveRecord::Base
belongs_to :order
validates_presence_of :supplier_id
validates_uniqueness_of :date, :scope => [:supplier_id]
named_scope :unpaid, :conditions => { :paid_on => nil }

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,9 +1,31 @@
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 env=(env)
@@env = env
end
def env
@@env
end
def config(rails_env = @@env)
@@configs[rails_env].symbolize_keys
end
def database(rails_env = @@env)
@@databases[rails_env].symbolize_keys
end
extend self
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']

View file

@ -1,9 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>Seite/Datei nicht gefunden!</h1>
<p>Das ist wohl eine Sackgasse und sollte eigentlich nicht vorkommen.</p>
<p>Bitte melden unter <a href="http://foodsoft.fcschinke09.de/">http://foodsoft.fcschinke09.de</a></p>
</body>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<h1>Seite/Datei nicht gefunden!</h1>
<p>Das ist wohl eine Sackgasse und sollte eigentlich nicht vorkommen.</p>
<p>Bitte melden unter <a href="http://dev.foodcoops.net/">http://dev.foodcoops.net</a></p>
</body>
</html>

View file

@ -1,9 +1,13 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<h1>FoodSoft Fehler!</h1>
<p>Ups, da ist uns wohl ein kleiner Fehler untergekommen.</p>
<p>Bitte melden unter <a href="http://foodsoft.fcschinke09.de/">http://foodsoft.fcschinke09.de</a></p>
</body>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<h1>FoodSoft Fehler!</h1>
<p>Ups, da ist uns wohl ein kleiner Fehler untergekommen.</p>
<p>Aber keine Angst. Die Entwicklerinnen sind automatisch darüber informiert worden
werden sich umgehen darum kümmern.</p>
</body>
</html>

11
public/503.html Normal file
View file

@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
</head>
<body>
<h1>Die FoodSoft wird gewartet!</h1>
<p>In ein paar Minuten dürfte aber wieder alles wieder funktionieren.... Nur Geduld ...</p>
</body>
</html>