Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddNotesToDeviceProfilingResult < ActiveRecord::Migration[8.0]
def up
add_column :device_profiling_results, :notes, :string, comment: 'sensitive=false'
end

def down
remove_column :device_profiling_results, :notes
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.0].define(version: 2025_06_11_195441) do
ActiveRecord::Schema[8.0].define(version: 2025_07_14_184424) do
# These are extensions that must be enabled in order to support this database
enable_extension "citext"
enable_extension "pg_catalog.plpgsql"
Expand Down Expand Up @@ -96,6 +96,7 @@
t.string "profiling_type", comment: "sensitive=false"
t.datetime "created_at", null: false, comment: "sensitive=false"
t.datetime "updated_at", null: false, comment: "sensitive=false"
t.string "notes", comment: "sensitive=false"
t.index ["user_id"], name: "index_device_profiling_results_on_user_id"
end

Expand Down
79 changes: 79 additions & 0 deletions lib/tasks/device_profiling.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# frozen_string_literal: true

namespace :device_profiling do
desc 'Approve rejected device profiling results to pass for list of UUIDs'
task :approve_rejected_users, [:user_uuids] => :environment do |_task, _args|
user_uuids = ARGV[1]

if user_uuids.blank?
puts 'Error: user_uuids is required'
exit 1
end

# Parse UUIDs
uuid_list = user_uuids.split(',').map(&:strip).reject(&:blank?)

puts "Processing #{uuid_list.count} user UUID(s)"
puts "Action: Change 'reject' to 'pass' (skip if already 'pass')"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand this. Is change/reject somehow associated with the uuids?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes its where we are changing the TMX device profile object from reject to pass since it was wrongly flagged as a reject.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action is just listing what will be happening throughout the script.

puts ''

total_users_processed = 0
total_results_updated = 0
skipped_already_passed = 0
users_with_no_results = 0

uuid_list.each do |user_uuid|
total_users_processed += 1

begin
# Find user by UUID
user = User.find_by(uuid: user_uuid)
if user.blank?
puts "User not found: #{user_uuid}"
next
end

# Find device profiling results for this user (reject or pass)
result = DeviceProfilingResult.where(
user_id: user.id,
profiling_type: DeviceProfilingResult::PROFILING_TYPES[:account_creation],
).first

if result.nil?
users_with_no_results += 1
puts "No device profiling results found for: #{user_uuid} (#{user.email})"
next
end

# Check if already passed

if result.review_status == 'pass'
skipped_already_passed += 1
puts "Already passed: #{user_uuid}"
next
end

# Update rejected results to pass
puts "Updating rejected result for: #{user_uuid}"
result.update!(review_status: 'pass', notes: 'Manually overridden')
total_results_updated += 1

puts "Successfully updated result for: #{user_uuid}"

# Log for audit
rescue => e
puts "Error processing #{user_uuid}: #{e.message}"
end
end

puts ''
puts '=' * 80
puts 'SUMMARY:'
puts "Total users processed: #{total_users_processed}"
puts "Results updated (reject → pass): #{total_results_updated}"
puts "Users already passed: #{skipped_already_passed}"
puts "Users with no results: #{users_with_no_results}"

puts 'Task completed successfully!'
end
end