diff --git a/api/src/pcapi/routes/pro/offerers.py b/api/src/pcapi/routes/pro/offerers.py index 781b31057c2..976f503e5f3 100644 --- a/api/src/pcapi/routes/pro/offerers.py +++ b/api/src/pcapi/routes/pro/offerers.py @@ -133,22 +133,6 @@ def get_offerer_members(offerer_id: int) -> offerers_serialize.GetOffererMembers ) -@private_api.route("/offerers//api_keys", methods=["POST"]) -@login_required -@spectree_serialize(response_model=offerers_serialize.GenerateOffererApiKeyResponse, api=blueprint.pro_private_schema) -def generate_api_key_route(offerer_id: int) -> offerers_serialize.GenerateOffererApiKeyResponse: - check_user_has_access_to_offerer(current_user, offerer_id) - offerer = offerers_models.Offerer.query.get_or_404(offerer_id) - try: - clear_key = api.generate_and_save_api_key(offerer.id) - except offerers_exceptions.ApiKeyCountMaxReached: - raise ApiErrors({"api_key_count_max": "Le nombre de clés maximal a été atteint"}) - except offerers_exceptions.ApiKeyPrefixGenerationError: - raise ApiErrors({"api_key": "Could not generate api key"}) - - return offerers_serialize.GenerateOffererApiKeyResponse(apiKey=clear_key) - - @private_api.route("/offerers/api_keys/", methods=["DELETE"]) @login_required @spectree_serialize(on_success_status=204, api=blueprint.pro_private_schema) diff --git a/api/tests/routes/pro/post_offerer_api_key_test.py b/api/tests/routes/pro/post_offerer_api_key_test.py deleted file mode 100644 index 13bc674a13a..00000000000 --- a/api/tests/routes/pro/post_offerer_api_key_test.py +++ /dev/null @@ -1,68 +0,0 @@ -import pytest - -from pcapi.core.bookings import factories as booking_factories -from pcapi.core.offerers.api import find_api_key -from pcapi.core.offerers.factories import ApiKeyFactory -from pcapi.core.offerers.factories import UserOffererFactory -from pcapi.core.offerers.models import ApiKey - - -@pytest.mark.usefixtures("db_session") -def test_api_key_journey(client): - booking = booking_factories.BookingFactory() - user_offerer = UserOffererFactory(offerer=booking.offerer) - client.with_session_auth(user_offerer.user.email) - - response = client.post(f"/offerers/{user_offerer.offerer.id}/api_keys") - - assert response.status_code == 200 - - saved_key = find_api_key(response.json["apiKey"]) - assert saved_key.offererId == user_offerer.offerer.id - - # test generated api key grants authentication on bookings API - response = client.get( - f"/v2/bookings/token/{booking.token.lower()}", - headers={"Authorization": f"""Bearer {response.json["apiKey"]}"""}, - ) - assert response.status_code == 200 - - # test user can delete the generated api key - response = client.delete(f"/offerers/api_keys/{saved_key.prefix}") - assert response.status_code == 204 - assert ApiKey.query.count() == 0 - - -@pytest.mark.usefixtures("db_session") -def test_maximal_api_key_reached(client): - user_offerer = UserOffererFactory() - for i in range(5): - ApiKeyFactory(prefix=f"prefix_{i}", offerer=user_offerer.offerer) - - client.with_session_auth(user_offerer.user.email) - response = client.post(f"/offerers/{user_offerer.offerer.id}/api_keys") - - assert response.status_code == 400 - assert response.json["api_key_count_max"] == "Le nombre de clés maximal a été atteint" - assert ApiKey.query.count() == 5 - - -@pytest.mark.usefixtures("db_session") -def test_delete_api_key_not_found(client): - user_offerer = UserOffererFactory() - - client.with_session_auth(user_offerer.user.email) - response = client.delete("/offerers/api_keys/wrong-prefix") - - assert response.status_code == 404 - - -@pytest.mark.usefixtures("db_session") -def test_delete_api_key_not_allowed(client): - user_offerer = UserOffererFactory() - api_key = ApiKeyFactory() - - client.with_session_auth(user_offerer.user.email) - response = client.delete(f"/offerers/api_keys/{api_key.prefix}") - - assert response.status_code == 404 # not 403, which would imply that the prefix exists diff --git a/pro/src/apiClient/v1/index.ts b/pro/src/apiClient/v1/index.ts index 1feeec9fae6..335bf8220ea 100644 --- a/pro/src/apiClient/v1/index.ts +++ b/pro/src/apiClient/v1/index.ts @@ -97,7 +97,6 @@ export type { FeatureResponseModel } from './models/FeatureResponseModel'; export type { FinanceBankAccountListResponseModel } from './models/FinanceBankAccountListResponseModel'; export type { FinanceBankAccountResponseModel } from './models/FinanceBankAccountResponseModel'; export { GenderEnum } from './models/GenderEnum'; -export type { GenerateOffererApiKeyResponse } from './models/GenerateOffererApiKeyResponse'; export type { GetCollectiveOfferCollectiveStockResponseModel } from './models/GetCollectiveOfferCollectiveStockResponseModel'; export type { GetCollectiveOfferManagingOffererResponseModel } from './models/GetCollectiveOfferManagingOffererResponseModel'; export type { GetCollectiveOfferProviderResponseModel } from './models/GetCollectiveOfferProviderResponseModel'; diff --git a/pro/src/apiClient/v1/models/GenerateOffererApiKeyResponse.ts b/pro/src/apiClient/v1/models/GenerateOffererApiKeyResponse.ts deleted file mode 100644 index 6fafa28a05c..00000000000 --- a/pro/src/apiClient/v1/models/GenerateOffererApiKeyResponse.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* generated using openapi-typescript-codegen -- do not edit */ -/* istanbul ignore file */ -/* tslint:disable */ -/* eslint-disable */ -export type GenerateOffererApiKeyResponse = { - apiKey: string; -}; - diff --git a/pro/src/apiClient/v1/services/DefaultService.ts b/pro/src/apiClient/v1/services/DefaultService.ts index 1503c5ae4df..d5ff80e0d75 100644 --- a/pro/src/apiClient/v1/services/DefaultService.ts +++ b/pro/src/apiClient/v1/services/DefaultService.ts @@ -36,7 +36,6 @@ import type { EducationalInstitutionsResponseModel } from '../models/Educational import type { EducationalRedactors } from '../models/EducationalRedactors'; import type { EventDatesInfos } from '../models/EventDatesInfos'; import type { FinanceBankAccountListResponseModel } from '../models/FinanceBankAccountListResponseModel'; -import type { GenerateOffererApiKeyResponse } from '../models/GenerateOffererApiKeyResponse'; import type { GetCollectiveOfferRequestResponseModel } from '../models/GetCollectiveOfferRequestResponseModel'; import type { GetCollectiveOfferResponseModel } from '../models/GetCollectiveOfferResponseModel'; import type { GetCollectiveOfferTemplateResponseModel } from '../models/GetCollectiveOfferTemplateResponseModel'; @@ -1412,27 +1411,6 @@ export class DefaultService { }, }); } - /** - * generate_api_key_route - * @param offererId - * @returns GenerateOffererApiKeyResponse OK - * @throws ApiError - */ - public generateApiKeyRoute( - offererId: number, - ): CancelablePromise { - return this.httpRequest.request({ - method: 'POST', - url: '/offerers/{offerer_id}/api_keys', - path: { - 'offerer_id': offererId, - }, - errors: { - 403: `Forbidden`, - 422: `Unprocessable Entity`, - }, - }); - } /** * get_offerer_bank_accounts_and_attached_venues * @param offererId