From d5ed8b20f224ab21d2f7154f509c4700fba22443 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D0=B5=D0=BC?= Date: Fri, 25 Aug 2023 10:22:14 +0300 Subject: [PATCH] changes get user id to get party id instead (#37) --- apps/capi/src/capi_handler_customers.erl | 9 ++++----- apps/capi/src/capi_handler_invoice_templates.erl | 3 +-- apps/capi/src/capi_handler_invoices.erl | 5 +---- apps/capi/src/capi_handler_payouts.erl | 3 +-- apps/capi/src/capi_handler_webhooks.erl | 3 +-- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/apps/capi/src/capi_handler_customers.erl b/apps/capi/src/capi_handler_customers.erl index e4a1475..aa1e85f 100644 --- a/apps/capi/src/capi_handler_customers.erl +++ b/apps/capi/src/capi_handler_customers.erl @@ -23,8 +23,7 @@ ) -> {ok, capi_handler:request_state()} | {error, noimpl}. prepare('CreateCustomer' = OperationID, Req, Context) -> CustomerParams = maps:get('CustomerParams', Req), - UserID = capi_handler_utils:get_user_id(Context), - PartyID = maps:get(<<"partyID">>, CustomerParams, UserID), + PartyID = maps:get(<<"partyID">>, CustomerParams, capi_handler_utils:get_party_id(Context)), ShopID = maps:get(<<"shopID">>, CustomerParams), Authorize = fun() -> Prototypes = [{operation, #{id => OperationID, party => PartyID, shop => ShopID}}], @@ -305,7 +304,7 @@ encode_customer_metadata(Meta) -> generate_binding_ids(OperationID, CustomerBindingParams, Context = #{woody_context := WoodyContext}) -> ExternalID = maps:get(<<"externalID">>, CustomerBindingParams, undefined), - UserID = capi_handler_utils:get_user_id(Context), + PartyID = capi_handler_utils:get_party_id(Context), PaymentResource = maps:get(<<"paymentResource">>, CustomerBindingParams), PaymentToolToken = maps:get(<<"paymentToolToken">>, PaymentResource), @@ -328,12 +327,12 @@ generate_binding_ids(OperationID, CustomerBindingParams, Context = #{woody_conte OperationIDBin = erlang:atom_to_binary(OperationID), CustomerBindingID = capi_bender:gen_snowflake( - {<>, UserID, ExternalID}, + {<>, PartyID, ExternalID}, Identity, WoodyContext ), RecPaymentToolID = capi_bender:gen_snowflake( - {<>, UserID, ExternalID}, + {<>, PartyID, ExternalID}, Identity, WoodyContext ), diff --git a/apps/capi/src/capi_handler_invoice_templates.erl b/apps/capi/src/capi_handler_invoice_templates.erl index 67d121f..db94141 100644 --- a/apps/capi/src/capi_handler_invoice_templates.erl +++ b/apps/capi/src/capi_handler_invoice_templates.erl @@ -17,8 +17,7 @@ ) -> {ok, capi_handler:request_state()} | {error, noimpl}. prepare('CreateInvoiceTemplate' = OperationID, Req, Context) -> InvoiceTemplateParams = maps:get('InvoiceTemplateCreateParams', Req), - UserID = capi_handler_utils:get_user_id(Context), - PartyID = maps:get(<<"partyID">>, InvoiceTemplateParams, UserID), + PartyID = maps:get(<<"partyID">>, InvoiceTemplateParams, capi_handler_utils:get_party_id(Context)), Authorize = fun() -> ShopID = maps:get(<<"shopID">>, InvoiceTemplateParams), Prototypes = [{operation, #{party => PartyID, shop => ShopID, id => OperationID}}], diff --git a/apps/capi/src/capi_handler_invoices.erl b/apps/capi/src/capi_handler_invoices.erl index 0669989..127ba2f 100644 --- a/apps/capi/src/capi_handler_invoices.erl +++ b/apps/capi/src/capi_handler_invoices.erl @@ -17,10 +17,7 @@ ) -> {ok, capi_handler:request_state()} | {error, noimpl}. prepare('CreateInvoice' = OperationID, Req, Context) -> InvoiceParams = maps:get('InvoiceParams', Req), - UserID = capi_handler_utils:get_user_id(Context), - %% Now hellgate checks user's possibility use party. - %% After integration with bouncer, we have to remove validation in hellgate. - PartyID = maps:get(<<"partyID">>, InvoiceParams, UserID), + PartyID = maps:get(<<"partyID">>, InvoiceParams, capi_handler_utils:get_party_id(Context)), Authorize = fun() -> ShopID = maps:get(<<"shopID">>, InvoiceParams), Prototypes = [ diff --git a/apps/capi/src/capi_handler_payouts.erl b/apps/capi/src/capi_handler_payouts.erl index 04eb3d4..32f6bbf 100644 --- a/apps/capi/src/capi_handler_payouts.erl +++ b/apps/capi/src/capi_handler_payouts.erl @@ -46,8 +46,7 @@ prepare(OperationID = 'GetPayout', Req, Context) -> {ok, #{authorize => Authorize, process => Process}}; prepare(OperationID = 'CreatePayout', Req, Context) -> PayoutParams = maps:get('PayoutParams', Req), - UserID = capi_handler_utils:get_user_id(Context), - PartyID = maps:get(<<"partyID">>, PayoutParams, UserID), + PartyID = maps:get(<<"partyID">>, PayoutParams, capi_handler_utils:get_party_id(Context)), OperationContext = #{ id => OperationID, party => PartyID, diff --git a/apps/capi/src/capi_handler_webhooks.erl b/apps/capi/src/capi_handler_webhooks.erl index 2ffe8ef..c0d7f30 100644 --- a/apps/capi/src/capi_handler_webhooks.erl +++ b/apps/capi/src/capi_handler_webhooks.erl @@ -16,8 +16,7 @@ ) -> {ok, capi_handler:request_state()} | {error, noimpl}. prepare('CreateWebhook' = OperationID, Req, Context) -> Params = maps:get('Webhook', Req), - UserID = capi_handler_utils:get_user_id(Context), - PartyID = maps:get(<<"partyID">>, Params, UserID), + PartyID = maps:get(<<"partyID">>, Params, capi_handler_utils:get_party_id(Context)), Authorize = fun() -> Prototypes = [{operation, #{party => PartyID, id => OperationID}}], Resolution = capi_auth:authorize_operation(Prototypes, Context),