-
Notifications
You must be signed in to change notification settings - Fork 57
Give each CardGrant its own CardGrantSetting (Part 1) #11259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
7664d58
5b7a510
cf40795
30b588b
dd7547c
8e88971
8b65663
86a3d7e
e420889
68c5f28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
module OneTimeJobs | ||
class BackfillCardGrantSettings | ||
def self.perform | ||
CardGrant.find_each do |cg| | ||
default_card_grant_setting = CardGrantSetting.find_by(event_id: cg.id) | ||
ActiveRecord::Base.transaction do | ||
card_grant_setting = CardGrantSetting.find_or_create_by!(card_grant_id: cg.id) | ||
card_grant_setting.update!({ | ||
banned_categories: cg.banned_categories || default_card_grant_setting.banned_categories, | ||
banned_merchants: cg.banned_merchants || default_card_grant_setting.banned_merchants, | ||
category_lock: cg.category_lock || default_card_grant_setting.category_lock, | ||
expiration_preference: default_card_grant_setting.expiration_preference, | ||
invite_message: default_card_grant_setting.invite_message, | ||
keyword_lock: cg.keyword_lock || default_card_grant_setting.keyword_lock, | ||
merchant_lock: cg.merchant_lock || default_card_grant_setting.merchant_lock, | ||
pre_authorization_required: cg.pre_authorization_required || default_card_grant_setting.pre_authorization_required, | ||
reimbursement_conversions_enabled: default_card_grant_setting.reimbursement_conversions_enabled | ||
}) | ||
end | ||
Luke-Oldenburg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
end | ||
end | ||
|
||
end | ||
end |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Is the plan to eventually drop all the attributes on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any values that can have a default configured should be moved over to the setting. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class AddCardGrantToCardGrantSetting < ActiveRecord::Migration[7.2] | ||
disable_ddl_transaction! | ||
|
||
def up | ||
add_reference :card_grant_settings, :card_grant, index: {algorithm: :concurrently} | ||
end | ||
|
||
def down | ||
remove_reference :card_grant_settings, :card_grant, index: {algorithm: :concurrently} | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class MakeEventIdOnCardGrantSettingNullable < ActiveRecord::Migration[7.2] | ||
def up | ||
change_column_null :card_grant_settings, :event_id, true | ||
end | ||
|
||
def down | ||
raise ActiveRecord::IrreversibleMigration, "this migration cannot be reversed because event id may be null" | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
on a new line, our Rubocop config will let you shift all of these lines to the leftpre_authorization_required
?). If so the fallback logic isn't going to work as if the card-grant-specific setting isfalse
we'll always check the fallback.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I'll add hardcoded fallbacks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I follow.
To illustrate my point, imagine we
cg.pre_authorization_required
isfalse
butdefault_card_grant_setting.pre_authorization_required
is true, we'll always returnstrue
asfalse || true
evaluates totrue
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh I didn't follow. How can I get around that without a bunch of nested ternaries calling
.present?
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 something like this could do