27
27
from auth_api .services .entity import Entity as EntityService
28
28
from auth_api .services .org import Org as OrgService
29
29
from auth_api .utils .enums import CorpType
30
+ from auth_api .utils .enums import NRNameStatus , NRStatus
30
31
from auth_api .utils .passcode import validate_passcode
31
32
from auth_api .utils .roles import ALL_ALLOWED_ROLES , CLIENT_AUTH_ROLES , STAFF
32
33
from .rest_service import RestService
@@ -182,7 +183,11 @@ def create_new_business_affiliation(org_id, business_identifier=None, # pylint:
182
183
nr_phone = nr_json .get ('applicants' ).get ('phoneNumber' )
183
184
nr_email = nr_json .get ('applicants' ).get ('emailAddress' )
184
185
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' ):
186
191
raise BusinessException (Error .NR_NOT_APPROVED , None )
187
192
188
193
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:
191
196
# Create an entity with the Name from NR if entity doesn't exist
192
197
if not entity :
193
198
# 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
+
196
205
entity = EntityService .save_entity ({
197
206
'businessIdentifier' : business_identifier ,
198
207
'name' : name ,
0 commit comments