-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
178 additions
and
78 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from fastapi import APIRouter | ||
from fastapi import Depends | ||
from fastapi import HTTPException | ||
from sqlalchemy.orm import Session | ||
|
||
from ee.onyx.server.tenants.user_mapping import remove_users_from_tenant | ||
from onyx.auth.users import current_admin_user | ||
from onyx.db.engine import get_current_tenant_id | ||
from onyx.db.engine import get_session | ||
from onyx.db.models import User | ||
from onyx.db.users import get_user_by_email | ||
from onyx.server.manage.models import UserByEmail | ||
from onyx.server.manage.users import delete_user_from_db | ||
from onyx.utils.logger import setup_logger | ||
|
||
logger = setup_logger() | ||
router = APIRouter() | ||
|
||
|
||
@router.post("/manage/admin/leave-organization") | ||
async def leave_organization( | ||
user_email: UserByEmail, | ||
_: User | None = Depends(current_admin_user), | ||
db_session: Session = Depends(get_session), | ||
tenant_id: str = Depends(get_current_tenant_id), | ||
) -> None: | ||
user_to_delete = get_user_by_email( | ||
email=user_email.user_email, db_session=db_session | ||
) | ||
if not user_to_delete: | ||
raise HTTPException(status_code=404, detail="User not found") | ||
|
||
delete_user_from_db(user_to_delete, db_session) | ||
remove_users_from_tenant([user_to_delete.email], tenant_id) |
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
30 changes: 1 addition & 29 deletions
30
web/src/components/admin/users/buttons/DeactivaterButton.tsx
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
66 changes: 66 additions & 0 deletions
66
web/src/components/admin/users/buttons/LeaveOrganizationButton.tsx
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { type User } from "@/lib/types"; | ||
import { PopupSpec } from "@/components/admin/connectors/Popup"; | ||
import userMutationFetcher from "@/lib/admin/users/userMutationFetcher"; | ||
import useSWRMutation from "swr/mutation"; | ||
import { Button } from "@/components/ui/button"; | ||
import { useState } from "react"; | ||
import { DeleteEntityModal } from "@/components/modals/DeleteEntityModal"; | ||
export const LeaveOrganizationButton = ({ | ||
user, | ||
setPopup, | ||
mutate, | ||
}: { | ||
user: User; | ||
setPopup: (spec: PopupSpec) => void; | ||
mutate: () => void; | ||
}) => { | ||
const { trigger, isMutating } = useSWRMutation( | ||
"/api/manage/admin/leave-organization", | ||
userMutationFetcher, | ||
{ | ||
onSuccess: () => { | ||
mutate(); | ||
setPopup({ | ||
message: "Successfully left the organization!", | ||
type: "success", | ||
}); | ||
}, | ||
onError: (errorMsg) => | ||
setPopup({ | ||
message: `Unable to leave organization - ${errorMsg}`, | ||
type: "error", | ||
}), | ||
} | ||
); | ||
|
||
const [showLeaveModal, setShowLeaveModal] = useState(false); | ||
|
||
const handleLeaveOrganization = () => { | ||
trigger({ user_email: user.email, method: "POST" }); | ||
}; | ||
|
||
return ( | ||
<> | ||
{showLeaveModal && ( | ||
<DeleteEntityModal | ||
deleteButtonText="Leave" | ||
entityType="organization" | ||
entityName="your organization" | ||
onClose={() => setShowLeaveModal(false)} | ||
onSubmit={handleLeaveOrganization} | ||
additionalDetails="You will lose access to all organization data and resources." | ||
/> | ||
)} | ||
|
||
<Button | ||
className="w-min" | ||
onClick={() => setShowLeaveModal(true)} | ||
disabled={isMutating} | ||
size="sm" | ||
variant="destructive" | ||
> | ||
Leave Organization | ||
</Button> | ||
</> | ||
); | ||
}; |
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