-
Notifications
You must be signed in to change notification settings - Fork 70
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
15603 - Initial changes for adding in displayName for legalName changes (SP/GP) #2690
Changes from all commits
933643b
4fcda76
bd05625
06671dd
5e329e6
08f2f69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,5 +33,3 @@ | |
from .user import User | ||
from .user_settings import UserSettings | ||
from .flags import Flags | ||
|
||
flags = Flags() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
from auth_api.models.membership import Membership as MembershipModel | ||
from auth_api.schemas import AffiliationSchema | ||
from auth_api.services.entity import Entity as EntityService | ||
from auth_api.services.flags import flags | ||
from auth_api.services.org import Org as OrgService | ||
from auth_api.services.user import User as UserService | ||
from auth_api.utils.enums import ActivityAction, CorpType, NRActionCodes, NRNameStatus, NRStatus | ||
|
@@ -392,12 +393,23 @@ def fix_stale_affiliations(org_id: int, entity_details: Dict, environment: str = | |
|
||
current_app.logger.debug('>fix_stale_affiliations') | ||
|
||
@staticmethod | ||
def _affiliation_details_url(affiliation: AffiliationModel) -> str: | ||
"""Determine url to call for affiliation details.""" | ||
# only have LEAR and NAMEX affiliations | ||
if affiliation.entity.corp_type_code == CorpType.NR.value: | ||
return current_app.config.get('NAMEX_AFFILIATION_DETAILS_URL') | ||
# Temporary until legal names is implemented. | ||
if flags.is_on('enable-alternate-names-mbr', default=False): | ||
return current_app.config.get('LEAR_ALTERNATE_AFFILIATION_DETAILS_URL') | ||
return current_app.config.get('LEAR_AFFILIATION_DETAILS_URL') | ||
|
||
@staticmethod | ||
async def get_affiliation_details(affiliations: List[AffiliationModel]) -> List: | ||
"""Return affiliation details by calling the source api.""" | ||
url_identifiers = {} # i.e. turns into { url: [identifiers...] } | ||
for affiliation in affiliations: | ||
url = affiliation.affiliation_details_url | ||
url = Affiliation._affiliation_details_url(affiliation) | ||
url_identifiers.setdefault(url, [affiliation.entity.business_identifier])\ | ||
.append(affiliation.entity.business_identifier) | ||
|
||
|
@@ -428,8 +440,7 @@ def sort_key(item): | |
raise ServiceUnavailableException('Failed to get affiliation details') from err | ||
|
||
@staticmethod | ||
def _combine_affiliation_details(details): | ||
"""Parse affiliation details responses and combine draft entities with NRs if applicable.""" | ||
def _group_details(details): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to make this easier to deal with |
||
name_requests = {} | ||
businesses = [] | ||
drafts = [] | ||
|
@@ -450,17 +461,24 @@ def _combine_affiliation_details(details): | |
drafts = [ | ||
{'draftType': CorpType.RTMP.value if draft['legalType'] in draft_reg_types | ||
else CorpType.TMP.value, **draft} for draft in data[drafts_key]] | ||
return name_requests, businesses, drafts | ||
|
||
@staticmethod | ||
def _update_draft_type_for_amalgamation_nr(business): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to make this easier to deal with |
||
if business.get('draftType', None) \ | ||
and business['nameRequest']['request_action_cd'] == NRActionCodes.AMALGAMATE.value: | ||
business['draftType'] = CorpType.ATMP.value | ||
return business | ||
|
||
@staticmethod | ||
def _combine_nrs(name_requests, businesses, drafts): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to make this easier to deal with |
||
# combine NRs | ||
for business in drafts + businesses: | ||
# Only drafts have nrNumber coming back from legal-api. | ||
if 'nrNumber' in business and (nr_num := business['nrNumber']): | ||
if business['nrNumber'] in name_requests: | ||
business['nameRequest'] = name_requests[nr_num]['nameRequest'] | ||
# Update the draft type if the draft NR request is for amalgamation | ||
if business.get('draftType', None) \ | ||
and business['nameRequest']['request_action_cd'] == NRActionCodes.AMALGAMATE.value: | ||
business['draftType'] = CorpType.ATMP.value | ||
business = Affiliation._update_draft_type_for_amalgamation_nr(business) | ||
# Remove the business if the draft associated to the NR is consumed. | ||
if business['nameRequest']['stateCd'] == NRStatus.CONSUMED.value: | ||
drafts.remove(business) | ||
|
@@ -471,6 +489,12 @@ def _combine_affiliation_details(details): | |
|
||
return [name_request for nr_num, name_request in name_requests.items()] + drafts + businesses | ||
|
||
@staticmethod | ||
def _combine_affiliation_details(details): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. refactor to make this easier to deal with |
||
"""Parse affiliation details responses and combine draft entities with NRs if applicable.""" | ||
name_requests, businesses, drafts = Affiliation._group_details(details) | ||
return Affiliation._combine_nrs(name_requests, businesses, drafts) | ||
|
||
@staticmethod | ||
def _get_nr_details(nr_number: str): | ||
"""Return NR details by calling legal-api.""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright © 2019 Province of British Columbia | ||
# Copyright © 2022 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. | ||
|
@@ -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.""" | ||
import logging | ||
from flask import current_app | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LD configuration setup the same as PAY now. so they're consistent. It was never used in auth. |
||
from ldclient import get as ldclient_get, set_config as ldclient_set_config # noqa: I001 | ||
from ldclient.config import Config # noqa: I005 | ||
|
@@ -48,24 +49,18 @@ def init_app(self, app): | |
|
||
if self.sdk_key or app.env != 'production': | ||
|
||
if app.env == 'production': | ||
config = Config(sdk_key=self.sdk_key) | ||
else: | ||
if app.env == 'testing': | ||
factory = Files.new_data_source(paths=['flags.json'], auto_update=True) | ||
config = Config(sdk_key=self.sdk_key, | ||
update_processor_class=factory, | ||
send_events=False) | ||
else: | ||
config = Config(sdk_key=self.sdk_key) | ||
|
||
ldclient_set_config(config) | ||
client = ldclient_get() | ||
|
||
app.extensions['featureflags'] = client | ||
app.teardown_appcontext(self.teardown) | ||
|
||
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: | ||
|
@@ -75,6 +70,7 @@ def _get_client(self): | |
self.init_app(current_app) | ||
client = current_app.extensions['featureflags'] | ||
except KeyError: | ||
logging.warning("Couldn\'t retrieve launch darkly client from extensions.") | ||
client = None | ||
|
||
return client | ||
|
@@ -89,24 +85,33 @@ def _user_as_key(user: User): | |
.set('firstName', user.firstname)\ | ||
.set('lastName', user.lastname).build() | ||
|
||
def is_on(self, flag: str, user: User = None) -> bool: | ||
def is_on(self, flag: str, default: bool = False, user: User = None) -> bool: | ||
"""Assert that the flag is set for this user.""" | ||
client = self._get_client() | ||
|
||
if not client: | ||
return default | ||
|
||
if user: | ||
flag_user = self._user_as_key(user) | ||
else: | ||
flag_user = self._get_anonymous_user() | ||
|
||
return bool(client.variation(flag, flag_user, None)) | ||
return bool(client.variation(flag, flag_user, default)) | ||
|
||
def value(self, flag: str, user: User = None) -> bool: | ||
def value(self, flag: str, default=None, user: User = None): | ||
"""Retrieve the value of the (flag, user) tuple.""" | ||
client = self._get_client() | ||
|
||
if not client: | ||
return default | ||
|
||
if user: | ||
flag_user = self._user_as_key(user) | ||
else: | ||
flag_user = self._get_anonymous_user() | ||
|
||
return client.variation(flag, flag_user, None) | ||
return client.variation(flag, flag_user, default) | ||
|
||
|
||
flags = Flags() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,12 +48,24 @@ export const useBusinessStore = defineStore('business', () => { | |
return useOrgStore().currentOrganization | ||
}) | ||
|
||
function determineDisplayName (resp: AffiliationResponse): string { | ||
if (!LaunchDarklyService.getFlag(LDFlags.AlternateNamesMbr, false)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will remove this after we get rid of feature flag |
||
return resp.legalName | ||
} | ||
if ([CorpTypes.SOLE_PROP, CorpTypes.PARTNERSHIP].includes(resp.legalType)) { | ||
// Intentionally show blank, if the alternate name is not found. This is to avoid showing the legal name. | ||
return resp.alternateNames?.find(alt => alt.identifier === resp.identifier)?.operatingName | ||
} else { | ||
return resp.legalName | ||
} | ||
} | ||
|
||
/* Internal function to build the business object. */ | ||
function buildBusinessObject (resp: AffiliationResponse): Business { | ||
return { | ||
businessIdentifier: resp.identifier, | ||
...(resp.businessNumber && { businessNumber: resp.businessNumber }), | ||
...(resp.legalName && { name: resp.legalName }), | ||
...(resp.legalName && { name: determineDisplayName(resp) }), | ||
...(resp.contacts && { contacts: resp.contacts }), | ||
...((resp.draftType || resp.legalType) && { corpType: { code: resp.draftType || resp.legalType } }), | ||
...(resp.legalType && { corpSubType: { code: resp.legalType } }), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had to move this out of the model, because of circular deps, can't call model -> service, but service -> service is fine.