-
Notifications
You must be signed in to change notification settings - Fork 28
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
add action to link users to accounts #696
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ ✅ All tests successful. No failed tests found. 📢 Thoughts on this report? Let us know! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. @@ Coverage Diff @@
## main #696 +/- ##
==========================================
+ Coverage 91.63% 91.65% +0.02%
==========================================
Files 632 632
Lines 16872 16917 +45
==========================================
+ Hits 15461 15506 +45
Misses 1411 1411
Flags with carried forward coverage won't be shown. Click here to find out more.
📣 Codecov offers a browser extension for seamless coverage viewing on GitHub. Try it in Chrome or Firefox today! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. @@ Coverage Diff @@
## main #696 +/- ##
==========================================
+ Coverage 91.63% 91.65% +0.02%
==========================================
Files 632 632
Lines 16872 16917 +45
==========================================
+ Hits 15461 15506 +45
Misses 1411 1411
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #696 +/- ##
===========================================
Coverage 95.98000 95.98000
===========================================
Files 812 812
Lines 18209 18254 +45
===========================================
+ Hits 17477 17522 +45
Misses 732 732
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
f5fc9d2
to
daf2712
Compare
codecov_auth/admin.py
Outdated
@admin.action(description="Link Users to Account") | ||
def link_users_to_account(self, request, queryset): | ||
for account in queryset: | ||
all_plan_activated_user_ids = set() |
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.
Nit/Optional: I find the "all" a bit redundant since the variable is plural. I also got tripped up a bit reading this like "(all plan) (activated user ids)" instead of "(all) (plan activated user ids)" 😅, but that might be me. I think calling this "activated_user_ids_in_orgs" represents this a bit better?
Similar idea for the rest of the "alls" as well
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 see what you mean. I'm naming it after the field on the Owner
model, plan_activated_users
, which is actually a list of ownerids (😭)
what I want this to represent is that they have been collected and deduped, so they represent the unique owner objects that need to be connected to the Account
(through their User
)
account_plan_activated_user_ownerids
?
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.
haha yeah naming is hard :/. That sounds good to me, I'll leave it up to you for final naming, you're the most familiar w/ the code so as long as it makes sense to you 👍
ownerid__in=all_plan_activated_user_ids | ||
).prefetch_related("user") | ||
non_student_count = all_plan_activated_users.exclude(student=True).count() | ||
total_seats_for_account = account.plan_seat_count + account.free_seat_count |
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.
What's a free seat count? I see it's defaulted to 0, is this for like free plans?
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's a thing that exists on Owners currently (named free
), but it's a way for us to give Orgs additional seats not in the count they pay for (plan_seat_count
) 🤷
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.
damn, was not aware of this
codecov_auth/admin.py
Outdated
all_plan_activated_users = Owner.objects.filter( | ||
ownerid__in=all_plan_activated_user_ids | ||
).prefetch_related("user") | ||
non_student_count = all_plan_activated_users.exclude(student=True).count() |
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.
Optional: maybe adding a comment on why we exclude students. Thanks for being so attentive and catching this this early, this is a edge case for suuuure
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.
hmmm, not really an edge case - check out activated_user_count
or can_activate_user
methods on Owner
and Account
- it's our built in policy.
I'm following the methods defined on the models to calculate things like can_activate_user
- but having to write it out instead of using the pre-built methods so that I can do bulk operations 👍
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.
Right, what I meant was that this is an easy thing to slip since the majority of our customers aren't students, so I was praising you for being diligent, looking at previous code and learning about our policy
codecov_auth/admin.py
Outdated
) | ||
userless_owners = [] | ||
for userless_owner in owners_without_user_objects: | ||
new_user = User.objects.create() |
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.
Is this new User object meant to be empty?
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.
no! fixed!
ty ty ty
total = Owner.objects.bulk_update(userless_owners, ["user"]) | ||
self.message_user( | ||
request, | ||
f"Created a User for {total} Owners", |
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.
Would probably be handy to log the owner ids we did this for 👀, up to you
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.
Left some comments, overall lgtm! Lmk and I can approve
268e8f7
to
0bda337
Compare
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.
Generally LGTM! This is only for adding orgs for now, correct? We would need some different mechanism if we were to remove orgs from accounts...
updated and added based on @adrian-codecov and @michelletran-codecov feedback! ty for the comments ❤️
|
Purpose/Motivation
Gives us a method to do the initial setup when an Account is created. This action will create the link between the Account object and the User object for any Owner who is a
plan_activated_user
on any of the Organizations linked to the Account.Can be run multiple times safely (in case it errors or times out)
Won't do the link if the Account doesn't have enough seats
For "auditing" its behavior - it gives messages about how many Users and AccountUsers were created. You can see the Users linked to the Account on the Account edit page (when you click into an Account on the admin). You can remove a AccountUsers connection on the User admin page.
Links to relevant tickets
Uses codecov/shared#295
part of codecov/engineering-team#2058