foodsoft/app/models/membership.rb

17 lines
383 B
Ruby
Raw Normal View History

2009-01-06 11:49:19 +01:00
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :group
before_destroy :check_last_admin
2009-01-06 11:49:19 +01:00
protected
2009-01-06 11:49:19 +01:00
# check if this is the last admin-membership and deny
def check_last_admin
raise I18n.t('model.membership.no_admin_delete') if self.group.role_admin? && self.group.memberships.size == 1 && Group.where(role_admin: true).count == 1
2009-01-06 11:49:19 +01:00
end
end