-
Notifications
You must be signed in to change notification settings - Fork 58
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
Conversation
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
db/schema.rb
Outdated
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.
concern: I'm a bit concerned about this approach as we now have
event_id |
card_grant_id |
|
---|---|---|
NULL |
✅ | Applies to card grant |
✅ | NULL |
Applies to event |
NULL |
NULL |
??? |
✅ | ✅ | ??? |
My recommendation here would be to keep event_id
as NOT NULL
(as card grants are specific to an event and can't be moved between events), which reduces the state space considerably
card_grant_id |
|
---|---|
✅ | Applies to card grant |
NULL |
Applies to event |
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.
How would I reference an events card grant setting? I can't make it a unique index so there's only one per event if we require event id for all of them.
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 can't make it a unique index so there's only one per event if we require event id for all of them.
I believe you can create a unique index over event_id, card_grant_id
with NULLS NOT DISTINCT
(https://www.postgresql.org/docs/15/sql-createindex.html) which will ensure there's only one row with card_grant_id = null
per event_id
.
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 that it's possible to write this in pure Ruby.
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.
yes - you can have a has_one
with a scope:
has_one :totp, -> { where(aasm_state: :verified) }, class_name: "User::Totp", inverse_of: :user
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.
Sorry I meant creating the migration to add the index. How would I do that?
default_cg_setting = @event.card_grant_setting | ||
CardGrantSetting.create!( | ||
{ | ||
banned_categories: default_cg_setting.banned_categories, | ||
banned_merchants: default_cg_setting.banned_merchants, | ||
category_lock: cg_params.category_lock, | ||
expiration_preference: default_cg_setting.expiration_preference, | ||
invite_message: default_cg_setting.invite_message, | ||
keyword_lock: cg_params.keyword_lock, | ||
merchant_lock: cg_params.merchant_lock, | ||
pre_authorization_required: cg_params.pre_authorization_required, | ||
reimbursement_conversions_enabled: default_cg_setting.reimbursement_conversions_enabled, | ||
card_grant_id: @card_grant.id, | ||
event_id: @event.id | ||
} | ||
) |
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.
could we do this cleaner - maybe cloning the object?
@@ -21,7 +21,7 @@ | |||
<%= link_to "Reimbursements", edit_event_path(@event, tab: "reimbursements"), data: { turbo: true, turbo_action: "advance" } %> | |||
<% end %> | |||
<% end %> | |||
<% if @event.card_grant_setting.present? %> | |||
<% if @event.plan.card_grants_enabled? %> |
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.
hmm - what happens if card_grant_setting is nil?
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.
It shouldn't be with this new system - I guess we could keep the old logic here.
Summary of the problem
Describe your changes