Skip to content

Commit e219a17

Browse files
committed
rest-api/context: add user_id
Change-Id: I75da234776beb8f1194d5a74506b723ecc651e46 JIRA-Ref: CMK-28547
1 parent 806b585 commit e219a17

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

cmk/gui/openapi/framework/_context.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,17 @@ class ApiContext:
132132
config: ApiConfig
133133
version: APIVersion
134134
etag: ApiETagHandler
135+
user_id: UserId | None
135136
token: AuthToken | None
136137

137138
@classmethod
138139
def new(
139-
cls, config: Config, version: APIVersion, etag_if_match: ETags, token: AuthToken | None
140+
cls,
141+
config: Config,
142+
version: APIVersion,
143+
etag_if_match: ETags,
144+
user_id: UserId | None,
145+
token: AuthToken | None,
140146
) -> Self:
141147
return cls(
142148
config=ApiConfig.from_config(config),
@@ -145,5 +151,6 @@ def new(
145151
enabled=config.rest_api_etag_locking,
146152
if_match=etag_if_match,
147153
),
154+
user_id=user_id,
148155
token=token,
149156
)

cmk/gui/wsgi/applications/rest_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def _handle_request(
229229
config=active_config,
230230
version=self.requested_version,
231231
etag_if_match=request.if_match,
232+
user_id=session.session.user.id,
232233
token=token,
233234
)
234235

tests/unit/cmk/gui/openapi/framework/test_endpoint_model.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ def _api_context() -> ApiContext:
270270
config=Config(),
271271
version=APIVersion.UNSTABLE,
272272
etag_if_match=ETags(),
273+
user_id=None,
273274
token=None,
274275
)
275276

tests/unit/cmk/gui/openapi/framework/test_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def _api_context() -> ApiContext:
184184
config=Config(),
185185
version=APIVersion.UNSTABLE,
186186
etag_if_match=ETags(),
187+
user_id=None,
187188
token=None,
188189
)
189190

0 commit comments

Comments
 (0)