Skip to content
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

[#153972] Add the option to remove the cancer center PriceGroup #2347

Merged
merged 3 commits into from
Jul 19, 2020

Conversation

giladshanan
Copy link
Collaborator

@giladshanan giladshanan commented Jul 17, 2020

Release Notes

UMass doesn't have a cancer center Price Group. The seed file will just skip creating a cancer center PriceGroup if no cancer_center key is found in settings.yml. I added a rake task that makes it easier to destroy an existing global PriceGroup if needed. The rake task will fail if the PriceGroup has any associated order_details.

@giladshanan giladshanan requested a review from a team as a code owner July 17, 2020 14:51
price_group.update_attribute(:admin_editable, false)
end
# This was relevant for updating records when the migration was run back in 2015.
# The PriceGroup#cancer_center method no longer exists. Leaving this here for documentation.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhanggi what do you think about this? I could see an argument for leaving it alone or removing it altogether. Let me know what you think.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably a good call to leave it in. The seeds cover the right settings for this attribute, right?

Copy link
Contributor

@jhanggi jhanggi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple thoughts, nothing I feel super strongly about, so I would be open to pushback on.

price_group.update_attribute(:admin_editable, false)
end
# This was relevant for updating records when the migration was run back in 2015.
# The PriceGroup#cancer_center method no longer exists. Leaving this here for documentation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is probably a good call to leave it in. The seeds cover the right settings for this attribute, right?

@@ -17,7 +17,7 @@ class PriceGroup < ApplicationRecord

default_scope -> { order(is_internal: :desc, display_order: :asc, name: :asc) }

before_destroy { throw :abort if global? }
before_destroy :throw_abort, if: :global?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's mainly just a personal preference., but I kind of prefer the block form for one-liners unless the method name aids understanding intention.

What's your opinion for why you pulled this up into a method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I get it now. You made it a method so you could skip it in the rake task.

task :cancer_center, [:cancer_center_name] => :environment do |_t, args|
cc_name = args[:cancer_center_name] || "Cancer Center Rate"
pg = PriceGroup.find_by(name: cc_name)
abort("No cancer center price group found with name #{cc_name}") unless pg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do a find_by! and let that exception take care of this for us. This could be better UI, though.

pg = PriceGroup.find_by(name: cc_name)
abort("No cancer center price group found with name #{cc_name}") unless pg

PriceGroup.skip_callback(:destroy, :before, :throw_abort)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about instead of skipping the callback, we set pg.global = false. Then the callback should get skipped as well and I would expect the destroy to go through. I think both feel a little hacky, but we are kind of hacking the system here.

Copy link
Collaborator Author

@giladshanan giladshanan Jul 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global? method checks for an associated facility. So the other option would be to set pg.facility = Facility.first or something like that. Do we actually have a cancer center price group on UMass prod? Another possible option would be adding a boolean to settings like cancer_center_enabled and adding some logic to the can_delete? method:

before_destroy { throw :abort unless can_delete? }

def can_delete?
  # use !.any? because it uses SQL count(), unlike none?
  (is_not_global? || deletable_cancer_denter?) && !order_details.any?
end

def deletable_cancer_center?
  !Settings.cancer_center_enabled && name.include?("Cancer"))
end

If we do that, admins can delete the cancer center price group through the UI.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There definitely is a cancer center group on UMass production. That's why we're trying to get rid of it: to prevent confusion when they go live for real.

If setting the pg.facility = Facility.first works and allows us to delete it without being to disruptive, I'd vote for that. This is a very special case so I'd rather not change internal functionality if we can avoid it.

I'd prefer what you currently have with the skipping the callback over adding a new setting and allowing this to happen on the UI. I'll leave it up to you whether you want to go with the callback skipping or the facility setting.

@giladshanan giladshanan merged commit 6c7094b into master Jul 19, 2020
@giladshanan giladshanan deleted the 153972-remove-cancer-center branch July 19, 2020 21:16
@jhanggi jhanggi added the UMass label Aug 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants