Admin namespace beendet.
This commit is contained in:
parent
6ddef7267a
commit
172db1d37e
23 changed files with 78 additions and 193 deletions
|
|
@ -5,10 +5,7 @@ class Group < ActiveRecord::Base
|
|||
has_many :users, :through => :memberships
|
||||
|
||||
validates :name, :presence => true, :length => {:in => 1..25}, :uniqueness => true
|
||||
validate :last_admin_on_earth, :on => :update
|
||||
|
||||
before_destroy :check_last_admin_group
|
||||
|
||||
|
||||
attr_reader :user_tokens
|
||||
|
||||
# Returns true if the given user if is an member of this group.
|
||||
|
|
@ -24,28 +21,6 @@ class Group < ActiveRecord::Base
|
|||
def user_tokens=(ids)
|
||||
self.user_ids = ids.split(",")
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Check before destroy a group, if this is the last group with admin role
|
||||
def check_last_admin_group
|
||||
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
|
||||
|
||||
# validates uniqueness of the Group.name. Checks groups and ordergroups
|
||||
def validate
|
||||
errors.add(:name, "ist schon vergeben") if (group = Group.find_by_name(name) || group = Ordergroup.find_by_name(name)) && self != group
|
||||
end
|
||||
|
||||
# add validation check on update
|
||||
# Return an error if this is the last group with admin role and role_admin should set to false
|
||||
def last_admin_on_earth
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ class Ordergroup < Group
|
|||
has_many :orders, :through => :group_orders
|
||||
|
||||
validates_numericality_of :account_balance, :message => 'ist keine gültige Zahl'
|
||||
validate :uniqueness_of_members
|
||||
|
||||
after_create :update_stats!
|
||||
|
||||
|
|
@ -78,6 +79,13 @@ class Ordergroup < Group
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Make sure, that a user can only be in one ordergroup
|
||||
def uniqueness_of_members
|
||||
users.each do |user|
|
||||
errors.add :user_tokens, "#{user.nick} ist schon in einer anderen Bestellgruppe" if user.groups.where(:type => 'Ordergroup').size > 1
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class User < ActiveRecord::Base
|
|||
attr_accessor :password, :setting_attributes
|
||||
|
||||
validates_presence_of :nick, :email
|
||||
validates_presence_of :password_hash, :message => "Password is required."
|
||||
validates_presence_of :password, :on => :create
|
||||
validates_length_of :nick, :in => 2..25
|
||||
validates_uniqueness_of :nick, :case_sensitive => false
|
||||
validates_format_of :email, :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i
|
||||
|
|
|
|||
|
|
@ -6,6 +6,9 @@ class Workgroup < Group
|
|||
|
||||
validates_presence_of :task_name, :weekday, :task_required_users,
|
||||
:if => Proc.new {|workgroup| workgroup.weekly_task }
|
||||
validate :last_admin_on_earth, :on => :update
|
||||
before_destroy :check_last_admin_group
|
||||
|
||||
|
||||
def self.weekdays
|
||||
[["Montag", "1"], ["Dienstag", "2"], ["Mittwoch","3"],["Donnerstag","4"],["Freitag","5"],["Samstag","6"],["Sonntag","0"]]
|
||||
|
|
@ -42,6 +45,23 @@ class Workgroup < Group
|
|||
:weekly => true
|
||||
}
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
# Check before destroy a group, if this is the last group with admin role
|
||||
def check_last_admin_group
|
||||
if role_admin && Workgroup.where(:role_admin => true).size == 1
|
||||
raise "Die letzte Gruppe mit Admin-Rechten darf nicht gelöscht werden"
|
||||
end
|
||||
end
|
||||
|
||||
# add validation check on update
|
||||
# Return an error if this is the last group with admin role and role_admin should set to false
|
||||
def last_admin_on_earth
|
||||
if !role_admin && Workgroup.where(:role_admin => true, :id.ne => id).empty?
|
||||
errors.add(:role_admin, "Der letzten Gruppe mit Admin-Rechten darf die Admin-Rolle nicht entzogen werden")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue