Skip to content

Commit

Permalink
[IMP] Moved some more code down into the business layer
Browse files Browse the repository at this point in the history
  • Loading branch information
c8y3 committed Mar 19, 2024
1 parent 5710228 commit a70b230
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
22 changes: 5 additions & 17 deletions source/app/blueprints/manage/manage_cases_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from werkzeug import Response
from werkzeug.utils import secure_filename

import app
from app import db
from app.datamgmt.alerts.alerts_db import get_alert_status_by_name
from app.datamgmt.case.case_db import get_case, get_review_id_from_name
Expand Down Expand Up @@ -238,22 +237,11 @@ def api_delete_case(cur_id, caseid):
if not ac_fast_check_current_user_has_case_access(cur_id, [CaseAccessLevel.full_access]):
return ac_api_return_access_denied(caseid=cur_id)

if cur_id == 1:
track_activity("tried to delete case {}, but case is the primary case".format(cur_id),
caseid=caseid, ctx_less=True)

return response_error("Cannot delete a primary case to keep consistency")

else:
try:
try:
delete(cur_id, caseid)
return response_success("Case successfully deleted")
except BusinessProcessingError as e:
return response_error(str(e))
except Exception as e:
app.app.logger.exception(e)
return response_error("Cannot delete the case. Please check server logs for additional informations")
try:
delete(cur_id, caseid)
return response_success('Case successfully deleted')
except BusinessProcessingError as e:
return response_error(str(e))


@manage_cases_blueprint.route('/manage/cases/reopen/<int:cur_id>', methods=['POST'])
Expand Down
23 changes: 15 additions & 8 deletions source/app/business/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,28 @@
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

from app import app
from app.iris_engine.module_handler.module_handler import call_modules_hook
from app.iris_engine.utils.tracker import track_activity
from app.datamgmt.manage.manage_cases_db import delete_case
from app.business.business_processing_error import BusinessProcessingError


def delete(identifier, context_case_identifier):
call_modules_hook('on_preload_case_delete', data=identifier, caseid=context_case_identifier)
if not delete_case(identifier):
track_activity(f'tried to delete case {identifier}, but it doesn\'t exist',
if identifier == 1:
track_activity(f'tried to delete case {identifier}, but case is the primary case',
caseid=context_case_identifier, ctx_less=True)
raise BusinessProcessingError('Tried to delete a non-existing case')
call_modules_hook('on_postload_case_delete', data=identifier, caseid=context_case_identifier)
track_activity(f'case {identifier} deleted successfully', ctx_less=True)



raise BusinessProcessingError('Cannot delete a primary case to keep consistency')

try:
call_modules_hook('on_preload_case_delete', data=identifier, caseid=context_case_identifier)
if not delete_case(identifier):
track_activity(f'tried to delete case {identifier}, but it doesn\'t exist',
caseid=context_case_identifier, ctx_less=True)
raise BusinessProcessingError('Tried to delete a non-existing case')
call_modules_hook('on_postload_case_delete', data=identifier, caseid=context_case_identifier)
track_activity(f'case {identifier} deleted successfully', ctx_less=True)
except Exception as e:
app.logger.exception(e)
raise BusinessProcessingError("Cannot delete the case. Please check server logs for additional informations")

0 comments on commit a70b230

Please sign in to comment.