From 0b9f24bfb64e10c03f2e7a2a11c36e38f0297b82 Mon Sep 17 00:00:00 2001 From: EasonPan Date: Tue, 28 May 2024 13:22:48 -0700 Subject: [PATCH] 21417 refactor to put group admin endpoints under one folder (#2719) * create admin module and move 3 files into it * create bp_admin Blueprint, create route using bp_admin * add admin path to EndpointEnum and change urls * register new bp_admin to v2 init * update import pathes and tests * clean up commented code * fix code format * change EndpointEnum name for admin to match the existing pattern --- .../src/legal_api/resources/constants.py | 1 + .../src/legal_api/resources/v2/__init__.py | 8 ++----- .../legal_api/resources/v2/admin/__init__.py | 24 +++++++++++++++++++ .../v2/{ => admin}/administrative_bn.py | 9 ++++--- .../src/legal_api/resources/v2/admin/bp.py | 24 +++++++++++++++++++ .../resources/v2/{ => admin}/configuration.py | 9 ++++--- .../resources/v2/{ => admin}/dissolution.py | 7 +++--- .../legal_api/resources/v2/request_tracker.py | 2 +- .../resources/v2/test_administrative_bn.py | 2 +- 9 files changed, 64 insertions(+), 22 deletions(-) create mode 100644 legal-api/src/legal_api/resources/v2/admin/__init__.py rename legal-api/src/legal_api/resources/v2/{ => admin}/administrative_bn.py (92%) create mode 100644 legal-api/src/legal_api/resources/v2/admin/bp.py rename legal-api/src/legal_api/resources/v2/{ => admin}/configuration.py (96%) rename legal-api/src/legal_api/resources/v2/{ => admin}/dissolution.py (87%) diff --git a/legal-api/src/legal_api/resources/constants.py b/legal-api/src/legal_api/resources/constants.py index 65574f4bc9..f1a584d2ac 100644 --- a/legal-api/src/legal_api/resources/constants.py +++ b/legal-api/src/legal_api/resources/constants.py @@ -25,6 +25,7 @@ class EndpointEnum(str, Enum): API = '/api' BUSINESSES_V2 = '/api/v2/businesses' DEFAULT_API = API_V1 + ADMIN_V2 = '/api/v2/admin' class EndpointVersionEnum(str, Enum): diff --git a/legal-api/src/legal_api/resources/v2/__init__.py b/legal-api/src/legal_api/resources/v2/__init__.py index 3f9a6f1387..2dc1507b53 100644 --- a/legal-api/src/legal_api/resources/v2/__init__.py +++ b/legal-api/src/legal_api/resources/v2/__init__.py @@ -16,11 +16,9 @@ from flask import Flask -from .administrative_bn import bp as administrative_bn_bp +from .admin import bp_admin as admin_bp from .business import bp as businesses_bp from .business.business_digital_credentials import bp_dc as digital_credentials_bp -from .configuration import bp as configuration_bp -from .dissolution import bp as dissolution_bp from .document_signature import bp as document_signature_bp from .internal_services import bp as internal_bp from .meta import bp as meta_bp @@ -44,16 +42,14 @@ def init_app(self, app): self.app = app self.app.register_blueprint(meta_bp) - self.app.register_blueprint(administrative_bn_bp) + self.app.register_blueprint(admin_bp) self.app.register_blueprint(businesses_bp) self.app.register_blueprint(digital_credentials_bp) - self.app.register_blueprint(dissolution_bp) self.app.register_blueprint(document_signature_bp) self.app.register_blueprint(namerequest_bp) self.app.register_blueprint(naics_bp) self.app.register_blueprint(request_tracker_bp) self.app.register_blueprint(internal_bp) - self.app.register_blueprint(configuration_bp) v2_endpoint = V2Endpoint() diff --git a/legal-api/src/legal_api/resources/v2/admin/__init__.py b/legal-api/src/legal_api/resources/v2/admin/__init__.py new file mode 100644 index 0000000000..5eb06c4ab3 --- /dev/null +++ b/legal-api/src/legal_api/resources/v2/admin/__init__.py @@ -0,0 +1,24 @@ +# Copyright © 2021 Province of British Columbia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""The Admin End-Points. + +Provides all admin services. +""" +from .administrative_bn import create_bn_request +from .bp import bp_admin +from .configuration import get_configurations, update_configurations +from .dissolution import get_statistics + + +__all__ = ('bp_admin',) diff --git a/legal-api/src/legal_api/resources/v2/administrative_bn.py b/legal-api/src/legal_api/resources/v2/admin/administrative_bn.py similarity index 92% rename from legal-api/src/legal_api/resources/v2/administrative_bn.py rename to legal-api/src/legal_api/resources/v2/admin/administrative_bn.py index c0c594f6c1..537ba753b6 100644 --- a/legal-api/src/legal_api/resources/v2/administrative_bn.py +++ b/legal-api/src/legal_api/resources/v2/admin/administrative_bn.py @@ -15,7 +15,7 @@ import uuid from http import HTTPStatus -from flask import Blueprint, current_app +from flask import current_app from flask_cors import cross_origin from sentry_sdk import capture_message @@ -24,12 +24,11 @@ from legal_api.utils.auth import jwt from legal_api.utils.datetime import datetime +from .bp import bp_admin -bp = Blueprint('ADMINISTRATIVE_BN', __name__, url_prefix='/api/v2/admin/bn') - -@bp.route('', methods=['POST']) -@bp.route('/', methods=['POST']) +@bp_admin.route('bn/', methods=['POST']) +@bp_admin.route('bn//', methods=['POST']) @cross_origin(origin='*') @jwt.has_one_of_roles([UserRoles.admin_edit, UserRoles.bn_edit]) def create_bn_request(identifier: str, business_number: str = None): diff --git a/legal-api/src/legal_api/resources/v2/admin/bp.py b/legal-api/src/legal_api/resources/v2/admin/bp.py new file mode 100644 index 0000000000..85a5ebb378 --- /dev/null +++ b/legal-api/src/legal_api/resources/v2/admin/bp.py @@ -0,0 +1,24 @@ +# Copyright © 2021 Province of British Columbia +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""The Admin End-Point Blueprint. + +Provides the mount point for all of the admin end-points. +""" + +from flask import Blueprint + +from legal_api.resources.constants import EndpointEnum + + +bp_admin = Blueprint('ADMIN_V2', __name__, url_prefix=EndpointEnum.ADMIN_V2) diff --git a/legal-api/src/legal_api/resources/v2/configuration.py b/legal-api/src/legal_api/resources/v2/admin/configuration.py similarity index 96% rename from legal-api/src/legal_api/resources/v2/configuration.py rename to legal-api/src/legal_api/resources/v2/admin/configuration.py index 62c27c0269..cf25c92d8a 100644 --- a/legal-api/src/legal_api/resources/v2/configuration.py +++ b/legal-api/src/legal_api/resources/v2/admin/configuration.py @@ -14,18 +14,17 @@ """API endpoints for managing Configuration resource.""" from http import HTTPStatus -from flask import Blueprint, jsonify, request +from flask import jsonify, request from flask_cors import cross_origin from sqlalchemy import any_ from legal_api.models import Configuration, UserRoles, db from legal_api.utils.auth import jwt +from .bp import bp_admin -bp = Blueprint('CONFIGURATION', __name__, url_prefix='/api/v2/admin/configurations') - -@bp.route('', methods=['GET']) +@bp_admin.route('/configurations', methods=['GET']) @cross_origin(origin='*') @jwt.has_one_of_roles([UserRoles.staff]) def get_configurations(): @@ -38,7 +37,7 @@ def get_configurations(): }), HTTPStatus.OK -@bp.route('', methods=['PUT']) +@bp_admin.route('/configurations', methods=['PUT']) @cross_origin(origin='*') @jwt.has_one_of_roles([UserRoles.staff]) def update_configurations(): diff --git a/legal-api/src/legal_api/resources/v2/dissolution.py b/legal-api/src/legal_api/resources/v2/admin/dissolution.py similarity index 87% rename from legal-api/src/legal_api/resources/v2/dissolution.py rename to legal-api/src/legal_api/resources/v2/admin/dissolution.py index 2612c5cd0f..57e5165b15 100644 --- a/legal-api/src/legal_api/resources/v2/dissolution.py +++ b/legal-api/src/legal_api/resources/v2/admin/dissolution.py @@ -14,18 +14,17 @@ """API endpoints for managing Involuntary Dissolution resources.""" from http import HTTPStatus -from flask import Blueprint, jsonify +from flask import jsonify from flask_cors import cross_origin from legal_api.models import UserRoles from legal_api.services import InvoluntaryDissolutionService from legal_api.utils.auth import jwt +from .bp import bp_admin -bp = Blueprint('INVOLUNTARY_DISSOLUTION', __name__, url_prefix='/api/v2/admin/dissolutions') - -@bp.route('/statistics', methods=['GET']) +@bp_admin.route('/dissolutions/statistics', methods=['GET']) @cross_origin(origin='*') @jwt.has_one_of_roles([UserRoles.staff]) def get_statistics(): diff --git a/legal-api/src/legal_api/resources/v2/request_tracker.py b/legal-api/src/legal_api/resources/v2/request_tracker.py index 05202a527e..d64a2c4569 100644 --- a/legal-api/src/legal_api/resources/v2/request_tracker.py +++ b/legal-api/src/legal_api/resources/v2/request_tracker.py @@ -19,7 +19,7 @@ from flask_cors import cross_origin from legal_api.models import Business, RequestTracker, UserRoles -from legal_api.resources.v2.administrative_bn import publish_entity_event +from legal_api.resources.v2.admin.administrative_bn import publish_entity_event from legal_api.utils.auth import jwt diff --git a/legal-api/tests/unit/resources/v2/test_administrative_bn.py b/legal-api/tests/unit/resources/v2/test_administrative_bn.py index 26842aa1cf..b58ff1c81e 100644 --- a/legal-api/tests/unit/resources/v2/test_administrative_bn.py +++ b/legal-api/tests/unit/resources/v2/test_administrative_bn.py @@ -21,7 +21,7 @@ from unittest.mock import patch from legal_api.models import Business, UserRoles -from legal_api.resources.v2 import administrative_bn +from legal_api.resources.v2.admin import administrative_bn from tests.unit.models import factory_business from tests.unit.services.utils import create_header