From d28da57c2cd15a945abc5f62c952264447f24004 Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Thu, 14 Nov 2024 09:40:28 -0800 Subject: [PATCH 1/2] 24295 - Freeze all corporations when synchronizing to COLIN --- colin-api/flags.json | 4 +- colin-api/src/colin_api/models/filing.py | 12 +++++- colin-api/src/colin_api/services/flags.py | 51 +++++++++++++++++++++++ 3 files changed, 64 insertions(+), 3 deletions(-) diff --git a/colin-api/flags.json b/colin-api/flags.json index c3d9f4e15..cab00d228 100644 --- a/colin-api/flags.json +++ b/colin-api/flags.json @@ -1,3 +1,5 @@ { - "flagValues": {} + "flagValues": { + "enable-bc-ccc-ulc": true + } } diff --git a/colin-api/src/colin_api/models/filing.py b/colin-api/src/colin_api/models/filing.py index f039d2e81..bb8d8e66b 100644 --- a/colin-api/src/colin_api/models/filing.py +++ b/colin-api/src/colin_api/models/filing.py @@ -45,6 +45,7 @@ ShareObject, # noqa: I001 ) # noqa: I001 from colin_api.resources.db import DB +from colin_api.services import flags from colin_api.utils import convert_to_json_date, convert_to_json_datetime, convert_to_pacific_time, convert_to_snake @@ -1358,8 +1359,15 @@ def add_filing(cls, con, filing: Filing) -> int: Business.TypeCodes.BCOMP_CONTINUE_IN.value, ]) - # Freeze BEN/CBEN entity - if (is_new_ben or is_new_cben or is_alteration_to_ben_or_cben): + # Freeze all entities except CP if 'enable-bc-ccc-ulc' flag is on else just freeze BEN + is_frozen_condition = ( + flags.is_on('enable-bc-ccc-ulc') and + business['business']['legalType'] != Business.TypeCodes.COOP.value + ) + + is_new_or_altered_ben = is_new_ben or is_new_cben or is_alteration_to_ben_or_cben + + if is_frozen_condition or is_new_or_altered_ben: Business.update_corp_frozen_type(cursor, corp_num, Business.CorpFrozenTypes.COMPANY_FROZEN.value) return filing.event_id diff --git a/colin-api/src/colin_api/services/flags.py b/colin-api/src/colin_api/services/flags.py index c2d0c7e85..a517addde 100644 --- a/colin-api/src/colin_api/services/flags.py +++ b/colin-api/src/colin_api/services/flags.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. """Manage the Feature Flags initialization, setup and service.""" +from flask import current_app from ldclient import get as ldclient_get, set_config as ldclient_set_config # noqa: I001 from ldclient.config import Config # noqa: I005 from ldclient.impl.integrations.files.file_data_source import _FileDataSource @@ -78,3 +79,53 @@ def init_app(self, app): client = ldclient_get() app.extensions['featureflags'] = client + + def teardown(self, exception): # pylint: disable=unused-argument; flask method signature + """Destroy all objects created by this extension.""" + client = current_app.extensions['featureflags'] + client.close() + + def _get_client(self): + try: + client = current_app.extensions['featureflags'] + except KeyError: + try: + self.init_app(current_app) + client = current_app.extensions['featureflags'] + except KeyError: + client = None + + return client + + @staticmethod + def _get_anonymous_user(): + return { + 'key': 'anonymous' + } + + def is_on(self, flag: str) -> bool: + """Assert that the flag is set for this user.""" + client = self._get_client() + + flag_user = self._get_anonymous_user() + + try: + flag_val = bool(client.variation(flag, flag_user, None)) + return flag_val + except Exception as err: # pylint: disable=broad-except; want to catch all errors + current_app.logger.error( + 'Unable to read flags: %s' % repr(err), exc_info=True) # pylint: disable=consider-using-f-string + return False + + def value(self, flag: str) -> bool: + """Retrieve the value of the (flag, user) tuple.""" + client = self._get_client() + + flag_user = self._get_anonymous_user() + + try: + return client.variation(flag, flag_user, None) + except Exception as err: # pylint: disable=broad-except; want to catch all errors + current_app.logger.error( + 'Unable to read flags: %s' % repr(err), exc_info=True) # pylint: disable=consider-using-f-string + return False From 76699e03878219a743e90b93c0cc2fd37e23e4ab Mon Sep 17 00:00:00 2001 From: ketaki-deodhar Date: Thu, 14 Nov 2024 10:46:46 -0800 Subject: [PATCH 2/2] 24295 - Fix linting issue --- colin-api/src/colin_api/models/filing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/colin-api/src/colin_api/models/filing.py b/colin-api/src/colin_api/models/filing.py index bb8d8e66b..ee8d24ef9 100644 --- a/colin-api/src/colin_api/models/filing.py +++ b/colin-api/src/colin_api/models/filing.py @@ -1361,7 +1361,7 @@ def add_filing(cls, con, filing: Filing) -> int: # Freeze all entities except CP if 'enable-bc-ccc-ulc' flag is on else just freeze BEN is_frozen_condition = ( - flags.is_on('enable-bc-ccc-ulc') and + flags.is_on('enable-bc-ccc-ulc') and business['business']['legalType'] != Business.TypeCodes.COOP.value )