diff --git a/api/namex/VERSION.py b/api/namex/VERSION.py index 8a5abcdfa..099b14913 100644 --- a/api/namex/VERSION.py +++ b/api/namex/VERSION.py @@ -1,2 +1,2 @@ -__version__ = '1.2.21j' +__version__ = '1.2.21k' diff --git a/api/namex/resources/payment_societies.py b/api/namex/resources/payment_societies.py index a9397c9ff..663e97b76 100644 --- a/api/namex/resources/payment_societies.py +++ b/api/namex/resources/payment_societies.py @@ -121,11 +121,9 @@ def post(self): ps_instance.save_to_db() current_app.logger.debug(f'ps_instance saved...') - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if nrd.stateCd == State.PENDING_PAYMENT: nrd.stateCd = 'DRAFT' - - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + nrd.save_to_db() current_app.logger.debug(f'nrd saved...') diff --git a/api/namex/resources/requests.py b/api/namex/resources/requests.py index b00282edd..3615b91e3 100644 --- a/api/namex/resources/requests.py +++ b/api/namex/resources/requests.py @@ -731,7 +731,7 @@ def put(nr, *args, **kwargs): if not valid_state_transition(user, nrd, state): return make_response(jsonify(message='you are not authorized to make these changes'), 401) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + name_choice_exists = {1: False, 2: False, 3: False} for name in json_input.get('names', None): if name['name'] and name['name'] != '': @@ -740,7 +740,7 @@ def put(nr, *args, **kwargs): return make_response(jsonify(message='Data does not include a name choice 1'), 400) if not name_choice_exists[2] and name_choice_exists[3]: return make_response(jsonify(message='Data contains a name choice 3 without a name choice 2'), 400) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + try: existing_nr = RequestDAO.get_inprogress(user) if existing_nr: @@ -768,7 +768,7 @@ def put(nr, *args, **kwargs): except Exception as e: current_app.logger.debug(f"Error parsing expirationDate: {str(e)}") pass - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # convert NWPTA dates to correct format if json_input.get('nwpta', None): for region in json_input['nwpta']: @@ -787,7 +787,7 @@ def put(nr, *args, **kwargs): reset = False if nrd.furnished == RequestDAO.REQUEST_FURNISHED and json_input.get('furnished', None) == 'N': reset = True - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + nrd.additionalInfo = convert_to_ascii(json_input.get('additionalInfo', None)) nrd.consentFlag = json_input.get('consentFlag', None) nrd.consent_dt = json_input.get('consent_dt', None) @@ -826,11 +826,11 @@ def put(nr, *args, **kwargs): nrd.previousRequestId = None except KeyError: nrd.previousRequestId = None - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # if we're changing to a completed or cancelled state, clear reset flag on NR record if state in State.COMPLETED_STATE + [State.CANCELLED]: nrd.hasBeenReset = False - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # check if any of the Oracle db fields have changed, so we can send them back is_changed__request = False is_changed__previous_request = False @@ -854,7 +854,7 @@ def put(nr, *args, **kwargs): is_changed_consent = True if nrd.consentFlag == 'R': queue_util.publish_email_notification(nrd.nrNum, 'CONSENT_RECEIVED') - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # Need this for a re-open if nrd.stateCd != State.CONDITIONAL and is_changed__request_state: nrd.consentFlag = None @@ -865,7 +865,7 @@ def put(nr, *args, **kwargs): ### APPLICANTS ### is_changed__applicant = False is_changed__address = False - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + if nrd.applicants: applicants_d = nrd.applicants[0] orig_applicant = applicants_d.as_dict() @@ -893,7 +893,7 @@ def put(nr, *args, **kwargs): applicants_d.postalCd = convert_to_ascii(appl.get('postalCd', None)) applicants_d.stateProvinceCd = convert_to_ascii(appl.get('stateProvinceCd', None)) applicants_d.countryTypeCd = convert_to_ascii(appl.get('countryTypeCd', None)) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # check if any of the Oracle db fields have changed, so we can send them back if applicants_d.lastName != orig_applicant['lastName']: is_changed__applicant = True @@ -929,12 +929,10 @@ def put(nr, *args, **kwargs): is_changed__address = True if applicants_d.countryTypeCd != orig_applicant['countryTypeCd']: is_changed__address = True - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") else: applicants_d.delete_from_db() is_changed__applicant = True is_changed__address = True - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") ### END applicants ### @@ -945,7 +943,7 @@ def put(nr, *args, **kwargs): is_changed__name2 = False is_changed__name3 = False deleted_names = [False] * 3 - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + if len(nrd.names) == 0: new_name_choice = Name() new_name_choice.nrId = nrd.id @@ -954,23 +952,23 @@ def put(nr, *args, **kwargs): new_name_choice.name = convert_to_ascii(new_name_choice.name) nrd.names.append(new_name_choice) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + for nrd_name in nrd.names: orig_name = nrd_name.as_dict() for in_name in json_input.get('names', []): - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + if len(nrd.names) < in_name['choice']: errors = names_schema.validate(in_name, partial=False) if errors: MessageServices.add_message(MessageServices.ERROR, 'names_validation', errors) # return make_response(jsonify(errors), 400 - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # don't save if the name is blank if in_name.get('name') and in_name.get('name') != '': - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + new_name_choice = Name() new_name_choice.nrId = nrd.id new_name_choice.choice = in_name.get('choice') @@ -997,7 +995,6 @@ def put(nr, *args, **kwargs): is_changed__name3 = True elif nrd_name.choice == in_name['choice']: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") errors = names_schema.validate(in_name, partial=False) if errors: MessageServices.add_message(MessageServices.ERROR, 'names_validation', errors) @@ -1018,48 +1015,42 @@ def put(nr, *args, **kwargs): nrd_name.name = in_name.get('name') nrd_name.state = in_name.get('state') nrd_name.name = convert_to_ascii(nrd_name.name.upper()) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # set comments (existing or cleared) if in_name.get('comment', None) is not None: # if there is a comment ID in data, just set it if in_name['comment'].get('id', None) is not None: nrd_name.commentId = in_name['comment'].get('id') - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") # if no comment id, it's a new comment, so add it else: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") # no business case for this at this point - this code will never run pass else: nrd_name.comment = None - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # convert data to ascii, removing data that won't save to Oracle # - also force uppercase nrd_name.name = convert_to_ascii(nrd_name.name) if (nrd_name.name is not None): nrd_name.name = nrd_name.name.upper() - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + # check if any of the Oracle db fields have changed, so we can send them back # - this is only for editing a name from the Edit NR section, NOT making a decision if nrd_name.name != orig_name['name']: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if nrd_name.choice == 1: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") is_changed__name1 = True json_input['comments'].append({'comment': 'Name choice 1 changed from {0} to {1}' .format(orig_name['name'], nrd_name.name)}) if nrd_name.choice == 2: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") is_changed__name2 = True if not nrd_name.name: deleted_names[nrd_name.choice - 1] = True json_input['comments'].append({'comment': 'Name choice 2 changed from {0} to {1}' .format(orig_name['name'], nrd_name.name)}) if nrd_name.choice == 3: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") is_changed__name3 = True if not nrd_name.name: deleted_names[nrd_name.choice - 1] = True @@ -1072,17 +1063,14 @@ def put(nr, *args, **kwargs): # we only add new comments, we do not change existing comments # - we can find new comments in json as those with no ID # - This must come after names section above, to handle comments re. changed names. - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") for in_comment in json_input['comments']: is_new_comment = False try: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if in_comment['id'] is None or in_comment['id'] == 0: is_new_comment = True except KeyError: is_new_comment = True if is_new_comment and in_comment['comment'] is not None: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") new_comment = Comment() new_comment.comment = convert_to_ascii(in_comment['comment']) new_comment.examiner = user @@ -1094,17 +1082,12 @@ def put(nr, *args, **kwargs): is_changed__nwpta_ab = False is_changed__nwpta_sk = False - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if nrd.partnerNS.count() > 0: for nrd_nwpta in nrd.partnerNS.all(): - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") - orig_nwpta = nrd_nwpta.as_dict() for in_nwpta in json_input['nwpta']: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if nrd_nwpta.partnerJurisdictionTypeCd == in_nwpta['partnerJurisdictionTypeCd']: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") errors = nwpta_schema.validate(in_nwpta, partial=False) if errors: MessageServices.add_message(MessageServices.ERROR, 'nwpta_validation', errors) @@ -1136,21 +1119,18 @@ def put(nr, *args, **kwargs): # if there were errors, abandon changes and return the set of errors warning_and_errors = MessageServices.get_all_messages() - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if warning_and_errors: for we in warning_and_errors: if we['type'] == MessageServices.ERROR: return make_response(jsonify(errors=warning_and_errors), 400) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") + if reset: nrd.expirationDate = None nrd.consentFlag = None nrd.consent_dt = None is_changed__request = True is_changed_consent = True - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") else: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") change_flags = { 'is_changed__request': is_changed__request, 'is_changed__previous_request': is_changed__previous_request, @@ -1166,33 +1146,24 @@ def put(nr, *args, **kwargs): } if any(value is True for value in change_flags.values()): - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") nrd.save_to_db() - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") # Delete any names that were blanked out - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") for nrd_name in nrd.names: - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if deleted_names[nrd_name.choice - 1]: nrd_name.delete_from_db() - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") # if there were errors, return the set of errors warning_and_errors = MessageServices.get_all_messages() - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") if warning_and_errors: for we in warning_and_errors: if we['type'] == MessageServices.ERROR: return make_response(jsonify(errors=warning_and_errors), 400) # Finally save the entire graph - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") nrd.save_to_db() - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") EventRecorder.record(user, Event.PUT, nrd, json_input) - current_app.logger.debug(f"continue...stateCd is: {nrd.stateCd}") except ValidationError as ve: return make_response(jsonify(ve.messages), 400) diff --git a/api/namex/services/name_request/utils.py b/api/namex/services/name_request/utils.py index fa54714bc..bdaea1f4f 100644 --- a/api/namex/services/name_request/utils.py +++ b/api/namex/services/name_request/utils.py @@ -149,14 +149,10 @@ def valid_state_transition(user, nr, new_state): """ # when the legacy user just created a new NR from legacy side, the user should be allowed to # modify and cancel it from the legacy side (while the NR still in DRAFT state). - current_app.logger.debug('stateCd: {}'.format(nr.stateCd)) - current_app.logger.debug('new_state: {}'.format(new_state)) - current_app.logger.debug(f"inside valid_state_transition") if (nr.stateCd == State.DRAFT or nr.stateCd == State.APPROVED or nr.stateCd == State.CANCELLED) \ and (new_state == State.DRAFT or new_state == State.CANCELLED): - current_app.logger.debug(f"inside valid_state_transition true") return True - current_app.logger.debug(f"inside valid_state_transition continue") + if (new_state in (State.APPROVED, State.REJECTED, State.CONDITIONAL)) \