Sha256: 5a1d028bf3f8408ef90d6af4e584fc3df17b968c564ec70b2f9c463dbbb14345

Contents?: true

Size: 982 Bytes

Versions: 2

Compression:

Stored size: 982 Bytes

Contents

module Jobshop
  class Team < ApplicationRecord
    belongs_to :owner, class_name: "Jobshop::User", optional: true
    has_many :users
    has_many :things
    has_many :places
    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
      return false if owner_id
      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

2 entries across 2 versions & 1 rubygems

Version Path
jobshop-0.0.131 app/models/jobshop/team.rb
jobshop-0.0.127 app/models/jobshop/team.rb