Skip to content
This repository has been archived by the owner on Sep 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1285 from interval/ctx-user-roles-teams
Browse files Browse the repository at this point in the history
Add role and teams to ctx.user value
  • Loading branch information
jacobmischka authored Jul 13, 2023
2 parents 14fe3f9 + 6080642 commit 94dec79
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/demos/shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async def handle_close_inner():
print("Closing...")
await interval.safely_close()
print("Closed!")
except Exception as err:
except Exception:
print("Failed closing gracefully", file=sys.stderr)
print("Closing forcibly")
await interval.immediately_close()
Expand Down
9 changes: 8 additions & 1 deletion src/interval_sdk/internal_rpc_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,14 @@ class IOResponseInputs(BaseModel):
transaction_id: str


ContextUserRole: TypeAlias = Literal["admin", "developer", "member"]


@dataclass
class ContextUser:
email: str
role: ContextUserRole
teams: list[str]
first_name: Optional[str] = None
last_name: Optional[str] = None

Expand All @@ -387,6 +392,8 @@ class ContextUserModel(BaseModel):
email: str
first_name: Optional[str] = None
last_name: Optional[str] = None
role: ContextUserRole
teams: list[str]


@dataclass
Expand Down Expand Up @@ -580,7 +587,7 @@ class OpenPageInputs(BaseModel):
client_id: Optional[str] = None
page: PageInfo
environment: ActionEnvironment
user: ContextUser
user: ContextUserModel
params: SerializableRecord
params_meta: Optional[Any] = None

Expand Down
2 changes: 1 addition & 1 deletion src/interval_sdk/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ async def send_loading_state(loading_state: LoadingState):
page_ctx = PageContext(
page_key=inputs.page_key,
logger=self._logger,
user=inputs.user,
user=ContextUser(**inputs.user.dict(by_alias=False)),
params=deserialize_dates(inputs.params),
environment=inputs.environment,
organization=self.organization,
Expand Down
10 changes: 8 additions & 2 deletions src/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ async def context(_, ctx_arg: ActionContext):
assert ctx_arg == ctx

return {
"user": f"{ctx.user.first_name} {ctx.user.last_name}",
"user": f"{ctx.user.first_name} {ctx.user.last_name} ({ctx.user.email})",
"role": ctx.user.role,
"teams": json.dumps(ctx.user.teams),
"message": ctx.params.get("message", None),
"environment": ctx.environment,
}
Expand All @@ -102,7 +104,11 @@ async def context(_, ctx_arg: ActionContext):
await transactions.run("context")
await page.goto(page.url + "?message=Hello")
await transactions.expect_success(
user="Test Runner", message="Hello", environment="development"
user="Test Runner ([email protected])",
message="Hello",
environment="development",
role="admin",
teams="[]",
)


Expand Down

0 comments on commit 94dec79

Please sign in to comment.