MCPcopy
hub / github.com/Agenta-AI/agenta / invite_user_to_organization

Function invite_user_to_organization

api/oss/src/routers/organization_router.py:170–245  ·  view source on GitHub ↗

Assigns a role to a user in an organization. Args: org_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. Returns: bool:

(
    org_id: str,
    payload: List[InviteRequest],
    workspace_id: str,
    request: Request,
)

Source from the content-addressed store, hash-verified

168 operation_id="invite_user_to_workspace",
169)
170async def invite_user_to_organization(
171 org_id: str,
172 payload: List[InviteRequest],
173 workspace_id: str,
174 request: Request,
175):
176 """
177 Assigns a role to a user in an organization.
178
179 Args:
180 org_id (str): The ID of the organization.
181 payload (InviteRequest): The payload containing the organization id, user email, and role to assign.
182 workspace_id (str): The ID of the workspace.
183
184 Returns:
185 bool: True if the role was successfully assigned, False otherwise.
186
187 Raises:
188 HTTPException: If the user does not have permission to perform this action.
189 HTTPException: If there is an error assigning the role to the user.
190 """
191
192 if len(payload) != 1:
193 return JSONResponse(
194 status_code=400,
195 content={"detail": "Only one user can be invited at a time."},
196 )
197
198 if is_ee():
199 user_org_workspace_data = await get_user_org_and_workspace_id(
200 request.state.user_id
201 )
202 project = await db_manager_ee.get_project_by_workspace(workspace_id)
203 has_permission = await check_rbac_permission(
204 user_org_workspace_data=user_org_workspace_data,
205 project_id=str(project.id),
206 role=WorkspaceRole.WORKSPACE_ADMIN,
207 )
208 if not has_permission:
209 return JSONResponse(
210 status_code=403,
211 content={
212 "detail": "You do not have permission to perform this action. Please contact your Organization Owner"
213 },
214 )
215
216 owner = await db_manager.get_organization_owner(org_id)
217 owner_domain = owner.email.split("@")[-1].lower() if owner else ""
218 user_domain = payload[0].email.split("@")[-1].lower()
219 skip_meter = owner_domain != "agenta.ai" and user_domain == "agenta.ai"
220
221 if not skip_meter:
222 check, _, _ = await check_entitlements(
223 organization_id=request.state.organization_id,
224 key=Gauge.USERS,
225 delta=1,
226 )
227

Callers

nothing calls this directly

Calls 2

is_eeFunction · 0.90

Tested by

no test coverage detected