app/controllers/avo/actions_controller.rb in avo-3.0.0.pre19 vs app/controllers/avo/actions_controller.rb in avo-3.0.1.beta1

- old
+ new

@@ -11,26 +11,36 @@ end before_action :set_action, only: [:show, :handle] def show # Se the view to :new so the default value gets prefilled - @view = Avo::ViewInquirer.new("new") + @view = :new @resource.hydrate(record: @record, view: @view, user: _current_user, params: params) @record = ActionModel.new @action.get_attributes_for_action end def handle resource_ids = action_params[:fields][:avo_resource_ids].split(",") + @selected_query = action_params[:fields][:avo_selected_query] - performed_action = @action.handle_action( - fields: action_params[:fields].except(:avo_resource_ids, :avo_selected_query), + fields = action_params[:fields].except(:avo_resource_ids, :avo_selected_query) + + args = { + fields: fields, current_user: _current_user, - resource: resource, - query: decrypted_query || @resource.find_record(resource_ids, params: params) - ) + resource: resource + } + args[:records] = if @selected_query.present? + @resource.model_class.find_by_sql decrypted_query + else + @resource.find_record resource_ids, params: params + end + + performed_action = @action.handle_action(**args) + respond performed_action.response end private @@ -94,12 +104,13 @@ message[:type] != :silent end end def decrypted_query - return if (encrypted_query = action_params[:fields][:avo_selected_query]).blank? - - Marshal.load(Avo::Services::EncryptionService.decrypt(message: encrypted_query, purpose: :select_all)) + Avo::Services::EncryptionService.decrypt( + message: @selected_query, + purpose: :select_all + ) end def decrypted_arguments arguments = params[:arguments] || params.dig(:fields, :arguments) return if arguments.blank?