Skip to content

Commit 652b809

Browse files
Add deactivated_at to User model to allow users to be deactivated (#476)
Changes: * DB migration * Schema and Model updates * Change Profile controller to filter out deactivated Users
1 parent 0023c5c commit 652b809

File tree

7 files changed

+15
-1
lines changed

7 files changed

+15
-1
lines changed

app/controllers/profiles_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ProfilesController < ApplicationController
77

88
def index
99
@profiles = @competition.profiles.published
10+
.where("#{User.table_name}.deactivated_at is null")
1011
.where.not(identifier: [nil, ''])
1112
.preload(:user)
1213
.includes(:skills)

app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# current_sign_in_at :datetime
1818
# current_sign_in_ip :inet
1919
# data_cruncher :boolean default(FALSE)
20+
# deactivated_at :datetime
2021
# dietary_requirements :text
2122
# email :string default(""), not null
2223
# encrypted_password :string default(""), not null
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class AddDeactivatedAtToUser < ActiveRecord::Migration[7.0]
2+
def up
3+
add_column :users, :deactivated_at, :datetime
4+
end
5+
def down
6+
remove_column :users, :deactivated_at
7+
end
8+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.0].define(version: 2022_07_11_130633) do
13+
ActiveRecord::Schema[7.0].define(version: 2025_08_22_200000) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616

@@ -523,6 +523,7 @@
523523
t.boolean "under_18"
524524
t.integer "region"
525525
t.integer "acting_on_behalf_of_id"
526+
t.datetime "deactivated_at"
526527
t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true
527528
t.index ["email"], name: "index_users_on_email", unique: true
528529
t.index ["region"], name: "index_users_on_region"

spec/factories/users.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# current_sign_in_at :datetime
1818
# current_sign_in_ip :inet
1919
# data_cruncher :boolean default(FALSE)
20+
# deactivated_at :datetime
2021
# dietary_requirements :text
2122
# email :string default(""), not null
2223
# encrypted_password :string default(""), not null

test/fixtures/users.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# current_sign_in_at :datetime
1616
# current_sign_in_ip :inet
1717
# data_cruncher :boolean default(FALSE)
18+
# deactivated_at :datetime
1819
# dietary_requirements :text
1920
# email :string default(""), not null
2021
# encrypted_password :string default(""), not null

test/models/user_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# current_sign_in_at :datetime
1818
# current_sign_in_ip :inet
1919
# data_cruncher :boolean default(FALSE)
20+
# deactivated_at :datetime
2021
# dietary_requirements :text
2122
# email :string default(""), not null
2223
# encrypted_password :string default(""), not null

0 commit comments

Comments
 (0)