Sha256: 953f3fa1f760242cdba5e1f4493780cdd46f84af19fcce2d6eb6fe1f2f3bd630

Contents?: true

Size: 953 Bytes

Versions: 26

Compression:

Stored size: 953 Bytes

Contents

module Mtwarden
	class Account < ActiveRecord::Base

		belongs_to :owner, :class_name => "Mtwarden::User"
		accepts_nested_attributes_for :owner

		belongs_to :plan, :class_name => "Mtwarden::Plan"

		validates :subdomain, :presence => true, :uniqueness => true
		validates :name, presence: true

		has_many :members, :class_name => "Mtwarden::Member"
		has_many :users, :through => :members

		EXCLUDED_SUBDOMAINS = %w(admin)
		validates_exclusion_of :subdomain, :in => EXCLUDED_SUBDOMAINS,
		:message => "is not allowed. Please choose another subdomain."

		validates_format_of :subdomain, :with => /\A[\w\-]+\Z/i,
		:message => "is not allowed. Please choose another subdomain."

		before_validation do
			self.subdomain = subdomain.to_s.downcase
		end

		def self.create_with_owner(params={})
			account = new(params)
			if account.save
				account.users << account.owner
			end
			account
		end

		def owner?(user)
			owner == user
		end
	end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
mtwarden-17.1.0 app/models/mtwarden/account.rb
mtwarden-17.0.0 app/models/mtwarden/account.rb
mtwarden-16.2.0 app/models/mtwarden/account.rb
mtwarden-16.1.0 app/models/mtwarden/account.rb
mtwarden-16.0.0 app/models/mtwarden/account.rb
mtwarden-15.0.0 app/models/mtwarden/account.rb
mtwarden-14.0.0 app/models/mtwarden/account.rb
mtwarden-13.0.1 app/models/mtwarden/account.rb
mtwarden-13.0.0 app/models/mtwarden/account.rb
mtwarden-12.0.0 app/models/mtwarden/account.rb
mtwarden-11.0.0 app/models/mtwarden/account.rb
mtwarden-9.0.0 app/models/mtwarden/account.rb
mtwarden-8.1.0 app/models/mtwarden/account.rb
mtwarden-8.0.1 app/models/mtwarden/account.rb
mtwarden-8.0.0 app/models/mtwarden/account.rb
mtwarden-7.2.0 app/models/mtwarden/account.rb
mtwarden-7.1.2 app/models/mtwarden/account.rb
mtwarden-7.1.1 app/models/mtwarden/account.rb
mtwarden-7.1.0 app/models/mtwarden/account.rb
mtwarden-7.0.0 app/models/mtwarden/account.rb