Browse Source

Fixes #5469 - Organization is removed in the report profile after an reload of the browser tab.

Co-authored-by: Florian Liebe <fl@zammad.com>
Rolf Schmidt 1 month ago
parent
commit
9075b14432

+ 1 - 0
app/models/report/profile.rb

@@ -4,6 +4,7 @@ class Report::Profile < ApplicationModel
   self.table_name = 'report_profiles'
   include ChecksConditionValidation
   include ChecksClientNotification
+  include Report::Profile::Assets
 
   validates :name, presence: true
   store     :condition

+ 31 - 0
app/models/report/profile/assets.rb

@@ -0,0 +1,31 @@
+# Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
+
+class Report::Profile
+  module Assets
+    extend ActiveSupport::Concern
+
+    def assets(data)
+      app_model_report_profile = Report::Profile.to_app_model
+      data[ app_model_report_profile ] ||= {}
+
+      return data if data[ app_model_report_profile ][ id ]
+
+      data[ app_model_report_profile ][ id ] = attributes_with_association_ids
+      data = assets_of_selector('condition', data)
+
+      app_model_user = User.to_app_model
+      data[ app_model_user ] ||= {}
+
+      %w[created_by_id updated_by_id].each do |local_user_id|
+        next if !self[ local_user_id ]
+        next if data[ app_model_user ][ self[ local_user_id ] ]
+
+        user = User.lookup(id: self[ local_user_id ])
+        next if !user
+
+        data = user.assets(data)
+      end
+      data
+    end
+  end
+end

+ 24 - 0
spec/models/report/profile_spec.rb

@@ -0,0 +1,24 @@
+# Copyright (C) 2012-2025 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe Report::Profile, type: :model do
+  describe 'Organization is removed in the report profile after an reload of the browser tab #5469' do
+    let(:conditions_orgs) { create_list(:organization, 3) }
+    let(:report_profile)  { create(:report_profile, condition: condition) }
+    let(:condition) do
+      {
+        'ticket.organization_id' => {
+          'operator'         => 'is',
+          'pre_condition'    => 'specific',
+          'value'            => conditions_orgs.map { |row| row.id.to_s },
+          'value_completion' => ''
+        }
+      }
+    end
+
+    it 'does contain assets for the conditions' do
+      expect(report_profile.assets({})[:Organization].keys.sort).to eq(conditions_orgs.map(&:id).sort)
+    end
+  end
+end