Skip to content
Open
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
39 changes: 39 additions & 0 deletions permit/api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def __role_assignments(self) -> SimpleHttpClient:
)
)

@property
def __user_invites(self) -> SimpleHttpClient:
return self._build_http_client(
"/v2/facts/{proj_id}/{env_id}/user_invites".format(
proj_id=self.config.api_context.project,
env_id=self.config.api_context.environment,
)
)

@required_permissions(ApiKeyAccessLevel.ENVIRONMENT_LEVEL_API_KEY)
@required_context(ApiContextLevel.ENVIRONMENT)
@validate_arguments
Expand Down Expand Up @@ -284,3 +293,33 @@ async def get_assigned_roles(
model=List[RoleAssignmentRead],
params=params,
)

@required_permissions(ApiKeyAccessLevel.ENVIRONMENT_LEVEL_API_KEY)
@required_context(ApiContextLevel.ENVIRONMENT)
@validate_arguments
async def approve(
self,
user_key: str,
email: str,
invite_code: str,
attributes: Optional[dict] = None,
) -> UserRead:
"""
Approves a user.

Args:
email: The email address of the user.
invite_code: The invite code of the user.

Returns:
the approved new created user object.

Raises:
PermitApiError: If the API returns an error HTTP status code.
PermitContextError: If the configured ApiContext does not match the required endpoint context.
"""
return await self.__user_invites.post(
f"/{invite_code}/approve",
model=UserRead,
json={"email": email, "key": user_key, "attributes": attributes or None},
)