Sha256: 9c6b490412ccf5c5eaac9ec1e343e8e3825b9ab8c371114916a96e8a67eb378c
Contents?: true
Size: 692 Bytes
Versions: 35
Compression:
Stored size: 692 Bytes
Contents
class AccountRole < ActiveRecord::Base include ActiveUUID::UUID belongs_to :account_user validate :valid_role? validates_uniqueness_of :name, :scope => :account_user_id, :allow_nil => false validates_presence_of :account_user attr_accessible :name before_destroy do false if only_owner? end def self.roles APP_ROLES['roles'] end private def valid_role? errors.add(:name, "errors.messages.invalid_role") unless APP_ROLES['roles'].include? name end def only_owner? self.name == APP_ROLES['owner_role'] && AccountRole.joins(:account_user).where('account_users.account_id = ? AND name = ?', account_user.account_id, :owner).count <= 1 end end
Version data entries
35 entries across 35 versions & 1 rubygems