From 34c41c4ef7139a766554ddaa38856647a1c4e31f Mon Sep 17 00:00:00 2001 From: dim145 Date: Tue, 2 Apr 2024 12:13:33 +0200 Subject: [PATCH] fix: cannot access current_user && bump --- app/models/activity_application.rb | 6 +++++- lib/elvis/version.rb | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/activity_application.rb b/app/models/activity_application.rb index 72971bcd..9710705b 100755 --- a/app/models/activity_application.rb +++ b/app/models/activity_application.rb @@ -173,7 +173,11 @@ def self.dependant end def pre_destroy - unless @current_user.is_admin + # get current_user if destroy job called from a controller + current_user = RequestStore.read(:request)&.controller_instance&.current_user + + # if user is not admin or destroy request not coming from a controller + unless current_user&.is_admin set_status = Parameter.find_by(label: "activityApplication.default_status") default_activity_status_id = set_status&.parse&.positive? ? set_status.parse : ActivityApplicationStatus::TREATMENT_PENDING_ID diff --git a/lib/elvis/version.rb b/lib/elvis/version.rb index 8f22e13e..8de5f8d8 100644 --- a/lib/elvis/version.rb +++ b/lib/elvis/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Elvis - VERSION = "2.2.11" + VERSION = "2.2.12" end