Merge pull request #80 from balkansalat/master

Session store, order creator, mailing list wiki link, task validation
This commit is contained in:
bennibu 2012-12-12 09:01:22 -08:00
commit 35ec54b4f4
15 changed files with 63 additions and 18 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@ config/environments/development.rb
capfile capfile
config/environments/fcschinke09.rb config/environments/fcschinke09.rb
*.swp *.swp
*~
public/**/*_cached.* public/**/*_cached.*
config/initializers/session_store.rb config/initializers/session_store.rb
.idea .idea

View file

@ -1,5 +1,6 @@
# A sample Gemfile # A sample Gemfile
source "http://rubygems.org" source "http://rubygems.org"
ruby "1.8.7"
gem "rails", '2.3.11' gem "rails", '2.3.11'
@ -13,4 +14,4 @@ gem 'sqlite3-ruby'
group :development do group :development do
gem 'annotate' gem 'annotate'
gem 'hirb' gem 'hirb'
end end

View file

@ -36,7 +36,16 @@ You need to create your own copy of the foodsoft configuration settings:
Edit app_config.yml to suit your needs or just keep the defaults for now. Edit app_config.yml to suit your needs or just keep the defaults for now.
(4) Required ruby and gems (4) Secret Token
-------------------
The user session is stored in a cookie. To avoid misusing the cookies and its sensitive information, rails will encrypt it with a token. So copy the config file
cp config/initializers/session_store.rb.SAMPLE config/initializers/session_store.rb
and modify the token "config.action_controller.session"!
(5) Required ruby and gems
------------------- -------------------
We reccomend the using of rvm (https://rvm.beginrescueend.com/). Install rvm and get the lates ruby (1.8.7). We reccomend the using of rvm (https://rvm.beginrescueend.com/). Install rvm and get the lates ruby (1.8.7).
If installed you only need to install the gem bundler: If installed you only need to install the gem bundler:
@ -48,7 +57,7 @@ After that you get the other gems easily with (from project root):
bundle install bundle install
(5) Create database (schema) and load defaults (6) Create database (schema) and load defaults
-------------------------- --------------------------
rake db:create rake db:create
rake db:schema:load rake db:schema:load
@ -57,8 +66,8 @@ After that you get the other gems easily with (from project root):
With this, you also get a ready to go user with username 'admin' and password 'secret'. With this, you also get a ready to go user with username 'admin' and password 'secret'.
(6) Try it out! (7) Try it out!
--------------- ---------------
Start the WEBrick server to try it out: Start the WEBrick server to try it out:
script/server script/server

View file

@ -172,4 +172,4 @@ class OrdersController < ApplicationController
end end
redirect_to order redirect_to order
end end
end end

View file

@ -17,14 +17,13 @@ class TasksController < ApplicationController
def create def create
@task = Task.new(params[:task]) @task = Task.new(params[:task])
if @task.errors.empty? if @task.errors.empty? && @task.save
@task.save
flash[:notice] = "Aufgabe wurde erstellt" flash[:notice] = "Aufgabe wurde erstellt"
if @task.workgroup if @task.workgroup
redirect_to :action => "workgroup", :id => @task.workgroup redirect_to :action => "workgroup", :id => @task.workgroup
else else
redirect_to :action => "index" redirect_to :action => "index"
end end
else else
render :template => "tasks/new" render :template => "tasks/new"
end end
@ -41,8 +40,7 @@ class TasksController < ApplicationController
def update def update
@task = Task.find(params[:id]) @task = Task.find(params[:id])
@task.attributes=(params[:task]) @task.attributes=(params[:task])
if @task.errors.empty? if @task.errors.empty? && @task.save
@task.save
flash[:notice] = "Aufgabe wurde aktualisiert" flash[:notice] = "Aufgabe wurde aktualisiert"
if @task.workgroup if @task.workgroup
redirect_to :action => "workgroup", :id => @task.workgroup redirect_to :action => "workgroup", :id => @task.workgroup

View file

@ -154,5 +154,11 @@ module ApplicationHelper
link_to h(address), "http://maps.google.de/?q=#{h(address)}", :title => "Show it on google maps", link_to h(address), "http://maps.google.de/?q=#{h(address)}", :title => "Show it on google maps",
:target => "_blank" :target => "_blank"
end end
# offers a link for writing message to user
# checks for nil (useful for relations)
def link_to_user_message_if_valid(user)
user.nil? ? '??' : ( link_to user.nick, user_message_path(user), :title => _('Nachricht schreiben') )
end
end end

View file

@ -11,13 +11,17 @@ class Order < ActiveRecord::Base
has_many :comments, :class_name => "OrderComment", :order => "created_at" has_many :comments, :class_name => "OrderComment", :order => "created_at"
has_many :stock_changes has_many :stock_changes
belongs_to :supplier belongs_to :supplier
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id" belongs_to :updated_by, :class_name => 'User', :foreign_key => 'updated_by_user_id'
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
# Validations # Validations
validates_presence_of :starts validates_presence_of :starts
validate :starts_before_ends, :include_articles validate :starts_before_ends, :include_articles
# Callbacks # Callbacks
before_create do |order|
order.created_by = User.current_user
end
after_update :update_price_of_group_orders after_update :update_price_of_group_orders
# Finders # Finders

View file

@ -11,7 +11,7 @@ class Task < ActiveRecord::Base
attr_protected :users attr_protected :users
validates_length_of :name, :minimum => 3 validates_length_of :name, :minimum => 3
validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than => 1 validates_numericality_of :duration, :required_users, :only_integer => true, :greater_than_or_equal_to => 1
after_save :update_ordergroup_stats after_save :update_ordergroup_stats
@ -29,6 +29,8 @@ class Task < ActiveRecord::Base
# extracts nicknames from a comma seperated string # extracts nicknames from a comma seperated string
# and makes the users responsible for the task # and makes the users responsible for the task
# TODO: check for uniqueness
# TODO: check for maximal number of users
def user_list=(string) def user_list=(string)
@user_list = string.split(%r{,\s*}) @user_list = string.split(%r{,\s*})
new_users = @user_list - users.collect(&:nick) new_users = @user_list - users.collect(&:nick)

View file

@ -11,6 +11,7 @@ class User < ActiveRecord::Base
has_many :tasks, :through => :assignments has_many :tasks, :through => :assignments
has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id" has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id"
has_many :pages, :foreign_key => 'updated_by' has_many :pages, :foreign_key => 'updated_by'
has_many :created_orders, :class_name => 'Order', :foreign_key => 'created_by_user_id', :dependent => :nullify
attr_accessor :password, :setting_attributes attr_accessor :password, :setting_attributes

View file

@ -17,8 +17,12 @@
%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 - if Foodsoft.config[:mailing_list_subscribe].blank?
= mail_to Foodsoft.config[:mailing_list_subscribe] Erklärungen zum Verteiler findest Du im
= link_to 'Wiki (Abschnitt Mailing-Liste)', wiki_page_path('MailingListe')
- else
z.b. mit einer Mail an
= mail_to Foodsoft.config[:mailing_list_subscribe]
%table#recipients %table#recipients
%tr %tr
%td %td
@ -58,4 +62,4 @@
%br/ %br/
~ f.text_area :body, :cols => '80', :rows => '20' ~ f.text_area :body, :cols => '80', :rows => '20'
= submit_tag "Senden" = submit_tag "Senden"

View file

@ -10,6 +10,9 @@
%p %p
%b Lieferantin: %b Lieferantin:
=h @order.name =h @order.name
%p
%b Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p %p
%b Ende: %b Ende:
=h format_time(@order.ends) =h format_time(@order.ends)

View file

@ -32,6 +32,9 @@
%p %p
Notiz: Notiz:
=h @order.note =h @order.note
%p
Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p %p
Ende: Ende:
%b=h format_time(@order.ends) %b=h format_time(@order.ends)

View file

@ -21,6 +21,9 @@
%p %p
Notiz: Notiz:
=h @order.note =h @order.note
%p
Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p %p
Beginn: Beginn:
%b=h format_time(@order.starts) %b=h format_time(@order.starts)
@ -90,4 +93,4 @@
%br/ %br/
= submit_tag "Kommentar hinzufügen" = submit_tag "Kommentar hinzufügen"
= link_to_top = link_to_top

View file

@ -0,0 +1,9 @@
class AddCreatedByUserIdToOrders < ActiveRecord::Migration
def self.up
add_column :orders, :created_by_user_id, :integer
end
def self.down
remove_column :orders, :created_by_user_id
end
end

View file

@ -9,7 +9,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20120622094337) do ActiveRecord::Schema.define(:version => 20121112093327) do
create_table "article_categories", :force => true do |t| create_table "article_categories", :force => true do |t|
t.string "name", :default => "", :null => false t.string "name", :default => "", :null => false
@ -234,6 +234,7 @@ ActiveRecord::Schema.define(:version => 20120622094337) do
t.integer "lock_version", :default => 0, :null => false t.integer "lock_version", :default => 0, :null => false
t.integer "updated_by_user_id" t.integer "updated_by_user_id"
t.decimal "foodcoop_result", :precision => 8, :scale => 2 t.decimal "foodcoop_result", :precision => 8, :scale => 2
t.integer "created_by_user_id"
end end
add_index "orders", ["state"], :name => "index_orders_on_state" add_index "orders", ["state"], :name => "index_orders_on_state"