Skip to content

Commit

Permalink
22774 make consume compatible to existing LEAR process (bcgov#1565)
Browse files Browse the repository at this point in the history
* consider 'CONSUMED' state in state transition validation

* update the names for consumption

* update version

* update to make it compatible to Lear

* update validation failure message
  • Loading branch information
eve-git authored Aug 22, 2024
1 parent faa8d6a commit c556bfc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
3 changes: 1 addition & 2 deletions api/namex/VERSION.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = '1.2.3'

__version__ = '1.2.4'
16 changes: 6 additions & 10 deletions api/namex/resources/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ def patch(nr, *args, **kwargs):
return make_response(jsonify({"message": "Request:{} not found".format(nr)}), 404)

if not valid_state_transition(user, nrd, state):
return make_response(jsonify(message='you are not authorized to make these changes'), 401)
return make_response(jsonify(message='Name Request state transition validation failed.'), 401)

# if the user has an existing (different) INPROGRESS NR, revert to previous state (default to HOLD)
existing_nr = RequestDAO.get_inprogress(user)
Expand Down Expand Up @@ -647,22 +647,18 @@ def patch(nr, *args, **kwargs):
nrd.furnished = 'Y'

def consumeName(nrd, json_input):
# Validate the required fields are present and not empty
name_to_consume = json_input.get('name')
if not name_to_consume \
or not json_input.get('consumptionDate') \
or not json_input.get('corpNum'):
return False, '"name", "consumptionDate", and "corpNum" are required and cannot be empty.'
if not json_input.get('corpNum'):
return False, '"corpNum" is required and cannot be empty.'

consumed = False
for nrd_name in nrd.names:
if name_to_consume == nrd_name.name:
nrd_name.consumptionDate = json_input.get('consumptionDate')
if nrd_name.state in (Name.APPROVED, Name.CONDITION):
nrd_name.consumptionDate = datetime.utcnow()
nrd_name.corpNum = json_input.get('corpNum')
consumed = True

if not consumed:
return False, f"The given name '{name_to_consume}' cannot be found to be consumed."
return False, f"Cannot find an Approved or Condition name to be consumed."

return True, None # Return success and no error message

Expand Down

0 comments on commit c556bfc

Please sign in to comment.