-
Notifications
You must be signed in to change notification settings - Fork 8
Add resource sharing for organization collectives #355
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
base: master
Are you sure you want to change the base?
Conversation
| ai_credit_count["monthly"] = min(amount, organization.monthly_ai_credits) | ||
| amount -= ai_credit_count["monthly"] | ||
|
|
||
| ai_credit_count["regular"] = min(amount, organization.number_ai_credits) | ||
| amount -= ai_credit_count["regular"] | ||
|
|
||
| if amount > 0: | ||
| raise InsufficientAICreditsError(amount) | ||
|
|
||
| organization.monthly_ai_credits -= ai_credit_count["monthly"] | ||
| organization.number_ai_credits -= ai_credit_count["regular"] | ||
| organization.save() | ||
|
|
||
| # Then deduct from parent resources | ||
| if parent: | ||
| parent_monthly = min(amount, parent.monthly_ai_credits) | ||
| ai_credit_count["monthly"] += parent_monthly | ||
| amount -= parent_monthly | ||
| parent.monthly_ai_credits -= parent_monthly | ||
|
|
||
| parent_regular = min(amount, parent.number_ai_credits) | ||
| ai_credit_count["regular"] += parent_regular | ||
| amount -= parent_regular | ||
| parent.number_ai_credits -= parent_regular | ||
| parent.save() | ||
|
|
||
| # Then deduct from group resources | ||
| for group in groups: | ||
| group_monthly = min(amount, group.monthly_ai_credits) | ||
| ai_credit_count["monthly"] += group_monthly | ||
| amount -= group_monthly | ||
| group.monthly_ai_credits -= group_monthly | ||
|
|
||
| group_regular = min(amount, group.number_ai_credits) | ||
| ai_credit_count["regular"] += group_regular | ||
| amount -= group_regular | ||
| group.number_ai_credits -= group_regular | ||
| group.save() |
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.
Same comments about duplicated logic pointing to a refactoring opportunity. Seeing this logic shared between spending requests and AI credits makes that even more apparent! Doesn't need to get addressed now, but let's make sure we keep this in mind this during our payments refactor.
|
I correctly am able to see that MuckRock and MuckRock child are on the organization plan now, so I believe the latest squarelet fixed that integration. However, MuckRock child only shows 5000 AI credits though, instead of 10,000 (5k from itself and 5k from its parent). Requests does show the correct totals - child 100 requests, parent 50. |
These are the same changes as the MuckRock repo, except for premium credits instead of requests. Also, some of the code is in the library
squarelet-authwhich DocumentCloud uses but MuckRock does not for historical reasons