Skip to content

Commit b08b505

Browse files
segiddinssimi
authored andcommitted
Add users.policies_acknowledged_at
So we can track when users last acked the policies, and prompt them to do so when we introduce/update them Signed-off-by: Samuel Giddins <segiddins@segiddins.me>
1 parent 496780c commit b08b505

5 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/avo/resources/user.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def fields # rubocop:disable Metrics
3939
field :mail_fails, as: :number
4040
field :blocked_email, as: :text
4141

42+
field :policies_acknowledged_at, as: :date_time
43+
4244
tabs style: :pills do
4345
tab "Auth" do
4446
field :encrypted_password, as: :password, visible: -> { false }

app/models/events/user_event.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@ class Events::UserEvent < ApplicationRecord
4444
end
4545

4646
PASSWORD_CHANGED = define_event "user:password:changed"
47+
48+
POLICIES_ACKNOWLEDGED = define_event "user:policies:acknowledged"
4749
end

app/models/user.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class User < ApplicationRecord
1717
after_update :record_email_update_event, if: :email_was_updated?
1818
after_update :record_email_verified_event, if: -> { saved_change_to_email? && email_confirmed? }
1919
after_update :record_password_update_event, if: :saved_change_to_encrypted_password?
20+
after_update :record_policies_acknowledged_event, if: :saved_change_to_policies_acknowledged_at?
2021
before_discard :yank_gems
2122
before_discard :expire_all_api_keys
2223
before_discard :destroy_associations_for_discard
@@ -375,4 +376,8 @@ def record_password_update_event
375376
def unique_with_org_handle
376377
errors.add(:handle, "has already been taken") if handle && Organization.where("lower(handle) = lower(?)", handle).any?
377378
end
379+
380+
def record_policies_acknowledged_event
381+
record_event!(Events::UserEvent::POLICIES_ACKNOWLEDGED)
382+
end
378383
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddPoliciesAcknowledgedAtToUsers < ActiveRecord::Migration[8.0]
2+
def change
3+
add_column :users, :policies_acknowledged_at, :datetime
4+
end
5+
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.2].define(version: 2024_11_04_065953) do
13+
ActiveRecord::Schema[8.0].define(version: 2025_03_12_181402) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "hstore"
1616
enable_extension "pgcrypto"
@@ -557,6 +557,7 @@
557557
t.string "mfa_hashed_recovery_codes", default: [], array: true
558558
t.boolean "public_email", default: false, null: false
559559
t.datetime "deleted_at"
560+
t.datetime "policies_acknowledged_at"
560561
t.index "lower((email)::text) varchar_pattern_ops", name: "index_users_on_lower_email"
561562
t.index ["email"], name: "index_users_on_email"
562563
t.index ["handle"], name: "index_users_on_handle"

0 commit comments

Comments
 (0)