-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuser_invites.py
More file actions
48 lines (40 loc) · 1.51 KB
/
user_invites.py
File metadata and controls
48 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from ..utils.pydantic_version import PYDANTIC_VERSION
if PYDANTIC_VERSION < (2, 0):
from pydantic import validate_arguments
else:
from pydantic.v1 import validate_arguments
from .base import (
BasePermitApi,
SimpleHttpClient,
)
from .context import ApiContextLevel, ApiKeyAccessLevel
from .models import (
ElementsUserInviteApprove,
UserRead,
)
class UserInvitesApi(BasePermitApi):
@property
def __user_invites(self) -> SimpleHttpClient:
return self._build_http_client(
f"/v2/facts/{self.config.api_context.project}/{self.config.api_context.environment}/user_invites"
)
@validate_arguments # type: ignore[operator]
async def approve(self, user_invite_id: str, approve_data: ElementsUserInviteApprove) -> UserRead:
"""
Approves a user invite.
Args:
user_invite_id: The ID of the user invite to approve.
approve_data: The approval data for the user invite.
Returns:
the approved user invite.
Raises:
PermitApiError: If the API returns an error HTTP status code.
PermitContextError: If the configured ApiContext does not match the required endpoint context.
"""
await self._ensure_access_level(ApiKeyAccessLevel.ENVIRONMENT_LEVEL_API_KEY)
await self._ensure_context(ApiContextLevel.ENVIRONMENT)
return await self.__user_invites.post(
f"/{user_invite_id}/approve",
model=UserRead,
json=approve_data,
)