8a74e7d77f
Annotate: Better look in schema.rb, this reference should be always up to date. Hirb: To reactivate hirb, look in railscasts: http://railscasts.com/episodes/48-console-tricks-revised
18 lines
494 B
Ruby
18 lines
494 B
Ruby
class Membership < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
|
belongs_to :group
|
|
|
|
before_destroy :check_last_admin
|
|
|
|
# messages
|
|
ERR_NO_ADMIN_MEMBER_DELETE = "Mitgliedschaft kann nicht beendet werden. Du bist die letzte Administratorin"
|
|
|
|
protected
|
|
|
|
# check if this is the last admin-membership and deny
|
|
def check_last_admin
|
|
raise ERR_NO_ADMIN_MEMBER_DELETE if self.group.role_admin? && self.group.memberships.size == 1 && Group.find_all_by_role_admin(true).size == 1
|
|
end
|
|
end
|
|
|