Skip to content

Conversation

Luke-Oldenburg
Copy link
Contributor

@Luke-Oldenburg Luke-Oldenburg commented Aug 7, 2025

Summary of the problem

Describe your changes

Luke-Oldenburg and others added 2 commits August 7, 2025 16:39
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
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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?

Comment on lines +31 to +46
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
}
)
Copy link
Member

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? %>
Copy link
Member

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?

Copy link
Contributor Author

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.

@Luke-Oldenburg
Copy link
Contributor Author

I think card grant settings are fine for now with the smaller improvements I just introduced.
#11632
#11633
#11634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants