Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions api/ee/src/routers/organization_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ async def get_user_organization(
raise HTTPException(status_code=500, detail=str(e))


@router.get("/{org_id}/", operation_id="fetch_ee_organization_details")
@router.get("/{organization_id}/", operation_id="fetch_ee_organization_details")
async def fetch_organization_details(
org_id: str,
organization_id: str,
request: Request,
):
"""Get an organization's details.
Expand All @@ -70,7 +70,7 @@ async def fetch_organization_details(

try:
workspace_id = await db_manager_ee.get_default_workspace_id_from_organization(
organization_id=org_id
organization_id=organization_id
)

project_id = await db_manager.get_default_project_id_from_workspace(
Expand All @@ -96,14 +96,16 @@ async def fetch_organization_details(
user_org_workspace_data = await get_user_org_and_workspace_id(
request.state.user_id
)
has_permission = await check_user_org_access(user_org_workspace_data, org_id)
has_permission = await check_user_org_access(
user_org_workspace_data, organization_id
)
if not has_permission:
return JSONResponse(
status_code=403,
content={"detail": "You do not have access to this organization"},
)

organization = await get_organization_details(org_id)
organization = await get_organization_details(organization_id)

if membership.role == "viewer" or membership.is_demo:
if "default_workspace" in organization:
Expand All @@ -121,9 +123,9 @@ async def fetch_organization_details(
)


@router.put("/{org_id}/", operation_id="update_organization")
@router.put("/{organization_id}/", operation_id="update_organization")
async def update_organization(
org_id: str,
organization_id: str,
payload: OrganizationUpdate,
request: Request,
):
Expand All @@ -138,15 +140,15 @@ async def update_organization(
request.state.user_id
)
has_permission = await check_user_org_access(
user_org_workspace_data, org_id, check_owner=True
user_org_workspace_data, organization_id, check_owner=True
)
if not has_permission:
return JSONResponse(
{"detail": "You do not have permission to perform this action"},
status_code=403,
)

organization = await update_an_organization(org_id, payload)
organization = await update_an_organization(organization_id, payload)

return organization

Expand All @@ -158,12 +160,12 @@ async def update_organization(


@router.post(
"/{org_id}/workspaces/",
"/{organization_id}/workspaces/",
operation_id="create_workspace",
response_model=WorkspaceResponse,
)
async def create_workspace(
org_id: str,
organization_id: str,
payload: CreateWorkspace,
request: Request,
) -> WorkspaceResponse:
Expand All @@ -172,7 +174,7 @@ async def create_workspace(
request.state.user_id
)
has_permission = await check_user_org_access(
user_org_workspace_data, org_id, check_owner=True
user_org_workspace_data, organization_id, check_owner=True
)
if not has_permission:
return JSONResponse(
Expand All @@ -186,7 +188,7 @@ async def create_workspace(
status_code=400,
)
workspace = await workspace_manager.create_new_workspace(
payload, org_id, user_org_workspace_data["uid"]
payload, organization_id, user_org_workspace_data["uid"]
)
return workspace

Expand All @@ -198,12 +200,12 @@ async def create_workspace(


@router.put(
"/{org_id}/workspaces/{workspace_id}/",
"/{organization_id}/workspaces/{workspace_id}/",
operation_id="update_workspace",
response_model=WorkspaceResponse,
)
async def update_workspace(
org_id: str,
organization_id: str,
workspace_id: str,
payload: UpdateWorkspace,
request: Request,
Expand Down
6 changes: 3 additions & 3 deletions api/ee/src/routers/workspace_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def assign_role_to_user(
@router.delete("/{workspace_id}/roles/", operation_id="unassign_role_from_user")
async def unassign_role_from_user(
email: str,
org_id: str,
organization_id: str,
role: str,
workspace_id: str,
request: Request,
Expand All @@ -121,7 +121,7 @@ async def unassign_role_from_user(
Args:
workspace_id (str): The ID of the workspace.
email (str): The email of the user to remove the role from.
org_id (str): The ID of the organization.
organization_id (str): The ID of the organization.
role (str): The role to remove from the user.
request (Request): The FastAPI request object.

Expand Down Expand Up @@ -153,7 +153,7 @@ async def unassign_role_from_user(

payload = UserRole(
email=email,
organization_id=org_id,
organization_id=organization_id,
role=role,
)

Expand Down
4 changes: 3 additions & 1 deletion api/ee/src/services/db_manager_ee.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ async def get_organizations_by_list_ids(organization_ids: List) -> List[Organiza
"""

async with engine.core_session() as session:
organization_uuids = [uuid.UUID(org_id) for org_id in organization_ids]
organization_uuids = [
uuid.UUID(organization_id) for organization_id in organization_ids
]
query = select(OrganizationDB).where(OrganizationDB.id.in_(organization_uuids))
result = await session.execute(query)
organizations = result.scalars().all()
Expand Down
16 changes: 10 additions & 6 deletions api/ee/src/services/organization_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@


async def update_an_organization(
org_id: str, payload: OrganizationUpdate
organization_id: str, payload: OrganizationUpdate
) -> OrganizationDB:
org = await db_manager_ee.get_organization(org_id)
org = await db_manager_ee.get_organization(organization_id)
if org is not None:
await db_manager_ee.update_organization(str(org.id), payload)
return org
Expand Down Expand Up @@ -61,8 +61,12 @@ async def send_invitation_email(
project_param = quote(project_id, safe="")

invite_link = (
f"{env.AGENTA_WEB_URL}/auth?token={token_param}&email={email_param}"
f"&org_id={org_param}&workspace_id={workspace_param}&project_id={project_param}"
f"{env.AGENTA_WEB_URL}/auth"
f"?token={token_param}"
f"&email={email_param}"
f"&organization_id={org_param}"
f"&workspace_id={workspace_param}"
f"&project_id={project_param}"
)

html_content = html_template.format(
Expand Down Expand Up @@ -116,6 +120,6 @@ async def notify_org_admin_invitation(workspace: WorkspaceDB, user: UserDB) -> b
return True


async def get_organization_details(org_id: str) -> dict:
organization = await db_manager_ee.get_organization(org_id)
async def get_organization_details(organization_id: str) -> dict:
organization = await db_manager_ee.get_organization(organization_id)
return await db_manager_ee.get_org_details(organization)
12 changes: 6 additions & 6 deletions api/ee/src/services/workspace_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def get_all_workspace_permissions() -> List[Permission]:

async def invite_user_to_workspace(
payload: List[InviteRequest],
org_id: str,
organization_id: str,
project_id: str,
workspace_id: str,
user_uid: str,
Expand All @@ -138,7 +138,7 @@ async def invite_user_to_workspace(

Args:
user_uid (str): The user uid.
org_id (str): The ID of the organization that the workspace belongs to.
organization_id (str): The ID of the organization that the workspace belongs to.
project_id (str): The ID of the project that belongs to the workspace.
workspace_id (str): The ID of the workspace.
payload (InviteRequest): The payload containing the email address of the user to invite.
Expand All @@ -152,7 +152,7 @@ async def invite_user_to_workspace(

try:
workspace = await get_workspace(workspace_id)
organization = await db_manager_ee.get_organization(org_id)
organization = await db_manager_ee.get_organization(organization_id)
user_performing_action = await db_manager.get_user(user_uid)

for payload_invite in payload:
Expand Down Expand Up @@ -216,15 +216,15 @@ async def invite_user_to_workspace(
async def resend_user_workspace_invite(
payload: ReseendInviteRequest,
project_id: str,
org_id: str,
organization_id: str,
workspace_id: str,
user_uid: str,
) -> JSONResponse:
"""
Resend an invitation to a user to a workspace.

Args:
org_id (str): The ID of the organization that the workspace belongs to.
organization_id (str): The ID of the organization that the workspace belongs to.
project_id (str): The ID of the project.
workspace_id (str): The ID of the workspace.
payload (ReseendInviteRequest): The payload containing the email address of the user to invite.
Expand All @@ -238,7 +238,7 @@ async def resend_user_workspace_invite(

try:
workspace = await get_workspace(workspace_id)
organization = await db_manager_ee.get_organization(org_id)
organization = await db_manager_ee.get_organization(organization_id)
user_performing_action = await db_manager.get_user(user_uid)

# Check if the email address already has a valid, unused invitation for the workspace
Expand Down
36 changes: 20 additions & 16 deletions api/oss/src/routers/organization_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ async def list_organizations(


@router.get(
"/{org_id}/",
"/{organization_id}/",
operation_id="fetch_organization_details",
response_model=OrganizationDetails,
)
async def fetch_organization_details(
org_id: str,
organization_id: str,
request: Request,
):
"""Return the details of the organization."""
Expand All @@ -100,11 +100,15 @@ async def fetch_organization_details(
if not active_workspace:
return {}

organization_owner = await db_manager.get_organization_owner(organization_id=org_id)
organization_owner = await db_manager.get_organization_owner(
organization_id=organization_id
)
project_invitations = await db_manager.get_project_invitations(
project_id=request.state.project_id
)
organization_db = await db_manager.get_organization_by_id(organization_id=org_id)
organization_db = await db_manager.get_organization_by_id(
organization_id=organization_id
)

invited_members = [
{
Expand Down Expand Up @@ -164,11 +168,11 @@ async def fetch_organization_details(


@router.post(
"/{org_id}/workspaces/{workspace_id}/invite/",
"/{organization_id}/workspaces/{workspace_id}/invite/",
operation_id="invite_user_to_workspace",
)
async def invite_user_to_organization(
org_id: str,
organization_id: str,
payload: List[InviteRequest],
workspace_id: str,
request: Request,
Expand All @@ -177,7 +181,7 @@ async def invite_user_to_organization(
Assigns a role to a user in an organization.

Args:
org_id (str): The ID of the organization.
organization_id (str): The ID of the organization.
payload (InviteRequest): The payload containing the organization id, user email, and role to assign.
workspace_id (str): The ID of the workspace.

Expand Down Expand Up @@ -213,7 +217,7 @@ async def invite_user_to_organization(
},
)

owner = await db_manager.get_organization_owner(org_id)
owner = await db_manager.get_organization_owner(organization_id)
owner_domain = owner.email.split("@")[-1].lower() if owner else ""
user_domain = payload[0].email.split("@")[-1].lower()
skip_meter = owner_domain != "agenta.ai" and user_domain == "agenta.ai"
Expand All @@ -230,7 +234,7 @@ async def invite_user_to_organization(

invite_user = await workspace_manager.invite_user_to_workspace(
payload=payload,
org_id=org_id,
organization_id=organization_id,
project_id=str(project.id),
workspace_id=workspace_id,
user_uid=request.state.user_id,
Expand All @@ -246,11 +250,11 @@ async def invite_user_to_organization(


@router.post(
"/{org_id}/workspaces/{workspace_id}/invite/resend/",
"/{organization_id}/workspaces/{workspace_id}/invite/resend/",
operation_id="resend_invitation",
)
async def resend_user_invitation_to_organization(
org_id: str,
organization_id: str,
workspace_id: str,
payload: ResendInviteRequest,
request: Request,
Expand Down Expand Up @@ -287,7 +291,7 @@ async def resend_user_invitation_to_organization(
invite_user = await workspace_manager.resend_user_workspace_invite(
payload=payload,
project_id=request.state.project_id,
org_id=org_id,
organization_id=organization_id,
workspace_id=workspace_id,
user_uid=request.state.user_id,
)
Expand All @@ -302,11 +306,11 @@ async def resend_user_invitation_to_organization(


@router.post(
"/{org_id}/workspaces/{workspace_id}/invite/accept/",
"/{organization_id}/workspaces/{workspace_id}/invite/accept/",
operation_id="accept_invitation",
)
async def accept_organization_invitation(
org_id: str,
organization_id: str,
workspace_id: str,
project_id: str,
payload: InviteToken,
Expand All @@ -326,7 +330,7 @@ async def accept_organization_invitation(

if is_ee():
workspace = await workspace_manager.get_workspace(workspace_id)
organization = await db_manager_ee.get_organization(org_id)
organization = await db_manager_ee.get_organization(organization_id)
user = await db_manager.get_user(request.state.user_id)

accept_invitation = await workspace_manager.accept_workspace_invitation(
Expand All @@ -343,7 +347,7 @@ async def accept_organization_invitation(
else:
await organization_service.accept_organization_invitation(
token=payload.token,
organization_id=org_id,
organization_id=organization_id,
email=payload.email,
)
return JSONResponse({"message": "Added user to workspace"}, status_code=200)
Loading