Sha256: b5f11c447ea7adbbf2512e343e31da62b93515e144c7688e24a0b8e4679bb366

Contents?: true

Size: 938 Bytes

Versions: 9

Compression:

Stored size: 938 Bytes

Contents

module Jobshop
  class Team < ApplicationRecord
    belongs_to :owner, class_name: "Jobshop::User", optional: true
    has_many :users, class_name: "Jobshop::User"
    has_one :default_dashboard, class_name: "Jobshop::Dashboard"

    scope :grouped_by_email, ->(email_addresses) {
      Jobshop::User
        .where(email: email_addresses)
        .joins(:team)
        .includes(:team)
        .each_with_object({}) { |user, teams|
          (teams[user.email] ||= []) << user.team
        }
    }

    def generate_registration_token
      raw, encrypted = Devise.token_generator.generate(
        self.class, :registration_token)

      self.registration_token = encrypted
      self.registration_token_sent_at = Time.now.utc
      self.save(validate: false)

      raw
    end

    def registration_token_period_valid?
      registration_token_sent_at &&
        registration_token_sent_at.utc >= 30.minutes.ago.utc
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
jobshop-0.0.113 app/models/jobshop/team.rb
jobshop-0.0.109 app/models/jobshop/team.rb
jobshop-0.0.107 app/models/jobshop/team.rb
jobshop-0.0.101 app/models/jobshop/team.rb
jobshop-0.0.67 app/models/jobshop/team.rb
jobshop-0.0.61 app/models/jobshop/team.rb
jobshop-0.0.59 app/models/jobshop/team.rb
jobshop-0.0.53 app/models/jobshop/team.rb
jobshop-0.0.41 app/models/jobshop/team.rb