Skip to content

Commit

Permalink
21417 refactor to put group admin endpoints under one folder (bcgov#2719
Browse files Browse the repository at this point in the history
)

* 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
  • Loading branch information
eason-pan-bc authored May 28, 2024
1 parent cf6bd42 commit 0b9f24b
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 22 deletions.
1 change: 1 addition & 0 deletions legal-api/src/legal_api/resources/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions legal-api/src/legal_api/resources/v2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
24 changes: 24 additions & 0 deletions legal-api/src/legal_api/resources/v2/admin/__init__.py
Original file line number Diff line number Diff line change
@@ -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',)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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('<string:identifier>', methods=['POST'])
@bp.route('<string:identifier>/<string:business_number>', methods=['POST'])
@bp_admin.route('bn/<string:identifier>', methods=['POST'])
@bp_admin.route('bn/<string:identifier>/<string:business_number>', 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):
Expand Down
24 changes: 24 additions & 0 deletions legal-api/src/legal_api/resources/v2/admin/bp.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand All @@ -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():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion legal-api/src/legal_api/resources/v2/request_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b9f24b

Please sign in to comment.