Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/jobs/identity/reap_aged_out_users_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ class Identity::ReapAgedOutUsersJob < ApplicationJob
queue_as :default

def perform
aged_out = Identity.where(ysws_eligible: true, hq_override: [false, nil])
aged_out = Identity.where(ysws_eligible: true, hq_override: [ false, nil ])
.where("birthday <= ?", 19.years.ago.to_date)

reaped_count = 0
Expand All @@ -15,4 +15,4 @@ def perform

Rails.logger.info "ReapAgedOutUsersJob: marked #{reaped_count} #{"user".pluralize reaped_count} as alumni and ineligible"
end
end
end
2 changes: 1 addition & 1 deletion app/services/analytics_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def promotion_breakdown
totals.map do |scenario, total|
prom = promoted[scenario] || 0
rate = total > 0 ? ((prom.to_f / total) * 100).round(1) : 0
[scenario || "default", { total: total, promoted: prom, rate: rate }]
[ scenario || "default", { total: total, promoted: prom, rate: rate } ]
end.sort_by { |_, v| -v[:total] }.to_h
end

Expand Down
38 changes: 38 additions & 0 deletions app/services/scim_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,13 @@ def build_user_payload(identity:, username:, user_type:)
}
}

# Set timezone based on user's browser
tz = timezone_for_identity(identity)
if tz.present?
payload[:timezone] = tz
Rails.logger.info "Setting Slack timezone to #{tz} for #{identity.primary_email}"
end

# Add guest extension for multi-channel guests
if user_type == :multi_channel_guest
payload[:schemas] << "urn:ietf:params:scim:schemas:extension:slack:guest:2.0:User"
Expand All @@ -294,5 +301,36 @@ def build_user_payload(identity:, username:, user_type:)

payload
end


def timezone_for_identity(identity)
# Prefer browser-detected timezone from the user's most recent session
session_tz = identity.sessions.order(created_at: :desc).pick(:timezone)
if session_tz.present?
begin
TZInfo::Timezone.get(session_tz)
return session_tz
rescue TZInfo::InvalidTimezoneIdentifier
Rails.logger.warn "Invalid session timezone '#{session_tz}' for identity #{identity.id}"
end
end

# Fall back to country-based timezone
country_code = identity.country
if country_code.present?
begin
country = TZInfo::Country.get(country_code.to_s)
zone_id = country.zone_identifiers.first
return zone_id if zone_id.present?
rescue TZInfo::InvalidCountryCode
Rails.logger.warn "Invalid country code '#{country_code}' for timezone lookup"
end
end

nil
rescue => e
Rails.logger.warn "Failed to determine timezone for identity #{identity.id}: #{e.message}"
nil
end
end
end