Removed acts-as-statemachine. Replaces User.find_ordergroup with ActiveRecord-Association 'has_one :ordergroup'.
This commit is contained in:
parent
ec402ffa7b
commit
e16bebd042
10 changed files with 33 additions and 47 deletions
|
@ -3,7 +3,7 @@ class HomeController < ApplicationController
|
|||
|
||||
def index
|
||||
@currentOrders = Order.open
|
||||
@ordergroup = @current_user.find_ordergroup
|
||||
@ordergroup = @current_user.ordergroup
|
||||
if @ordergroup
|
||||
@financial_transactions = @ordergroup.financial_transactions.find(:all, :order => 'created_on desc', :limit => 3)
|
||||
end
|
||||
|
@ -37,7 +37,7 @@ class HomeController < ApplicationController
|
|||
|
||||
def ordergroup
|
||||
@user = @current_user
|
||||
@ordergroup = @user.find_ordergroup
|
||||
@ordergroup = @user.ordergroup
|
||||
@ordergroup_column_names = ["Description", "Actual Size", "Balance", "Updated"]
|
||||
@ordergroup_columns = ["description", "actual_size", "account_balance", "account_updated"]
|
||||
|
||||
|
|
|
@ -149,7 +149,7 @@ class OrderingController < ApplicationController
|
|||
# Returns true if @current_user is member of an Ordergroup.
|
||||
# Used as a :before_filter by OrderingController.
|
||||
def ensure_ordergroup_member
|
||||
@ordergroup = @current_user.find_ordergroup
|
||||
@ordergroup = @current_user.ordergroup
|
||||
if @ordergroup.nil?
|
||||
flash[:notice] = 'Sie gehören keiner Bestellgruppe an.'
|
||||
redirect_to :controller => root_path
|
||||
|
|
|
@ -40,13 +40,7 @@ class Group < ActiveRecord::Base
|
|||
|
||||
# Returns all NONmembers and a checks for possible multiple Ordergroup-Memberships
|
||||
def non_members
|
||||
nonMembers = Array.new
|
||||
for user in User.find(:all, :order => "nick")
|
||||
unless self.users.include?(user) || ( self.is_a?(Ordergroup) && user.find_ordergroup )
|
||||
nonMembers << user
|
||||
end
|
||||
end
|
||||
return nonMembers
|
||||
User.all(:order => 'nick').reject { |u| users.include?(u) }
|
||||
end
|
||||
|
||||
# Check before destroy a group, if this is the last group with admin role
|
||||
|
@ -56,11 +50,6 @@ class Group < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# get all groups, which are NOT Ordergroups
|
||||
def self.workgroups
|
||||
Workgroup.all
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# validates uniqueness of the Group.name. Checks groups and ordergroups
|
||||
|
|
|
@ -43,6 +43,9 @@ class Ordergroup < Group
|
|||
|
||||
attr_accessible :actual_size, :account_updated
|
||||
|
||||
def non_members
|
||||
User.all(:order => 'nick').reject { |u| (users.include?(u) || u.ordergroup) }
|
||||
end
|
||||
|
||||
def value_of_open_orders(exclude = nil)
|
||||
group_orders.open.reject{|go| go == exclude}.collect(&:price).sum
|
||||
|
|
|
@ -23,7 +23,7 @@ require 'digest/sha1'
|
|||
class User < ActiveRecord::Base
|
||||
has_many :memberships, :dependent => :destroy
|
||||
has_many :groups, :through => :memberships
|
||||
has_many :ordergroups, :through => :memberships, :source => :group
|
||||
has_one :ordergroup, :through => :memberships, :source => :group
|
||||
has_many :assignments, :dependent => :destroy
|
||||
has_many :tasks, :through => :assignments
|
||||
has_many :send_messages, :class_name => "Message", :foreign_key => "sender_id"
|
||||
|
@ -147,13 +147,7 @@ class User < ActiveRecord::Base
|
|||
groups.detect {|group| group.role_orders?}
|
||||
end
|
||||
|
||||
# Returns the user's Ordergroup or nil if none found.
|
||||
def find_ordergroup
|
||||
ordergroups.first
|
||||
end
|
||||
|
||||
def ordergroup_name
|
||||
ordergroup = find_ordergroup
|
||||
ordergroup ? ordergroup.name : "keine Bestellgruppe"
|
||||
end
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
%li= link_to _("Write message"), :controller => "messages", :action => "new"
|
||||
|
||||
// Orders
|
||||
- hasOrdergroup = !@current_user.find_ordergroup.nil?
|
||||
- hasOrdergroup = !@current_user.ordergroup.nil?
|
||||
- hasOrdersRole = @current_user.role_orders?
|
||||
- if hasOrdergroup || hasOrdersRole
|
||||
%li
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<ul class="autocomplete">
|
||||
<% for user in @users do -%>
|
||||
<li><span class="nick"><%=h user.nick %></span><span class="informal"> (<%= user.find_ordergroup.name.to_s if user.find_ordergroup %>)</span></li>
|
||||
<li><span class="nick"><%=h user.nick %></span><span class="informal"> (<%= user.ordergroup.name.to_s if user.ordergroup %>)</span></li>
|
||||
<% end -%>
|
||||
</ul>
|
|
@ -2,5 +2,5 @@
|
|||
%h4= link_to_function group.name, "Element.toggle('group_#{group.id}')"
|
||||
%ul{:style => "display:none"}[group]
|
||||
- for user in group.users.find :all, :order => "nick"
|
||||
%li= user.nick + " (#{user.find_ordergroup.name if user.find_ordergroup})"
|
||||
%li= user.nick + " (#{user.ordergroup.name if user.ordergroup})"
|
||||
|
|
@ -67,7 +67,6 @@ Rails::Initializer.run do |config|
|
|||
# library for parsing/writing files from/to csv-file
|
||||
config.gem "fastercsv"
|
||||
config.gem "prawn"
|
||||
config.gem "rubyist-aasm", :lib => 'aasm', :version => '2.0.5', :source => "http://gems.github.com" # acts_as_statemachine
|
||||
|
||||
# The internationalization framework can be changed to have another default locale (standard is :en) or more load paths.
|
||||
# All files from config/locales/*.rb,yml are added automatically.
|
||||
|
|
|
@ -3,24 +3,25 @@
|
|||
|
||||
namespace :foodsoft do
|
||||
|
||||
# "rake foodsoft:create_admin"
|
||||
desc "creates Administrators-group and admin-user"
|
||||
task :create_admin => :environment do
|
||||
puts "Create Group 'Administators'"
|
||||
administrators = Group.create(:name => "Administrators",
|
||||
:description => "System administrators.",
|
||||
:role_admin => true,
|
||||
:role_finance => true,
|
||||
:role_article_meta => true,
|
||||
:role_suppliers => true,
|
||||
:role_orders => true)
|
||||
# "rake foodsoft:create_admin"
|
||||
desc "creates Administrators-group and admin-user"
|
||||
task :create_admin => :environment do
|
||||
puts "Create Workgroup 'Administators'"
|
||||
administrators = Workgroup.create(
|
||||
:name => "Administrators",
|
||||
:description => "System administrators.",
|
||||
:role_admin => true,
|
||||
:role_finance => true,
|
||||
:role_article_meta => true,
|
||||
:role_suppliers => true,
|
||||
:role_orders => true
|
||||
)
|
||||
|
||||
puts "Create User 'admin' with password 'secret'"
|
||||
admin = User.new(:nick => "admin", :first_name => "Anton", :last_name => "Administrator", :email => "admin@foo.test")
|
||||
admin.password = "secret"
|
||||
admin.save
|
||||
puts "Create User 'admin' with password 'secret'"
|
||||
admin = User.create(:nick => "admin", :first_name => "Anton", :last_name => "Administrator",
|
||||
:email => "admin@foo.test", :password => "secret")
|
||||
|
||||
puts "Joining 'admin' user to 'Administrators' group"
|
||||
Membership.create(:group => administrators, :user => admin)
|
||||
end
|
||||
puts "Joining 'admin' user to 'Administrators' group"
|
||||
Membership.create(:group => administrators, :user => admin)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue