2009-01-06 11:49:19 +01:00
|
|
|
class Membership < ActiveRecord::Base
|
|
|
|
|
|
|
|
belongs_to :user
|
|
|
|
belongs_to :group
|
2011-05-15 23:43:23 +02:00
|
|
|
|
|
|
|
before_destroy :check_last_admin
|
2009-01-06 11:49:19 +01:00
|
|
|
|
|
|
|
# messages
|
2013-03-22 01:21:44 +01:00
|
|
|
ERR_NO_ADMIN_MEMBER_DELETE = I18n.t('model.membership.no_admin_delete')
|
2011-05-15 23:43:23 +02:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
2009-01-06 11:49:19 +01:00
|
|
|
# check if this is the last admin-membership and deny
|
2011-05-15 23:43:23 +02:00
|
|
|
def check_last_admin
|
2009-01-06 11:49:19 +01:00
|
|
|
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
|
2011-05-07 21:55:24 +02:00
|
|
|
|