Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

24295 - Freeze all corporations when synchronizing to COLIN #3076

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion colin-api/flags.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"flagValues": {}
"flagValues": {
"enable-bc-ccc-ulc": true
}
}
12 changes: 10 additions & 2 deletions colin-api/src/colin_api/models/filing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions colin-api/src/colin_api/services/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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