Introduced acts_as_paranoid. Avoid deleting of suppliers and articles. (for consistency of order-results)

This commit is contained in:
Benjamin Meichsner 2009-01-20 19:37:15 +01:00
parent b820577382
commit fc45345e0d
30 changed files with 1238 additions and 151 deletions

View file

@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20090115232435
# Schema version: 20090119155930
#
# Table name: articles
#
@ -22,9 +22,12 @@
# created_at :datetime
# updated_at :datetime
# quantity :decimal(6, 2) default(0.0)
# deleted_at :datetime
#
class Article < ActiveRecord::Base
acts_as_paranoid # Avoid deleting the article for consistency of order-results
belongs_to :supplier
belongs_to :article_category

View file

@ -32,10 +32,6 @@ class Group < ActiveRecord::Base
validates_length_of :name, :in => 1..25
validates_uniqueness_of :name
# messages
ERR_LAST_ADMIN_GROUP_UPDATE = "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden"
ERR_LAST_ADMIN_GROUP_DELETE = "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
# Returns true if the given user if is an member of this group.
def member?(user)
memberships.find_by_user_id(user.id)
@ -54,7 +50,9 @@ class Group < ActiveRecord::Base
# Check before destroy a group, if this is the last group with admin role
def before_destroy
raise ERR_LAST_ADMIN_GROUP_DELETE if self.role_admin == true && Group.find_all_by_role_admin(true).size == 1
if self.role_admin == true && Group.find_all_by_role_admin(true).size == 1
raise "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
end
end
# get all groups, which are NOT Ordergroups
@ -72,7 +70,9 @@ class Group < ActiveRecord::Base
# add validation check on update
def validate_on_update
# error if this is the last group with admin role and role_admin should set to false
errors.add(:role_admin, ERR_LAST_ADMIN_GROUP_UPDATE) if self.role_admin == false && Group.find_all_by_role_admin(true).size == 1 && self == Group.find(:first, :conditions => "role_admin = 1")
if self.role_admin == false && Group.find_all_by_role_admin(true).size == 1 && self == Group.find(:first, :conditions => "role_admin = 1")
errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden")
end
end
end

View file

@ -1,5 +1,5 @@
# == Schema Information
# Schema version: 20090102171850
# Schema version: 20090119155930
#
# Table name: suppliers
#
@ -18,9 +18,12 @@
# note :string(255)
# shared_supplier_id :integer(4)
# min_order_quantity :string(255)
# deleted_at :datetime
#
class Supplier < ActiveRecord::Base
acts_as_paranoid # Avoid deleting the supplier for consistency of order-results
has_many :articles, :dependent => :destroy
has_many :orders
has_many :deliveries

View file

@ -150,7 +150,6 @@ class User < ActiveRecord::Base
# Returns the user's Ordergroup or nil if none found.
def find_ordergroup
ordergroups.first
#groups.find(:first, :conditions => "type = 'Ordergroup'")
end
# Find all tasks, for which the current user should be responsible