Skip to content

Commit e9d6eb4

Browse files
authored
29535 - Add in Original-Username and Original-Sub to pay-api calls for activity log (#3513)
1 parent 616ec81 commit e9d6eb4

File tree

3 files changed

+41
-4
lines changed

3 files changed

+41
-4
lines changed

auth-api/src/auth_api/services/org.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,21 +263,28 @@ def _create_payment_settings(
263263
pay_request = Org._build_payment_request(org_model, payment_info, payment_method, mailing_address, **kwargs)
264264
error_code = None
265265
token = RestService.get_service_account_token()
266+
user_from_context: UserContext = kwargs["user_context"]
267+
268+
additional_headers = {
269+
"Original-Username": user_from_context.user_name or "",
270+
"Original-Sub": str(user_from_context.sub or ""),
271+
}
266272

267273
if is_new_org:
268274
response = RestService.post(
269275
endpoint=f"{pay_url}/accounts",
270276
data=pay_request,
271277
token=token,
272278
raise_for_status=True,
279+
additional_headers=additional_headers,
273280
)
274281
else:
275-
response = RestService.get(endpoint=f"{pay_url}/accounts/{org_model.id}", token=token)
276282
response = RestService.put(
277283
endpoint=f"{pay_url}/accounts/{org_model.id}",
278284
data=pay_request,
279285
token=token,
280286
raise_for_status=True,
287+
additional_headers=additional_headers,
281288
)
282289

283290
match response.status_code:

auth-api/src/auth_api/services/rest_service.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,22 @@ def put( # pylint: disable=too-many-positional-arguments,too-many-arguments
134134
content_type: ContentType = ContentType.JSON,
135135
data=None,
136136
raise_for_status: bool = True,
137+
additional_headers: dict = None,
138+
generate_token: bool = True,
137139
):
138-
"""POST service."""
139-
current_app.logger.debug("<post")
140-
return RestService._invoke("put", endpoint, token, auth_header_type, content_type, data, raise_for_status)
140+
"""PUT service."""
141+
current_app.logger.debug("<put")
142+
return RestService._invoke(
143+
"put",
144+
endpoint,
145+
token,
146+
auth_header_type,
147+
content_type,
148+
data,
149+
raise_for_status,
150+
additional_headers,
151+
generate_token,
152+
)
141153

142154
@staticmethod
143155
def patch( # pylint: disable=too-many-positional-arguments,too-many-arguments

auth-api/tests/unit/services/test_org.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,12 @@ def test_create_org_assert_pay_request_is_correct(
157157
}
158158
assert expected_data == actual_data
159159

160+
call_kwargs = mock_post.call_args.kwargs
161+
assert "additional_headers" in call_kwargs
162+
additional_headers = call_kwargs["additional_headers"]
163+
assert "Original-Username" in additional_headers
164+
assert "Original-Sub" in additional_headers
165+
160166

161167
@mock.patch("auth_api.services.affiliation_invitation.RestService.get_service_account_token", mock_token)
162168
def test_pay_request_is_correct_with_branch_name(session, keycloak_mock, monkeypatch): # pylint:disable=unused-argument
@@ -225,6 +231,12 @@ def test_update_basic_org_assert_pay_request_is_correct(
225231
}
226232
assert expected_data == actual_data, "updating to Online Banking works."
227233

234+
call_kwargs = mock_put.call_args.kwargs
235+
assert "additional_headers" in call_kwargs
236+
additional_headers = call_kwargs["additional_headers"]
237+
assert "Original-Username" in additional_headers
238+
assert "Original-Sub" in additional_headers
239+
228240
new_payment_method = TestPaymentMethodInfo.get_payment_method_input(PaymentMethod.DIRECT_PAY)
229241
patch_token_info(TestJwtClaims.public_user_role, monkeypatch)
230242
org = OrgService.update_org(org, new_payment_method)
@@ -240,6 +252,12 @@ def test_update_basic_org_assert_pay_request_is_correct(
240252
}
241253
assert expected_data == actual_data, "updating bank to Credit Card works."
242254

255+
call_kwargs = mock_put.call_args.kwargs
256+
assert "additional_headers" in call_kwargs
257+
additional_headers = call_kwargs["additional_headers"]
258+
assert "Original-Username" in additional_headers
259+
assert "Original-Sub" in additional_headers
260+
243261

244262
@mock.patch("auth_api.services.affiliation_invitation.RestService.get_service_account_token", mock_token)
245263
def test_create_basic_org_assert_pay_request_is_correct_online_banking(

0 commit comments

Comments
 (0)