Skip to content

Commit e9884bf

Browse files
authored
Merge pull request #751 from sumesh-aot/fix_nr_navigation
3947: Changes for affiliation and name for CONDITIONAL name requests
2 parents e60b492 + 23b7106 commit e9884bf

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

auth-api/src/auth_api/services/affiliation.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from auth_api.services.entity import Entity as EntityService
2828
from auth_api.services.org import Org as OrgService
2929
from auth_api.utils.enums import CorpType
30+
from auth_api.utils.enums import NRNameStatus, NRStatus
3031
from auth_api.utils.passcode import validate_passcode
3132
from auth_api.utils.roles import ALL_ALLOWED_ROLES, CLIENT_AUTH_ROLES, STAFF
3233
from .rest_service import RestService
@@ -182,7 +183,11 @@ def create_new_business_affiliation(org_id, business_identifier=None, # pylint:
182183
nr_phone = nr_json.get('applicants').get('phoneNumber')
183184
nr_email = nr_json.get('applicants').get('emailAddress')
184185

185-
if status not in ('APPROVED', 'CONDITIONAL'):
186+
if status not in (NRStatus.APPROVED.value, NRStatus.CONDITIONAL.value):
187+
raise BusinessException(Error.NR_NOT_APPROVED, None)
188+
189+
# If consentFlag is not R, N or Null for a CONDITIONAL NR throw error
190+
if status == NRStatus.CONDITIONAL.value and nr_json.get('consentFlag', None) not in (None, 'R', 'N'):
186191
raise BusinessException(Error.NR_NOT_APPROVED, None)
187192

188193
if (phone and phone != nr_phone) or (email and email != nr_email):
@@ -191,8 +196,12 @@ def create_new_business_affiliation(org_id, business_identifier=None, # pylint:
191196
# Create an entity with the Name from NR if entity doesn't exist
192197
if not entity:
193198
# Filter the names from NR response and get the name which has status APPROVED as the name.
194-
name = next(
195-
(name.get('name') for name in nr_json.get('names') if name.get('state', None) == 'APPROVED'), None)
199+
# Filter the names from NR response and get the name which has status CONDITION as the name.
200+
nr_name_state = NRNameStatus.APPROVED.value if status == NRStatus.APPROVED.value \
201+
else NRNameStatus.CONDITION.value
202+
name = next((name.get('name') for name in nr_json.get('names') if
203+
name.get('state', None) == nr_name_state), None)
204+
196205
entity = EntityService.save_entity({
197206
'businessIdentifier': business_identifier,
198207
'name': name,

auth-api/src/auth_api/utils/enums.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,17 @@ class DocumentType(Enum):
8080

8181
TERMS_OF_USE = 'termsofuse'
8282
TERMS_OF_USE_DIRECTOR_SEARCH = 'termsofuse_directorsearch'
83+
84+
85+
class NRStatus(Enum):
86+
"""NR statuses."""
87+
88+
APPROVED = 'APPROVED'
89+
CONDITIONAL = 'CONDITIONAL'
90+
91+
92+
class NRNameStatus(Enum):
93+
"""NR name statuses."""
94+
95+
APPROVED = 'APPROVED'
96+
CONDITION = 'CONDITION'

0 commit comments

Comments
 (0)