Module: Teams::Base

Extended by:
ActiveSupport::Concern
Included in:
Team
Defined in:
app/models/concerns/teams/base.rb

Instance Method Summary collapse

Instance Method Details

#admin_usersObject



48
49
50
# File 'app/models/concerns/teams/base.rb', line 48

def admin_users
  admins.map(&:user).compact
end

#adminsObject



44
45
46
# File 'app/models/concerns/teams/base.rb', line 44

def admins
  memberships.current_and_invited.admins
end

#formatted_email_addressObject



56
57
58
# File 'app/models/concerns/teams/base.rb', line 56

def formatted_email_address
  primary_contact.email
end

#initialize(attributes = nil) ⇒ Object



28
29
30
31
# File 'app/models/concerns/teams/base.rb', line 28

def initialize(attributes = nil)
  super
  self.time_zone = "UTC" if time_zone.blank?
end

#invalidate_cachesObject



60
61
62
# File 'app/models/concerns/teams/base.rb', line 60

def invalidate_caches
  users.map(&:invalidate_ability_cache)
end

#platform_agent_access_tokensObject



40
41
42
# File 'app/models/concerns/teams/base.rb', line 40

def platform_agent_access_tokens
  Platform::AccessToken.joins(:application).where(resource_owner_id: users.where.not(platform_agent_of_id: nil), application: {team: nil})
end

#primary_contactObject



52
53
54
# File 'app/models/concerns/teams/base.rb', line 52

def primary_contact
  admin_users.min { |user| user.created_at }
end

#set_time_zone_from_user(user) ⇒ Object



33
34
35
36
37
38
# File 'app/models/concerns/teams/base.rb', line 33

def set_time_zone_from_user(user)
  if time_zone.blank? || time_zone == "UTC"
    self.time_zone = user.time_zone if user.time_zone.present?
    save
  end
end

#teamObject



64
65
66
67
68
# File 'app/models/concerns/teams/base.rb', line 64

def team
  # some generic features appeal to the `team` method for security or scoping purposes, but sometimes those same
  # generic functions need to function for a team model as well, so we do this.
  self
end