From 5c48ecb8ff48a377884a029f15dfb0bf115294b4 Mon Sep 17 00:00:00 2001 From: cenon-delrosario Date: Wed, 3 Sep 2025 10:47:08 +1000 Subject: [PATCH] Change Profiles controller to only display users that have registered to Competition events Changes: * Refactor Profiles controller to only display users that have registered to Competition events * Revert Users.deactivated_at because no longer required --- app/controllers/profiles_controller.rb | 31 +++++++++++++++++-- app/models/user.rb | 1 - ...250903110000_remove_user_deactivated_at.rb | 8 +++++ db/schema.rb | 3 +- spec/factories/users.rb | 1 - test/fixtures/users.yml | 1 - test/models/user_test.rb | 1 - 7 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 db/migrate/20250903110000_remove_user_deactivated_at.rb diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 1b83017a..563ae2c9 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -6,9 +6,34 @@ class ProfilesController < ApplicationController before_action :check_profile_found!, :check_published!, only: :show def index - @profiles = @competition.profiles.published - .where("#{User.table_name}.deactivated_at is null") - .where.not(identifier: [nil, '']) + # Original filter + # @profiles = @competition.profiles.published + # .where.not(identifier: [nil, '']) + # .preload(:user) + # .includes(:skills) + # + # Changed to only display profiles for users that have registered + # for a Competition Event Type for the given @competition (i.e. Current Competition) + @profiles = Profile + .joins( + user: { + assignments: { + registrations: %i[event competition], + }, + }, + ) + .where.not( + identifier: [nil, ''], + ) + .where( + events: { + event_type: 'Competition', + }, + competitions: { + id: @competition.id, + }, + ) + .published .preload(:user) .includes(:skills) end diff --git a/app/models/user.rb b/app/models/user.rb index 402a0832..d4f3c0e9 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -17,7 +17,6 @@ # current_sign_in_at :datetime # current_sign_in_ip :inet # data_cruncher :boolean default(FALSE) -# deactivated_at :datetime # dietary_requirements :text # email :string default(""), not null # encrypted_password :string default(""), not null diff --git a/db/migrate/20250903110000_remove_user_deactivated_at.rb b/db/migrate/20250903110000_remove_user_deactivated_at.rb new file mode 100644 index 00000000..852b7da1 --- /dev/null +++ b/db/migrate/20250903110000_remove_user_deactivated_at.rb @@ -0,0 +1,8 @@ +class RemoveUserDeactivatedAt < ActiveRecord::Migration[7.0] + def up + remove_column :users, :deactivated_at + end + def down + add_column :users, :deactivated_at, :datetime + end +end diff --git a/db/schema.rb b/db/schema.rb index 4e56d89c..f429a5f9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2025_08_22_200000) do +ActiveRecord::Schema[7.0].define(version: 2025_09_03_110000) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -523,7 +523,6 @@ t.boolean "under_18" t.integer "region" t.integer "acting_on_behalf_of_id" - t.datetime "deactivated_at" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["region"], name: "index_users_on_region" diff --git a/spec/factories/users.rb b/spec/factories/users.rb index e17fd5be..1e850917 100644 --- a/spec/factories/users.rb +++ b/spec/factories/users.rb @@ -17,7 +17,6 @@ # current_sign_in_at :datetime # current_sign_in_ip :inet # data_cruncher :boolean default(FALSE) -# deactivated_at :datetime # dietary_requirements :text # email :string default(""), not null # encrypted_password :string default(""), not null diff --git a/test/fixtures/users.yml b/test/fixtures/users.yml index 3540b201..ff1839aa 100644 --- a/test/fixtures/users.yml +++ b/test/fixtures/users.yml @@ -15,7 +15,6 @@ # current_sign_in_at :datetime # current_sign_in_ip :inet # data_cruncher :boolean default(FALSE) -# deactivated_at :datetime # dietary_requirements :text # email :string default(""), not null # encrypted_password :string default(""), not null diff --git a/test/models/user_test.rb b/test/models/user_test.rb index 3668e21e..ba20aa44 100644 --- a/test/models/user_test.rb +++ b/test/models/user_test.rb @@ -17,7 +17,6 @@ # current_sign_in_at :datetime # current_sign_in_ip :inet # data_cruncher :boolean default(FALSE) -# deactivated_at :datetime # dietary_requirements :text # email :string default(""), not null # encrypted_password :string default(""), not null