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

update account-detail endpoint to show info on Account if the Org has an Account #730

Merged
merged 1 commit into from
Aug 5, 2024

Conversation

nora-codecov
Copy link
Contributor

What does this PR do?

There are certain fields that are controlled by the Account if the Org has an Account. These changes make it so that when you view the plan or member page, if your Org has an Account, you see the details from the Account, not the Org.

Also adds logic to make sure that a user cannot do self-serve functions (changing their plan) if they have an Account. The current implementation of Accounts are that they are sales-led only, they have to change their plan details through their sales contact, and if they were able to change the plan on a single Org in the Account, weird things would happen. So if they have an Account we want to block these actions.

@nora-codecov nora-codecov requested a review from a team August 2, 2024 00:07
@codecov-notifications
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Aug 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.03%. Comparing base (4e8122c) to head (1c20675).
Report is 2 commits behind head on main.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@             Coverage Diff             @@
##               main       #730   +/-   ##
===========================================
  Coverage   96.03000   96.03000           
===========================================
  Files           814        814           
  Lines         18424      18449   +25     
===========================================
+ Hits          17693      17718   +25     
  Misses          731        731           
Flag Coverage Δ
unit 91.75% <100.00%> (+0.01%) ⬆️
unit-latest-uploader 91.75% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +146 to +150
current_org = self.context["view"].owner
if current_org.account:
raise serializers.ValidationError(
detail="You cannot update your plan manually, for help or changes to plan, connect with sales@codecov.io"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm... I might be misunderstanding how Django Serializers work, but I'm a bit surprised that this error didn't get raised in the test_retrieve_org_with_account test. AccountPlanSerializer references a plan that is serialized by PlanSerializer. If there is an account on the org (which there is), then I would guess that when the plan attempts to serialize, then it would fail here... 🤔

Copy link
Contributor Author

@nora-codecov nora-codecov Aug 2, 2024

Choose a reason for hiding this comment

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

heheh, this is definitely a django serializers thing. there are different flows to serialize incoming and outgoing objects. the object only goes through validate when you try to update it, so when the object is incoming to the database with changes. It doesn't go through here on the way out to be displayed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oooff, this is definitely not intuitive.

Would we also want to pull some values in this "plan" from the accounts object instead? i.e. plan type, billing rate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

heheheh, it is :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so for Orgs, we need to think about the GET experience and the PATCH experience, (no POSTs to this endpoint)

the GET experience (what we return to the User to see), they see the pretty_plan from the Account if the Org has an Account, if they don't have an account they see the pretty_plan on the Org.

The PATCH experience (user wants to update plan):

  • without Account: can update the plan on the Org according to all the layered rules and validation we have already 😅
  • with Account: firstly, they shouldn't be able to see options to update the plan since they are sales led, so this should never happen, but just in case they manage to send this in, reject changes with this error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this logic is twisty-turny because things like the pretty_plan replacement are happening in shared and plan updating comes through gazebo (+1 for monorepo!!), lmk if you wanna do a call to trace the pathways 👍 👍 👍

Copy link
Contributor

@michelletran-codecov michelletran-codecov left a comment

Choose a reason for hiding this comment

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

Generally LGTM. Just a non-blocking question on whether the PlanSerializer returns the values that we would actually like (for users with accounts).

@nora-codecov nora-codecov added this pull request to the merge queue Aug 5, 2024
Merged via the queue into main with commit 96ade56 Aug 5, 2024
17 of 18 checks passed
@nora-codecov nora-codecov deleted the nora/2060 branch August 5, 2024 19:07
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.

2 participants