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
config/environments/fcschinke09.rb
*.swp
*~
public/**/*_cached.*
config/initializers/session_store.rb
.idea

View file

@ -1,5 +1,6 @@
# A sample Gemfile
source "http://rubygems.org"
ruby "1.8.7"
gem "rails", '2.3.11'
@ -13,4 +14,4 @@ gem 'sqlite3-ruby'
group :development do
gem 'annotate'
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.
(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).
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
(5) Create database (schema) and load defaults
(6) Create database (schema) and load defaults
--------------------------
rake db:create
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'.
(6) Try it out!
(7) 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
redirect_to order
end
end
end

View file

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

View file

@ -11,13 +11,17 @@ class Order < ActiveRecord::Base
has_many :comments, :class_name => "OrderComment", :order => "created_at"
has_many :stock_changes
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
validates_presence_of :starts
validate :starts_before_ends, :include_articles
# Callbacks
before_create do |order|
order.created_by = User.current_user
end
after_update :update_price_of_group_orders
# Finders

View file

@ -11,7 +11,7 @@ class Task < ActiveRecord::Base
attr_protected :users
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
@ -29,6 +29,8 @@ class Task < ActiveRecord::Base
# extracts nicknames from a comma seperated string
# and makes the users responsible for the task
# TODO: check for uniqueness
# TODO: check for maximal number of users
def user_list=(string)
@user_list = string.split(%r{,\s*})
new_users = @user_list - users.collect(&:nick)

View file

@ -11,6 +11,7 @@ class User < ActiveRecord::Base
has_many :tasks, :through => :assignments
has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id"
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

View file

@ -17,8 +17,12 @@
%small{:style => "color:grey"}
Eventuell musst Du Dich dem Verteiler erst bekannt machen.
%br/
z.b. mit einer Mail an
= mail_to Foodsoft.config[:mailing_list_subscribe]
- if Foodsoft.config[:mailing_list_subscribe].blank?
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
%tr
%td
@ -58,4 +62,4 @@
%br/
~ f.text_area :body, :cols => '80', :rows => '20'
= submit_tag "Senden"
= submit_tag "Senden"

View file

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

View file

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

View file

@ -21,6 +21,9 @@
%p
Notiz:
=h @order.note
%p
Erstellt von:
=h link_to_user_message_if_valid(@order.created_by)
%p
Beginn:
%b=h format_time(@order.starts)
@ -90,4 +93,4 @@
%br/
= 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.
ActiveRecord::Schema.define(:version => 20120622094337) do
ActiveRecord::Schema.define(:version => 20121112093327) do
create_table "article_categories", :force => true do |t|
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 "updated_by_user_id"
t.decimal "foodcoop_result", :precision => 8, :scale => 2
t.integer "created_by_user_id"
end
add_index "orders", ["state"], :name => "index_orders_on_state"