mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
Merge pull request #36 from hackclub/automatic-migration
Automatically migrate user data on signin
This commit is contained in:
@@ -20,6 +20,12 @@ class SessionsController < ApplicationController
|
||||
|
||||
if @user&.persisted?
|
||||
session[:user_id] = @user.id
|
||||
|
||||
if @user.data_migration_jobs.empty?
|
||||
# if they don't have a data migration job, add one to the queue
|
||||
OneTime::MigrateUserFromHackatimeJob.perform_later(@user.id)
|
||||
end
|
||||
|
||||
redirect_to root_path, notice: "Successfully signed in with Slack!"
|
||||
else
|
||||
Rails.logger.error "Failed to create/update user from Slack data"
|
||||
|
||||
@@ -11,11 +11,7 @@ class UsersController < ApplicationController
|
||||
enabled: true,
|
||||
).where.not(slack_channel_id: "C0835AZP9GB")
|
||||
|
||||
@heartbeats_migration_jobs = GoodJob::Job.where(
|
||||
"serialized_params->>'arguments' LIKE ?", "%#{@user.id}%"
|
||||
).where(
|
||||
"job_class = ?", "OneTime::MigrateUserFromHackatimeJob"
|
||||
).order(created_at: :desc).limit(10).all
|
||||
@heartbeats_migration_jobs = @user.data_migration_jobs
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@@ -28,6 +28,14 @@ class User < ApplicationRecord
|
||||
compliment_text: 2
|
||||
}
|
||||
|
||||
def data_migration_jobs
|
||||
GoodJob::Job.where(
|
||||
"serialized_params->>'arguments' LIKE ?", "%#{id}%"
|
||||
).where(
|
||||
"job_class = ?", "OneTime::MigrateUserFromHackatimeJob"
|
||||
).order(created_at: :desc).limit(10).all
|
||||
end
|
||||
|
||||
def format_extension_text(duration)
|
||||
case hackatime_extension_text_type
|
||||
when "simple_text"
|
||||
|
||||
Reference in New Issue
Block a user