-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Billing #2667
Merged
Merged
Billing #2667
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
ab9e548
k
pablonyx d015a02
data -> control
pablonyx 30559b0
nit
pablonyx 9efd372
nit: error handling
pablonyx 8a726fb
auth + app
pablonyx 7859d97
nit: color standardization
pablonyx 85f8fff
nit
pablonyx 9809295
nit: typing
pablonyx cdafb32
k
pablonyx 518e0ef
k
pablonyx c356812
feat: functional upgrading
pablonyx 2f0b625
feat: add block for downgrading to seats < active users
pablonyx cf14be7
add auth
pablonyx 3f13dd6
remove accomplished todo + prints
pablonyx 516af73
nit
pablonyx 18f7a8f
tiny nit
pablonyx a1289bd
nit: centralize security
pablonyx e0f4e1f
add tenant expulsion/gating + invite user -> increment billing seat no.
pablonyx 36c31eb
add cloud configs
pablonyx a91b534
k
pablonyx afae460
k
pablonyx 6faad9c
nit: update
pablonyx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
from datetime import timezone | ||
|
||
import jwt | ||
from email_validator import EmailNotValidError | ||
from email_validator import EmailUndeliverableError | ||
from email_validator import validate_email | ||
from fastapi import APIRouter | ||
from fastapi import Body | ||
|
@@ -35,6 +37,7 @@ | |
from danswer.configs.app_configs import SESSION_EXPIRE_TIME_SECONDS | ||
from danswer.configs.app_configs import VALID_EMAIL_DOMAINS | ||
from danswer.configs.constants import AuthType | ||
from danswer.db.auth import get_total_users | ||
from danswer.db.engine import current_tenant_id | ||
from danswer.db.engine import get_session | ||
from danswer.db.models import AccessToken | ||
|
@@ -60,6 +63,7 @@ | |
from ee.danswer.db.api_key import is_api_key_email_address | ||
from ee.danswer.db.external_perm import delete_user__ext_group_for_user__no_commit | ||
from ee.danswer.db.user_group import remove_curator_status__no_commit | ||
from ee.danswer.server.tenants.billing import register_tenant_users | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here and around this line, it should not import from ee |
||
from ee.danswer.server.tenants.provisioning import add_users_to_tenant | ||
from ee.danswer.server.tenants.provisioning import remove_users_from_tenant | ||
|
||
|
@@ -174,19 +178,29 @@ def list_all_users( | |
def bulk_invite_users( | ||
emails: list[str] = Body(..., embed=True), | ||
current_user: User | None = Depends(current_admin_user), | ||
db_session: Session = Depends(get_session), | ||
) -> int: | ||
"""emails are string validated. If any email fails validation, no emails are | ||
invited and an exception is raised.""" | ||
|
||
if current_user is None: | ||
raise HTTPException( | ||
status_code=400, detail="Auth is disabled, cannot invite users" | ||
) | ||
|
||
tenant_id = current_tenant_id.get() | ||
|
||
normalized_emails = [] | ||
for email in emails: | ||
email_info = validate_email(email) # can raise EmailNotValidError | ||
normalized_emails.append(email_info.normalized) # type: ignore | ||
try: | ||
for email in emails: | ||
email_info = validate_email(email) | ||
normalized_emails.append(email_info.normalized) # type: ignore | ||
|
||
except (EmailUndeliverableError, EmailNotValidError): | ||
raise HTTPException( | ||
status_code=400, | ||
detail="One or more emails in the list are invalid", | ||
) | ||
|
||
if MULTI_TENANT: | ||
try: | ||
|
@@ -199,30 +213,58 @@ def bulk_invite_users( | |
) | ||
raise | ||
|
||
all_emails = list(set(normalized_emails) | set(get_invited_users())) | ||
initial_invited_users = get_invited_users() | ||
|
||
if MULTI_TENANT and ENABLE_EMAIL_INVITES: | ||
try: | ||
for email in all_emails: | ||
send_user_email_invite(email, current_user) | ||
except Exception as e: | ||
logger.error(f"Error sending email invite to invited users: {e}") | ||
all_emails = list(set(normalized_emails) | set(initial_invited_users)) | ||
number_of_invited_users = write_invited_users(all_emails) | ||
|
||
return write_invited_users(all_emails) | ||
if not MULTI_TENANT: | ||
return number_of_invited_users | ||
try: | ||
logger.info("Registering tenant users") | ||
register_tenant_users(current_tenant_id.get(), get_total_users(db_session)) | ||
if ENABLE_EMAIL_INVITES: | ||
try: | ||
for email in all_emails: | ||
send_user_email_invite(email, current_user) | ||
except Exception as e: | ||
logger.error(f"Error sending email invite to invited users: {e}") | ||
|
||
return number_of_invited_users | ||
except Exception as e: | ||
logger.error(f"Failed to register tenant users: {str(e)}") | ||
logger.info( | ||
"Reverting changes: removing users from tenant and resetting invited users" | ||
) | ||
write_invited_users(initial_invited_users) # Reset to original state | ||
remove_users_from_tenant(normalized_emails, tenant_id) | ||
raise e | ||
|
||
|
||
@router.patch("/manage/admin/remove-invited-user") | ||
def remove_invited_user( | ||
user_email: UserByEmail, | ||
_: User | None = Depends(current_admin_user), | ||
db_session: Session = Depends(get_session), | ||
) -> int: | ||
user_emails = get_invited_users() | ||
remaining_users = [user for user in user_emails if user != user_email.user_email] | ||
|
||
tenant_id = current_tenant_id.get() | ||
remove_users_from_tenant([user_email.user_email], tenant_id) | ||
number_of_invited_users = write_invited_users(remaining_users) | ||
|
||
try: | ||
if MULTI_TENANT: | ||
register_tenant_users(current_tenant_id.get(), get_total_users(db_session)) | ||
except Exception: | ||
logger.error( | ||
"Request to update number of seats taken in control plane failed. " | ||
"This may cause synchronization issues/out of date enforcement of seat limits." | ||
) | ||
raise | ||
|
||
return write_invited_users(remaining_users) | ||
return number_of_invited_users | ||
|
||
|
||
@router.patch("/manage/admin/deactivate-user") | ||
|
@@ -421,7 +463,6 @@ def get_current_token_creation( | |
|
||
@router.get("/me") | ||
def verify_user_logged_in( | ||
request: Request, | ||
user: User | None = Depends(optional_user), | ||
db_session: Session = Depends(get_session), | ||
) -> UserInfo: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We should not import ee modules from the MIT stuff. It confuses the separation between the versions.
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.
There are other places this is done but we should address those.