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

Version Path
iugusdk-1.0.11 app/models/account_role.rb
iugusdk-1.0.10 app/models/account_role.rb
iugusdk-1.0.9 app/models/account_role.rb
iugusdk-1.0.8 app/models/account_role.rb
iugusdk-1.0.7 app/models/account_role.rb
iugusdk-1.0.6 app/models/account_role.rb
iugusdk-1.0.5 app/models/account_role.rb
iugusdk-1.0.4 app/models/account_role.rb
iugusdk-1.0.3 app/models/account_role.rb
iugusdk-1.0.2 app/models/account_role.rb
iugusdk-1.0.1 app/models/account_role.rb
iugusdk-1.0.0.alpha.32 app/models/account_role.rb
iugusdk-1.0.0.alpha.31 app/models/account_role.rb
iugusdk-1.0.0.alpha.30 app/models/account_role.rb
iugusdk-1.0.0.alpha.29 app/models/account_role.rb
iugusdk-1.0.0.alpha.28 app/models/account_role.rb
iugusdk-1.0.0.alpha.27 app/models/account_role.rb
iugusdk-1.0.0.alpha.26 app/models/account_role.rb
iugusdk-1.0.0.alpha.25 app/models/account_role.rb
iugusdk-1.0.0.alpha.24 app/models/account_role.rb