diff --git a/.gitignore b/.gitignore index 69e73788..0b4b3134 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ config/environments/development.rb capfile config/environments/fcschinke09.rb *.swp +*~ public/**/*_cached.* config/initializers/session_store.rb .idea diff --git a/Gemfile b/Gemfile index 2bf05686..fec6f012 100644 --- a/Gemfile +++ b/Gemfile @@ -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 \ No newline at end of file +end diff --git a/README_DEVEL b/README_DEVEL index 060a4ed0..53d20372 100644 --- a/README_DEVEL +++ b/README_DEVEL @@ -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 \ No newline at end of file + script/server diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index c9bb0de7..053a0646 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -172,4 +172,4 @@ class OrdersController < ApplicationController end redirect_to order end -end \ No newline at end of file +end diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index ee11b6a8..57bff129 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5ea4120c..fbf40827 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/models/order.rb b/app/models/order.rb index f154501f..2f49345a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -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 diff --git a/app/models/task.rb b/app/models/task.rb index 7a3dfacf..f32e6ebd 100644 --- a/app/models/task.rb +++ b/app/models/task.rb @@ -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) diff --git a/app/models/user.rb b/app/models/user.rb index 81b80e9f..3011d2a4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/messages/new.haml b/app/views/messages/new.haml index 72939eea..ee119d96 100644 --- a/app/views/messages/new.haml +++ b/app/views/messages/new.haml @@ -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" \ No newline at end of file + = submit_tag "Senden" diff --git a/app/views/ordering/_order_head.haml b/app/views/ordering/_order_head.haml index 126fe200..ada44597 100644 --- a/app/views/ordering/_order_head.haml +++ b/app/views/ordering/_order_head.haml @@ -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) diff --git a/app/views/ordering/my_order_result.haml b/app/views/ordering/my_order_result.haml index 14d5b6c7..2177d73c 100644 --- a/app/views/ordering/my_order_result.haml +++ b/app/views/ordering/my_order_result.haml @@ -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) diff --git a/app/views/orders/show.haml b/app/views/orders/show.haml index 7d16b185..77b3629e 100644 --- a/app/views/orders/show.haml +++ b/app/views/orders/show.haml @@ -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 \ No newline at end of file + = link_to_top diff --git a/db/migrate/20121112093327_add_created_by_user_id_to_orders.rb b/db/migrate/20121112093327_add_created_by_user_id_to_orders.rb new file mode 100644 index 00000000..64614aa4 --- /dev/null +++ b/db/migrate/20121112093327_add_created_by_user_id_to_orders.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 0e034bbd..033e1ef6 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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"