Browse Source

Maintenance: Improve object manager attribute handling during frontend initialization.

Co-authored-by: Martin Gruner <mg@zammad.com>
Co-authored-by: Dominik Klein <dk@zammad.com>
Co-authored-by: Florian Liebe <fl@zammad.com>
Florian Liebe 1 year ago
parent
commit
1aa70ea4b7

+ 4 - 1
lib/session_helper.rb

@@ -46,7 +46,10 @@ module SessionHelper
     models = {}
     objects = ObjectManager.list_objects
     objects.each do |object|
-      attributes = ObjectManager::Object.new(object).attributes(user)
+      # User related fields are needed for register.
+      next if user.nil? && !object.eql?('User')
+
+      attributes = ObjectManager::Object.new(object).attributes(user, skip_permission: user.nil?)
       models[object] = attributes
     end
     models

+ 1 - 1
public/assets/tests/qunit/form_extended.js

@@ -430,7 +430,7 @@ QUnit.test('form checks', assert => {
     },
     executions: {
       'ticket.state_id': {
-        value: "1",
+        value: "4",
       },
     },
   }

+ 10 - 0
spec/requests/session_spec.rb

@@ -116,6 +116,16 @@ RSpec.describe 'Sessions endpoints', type: :request do
         end
       end
     end
+
+    context 'user not logged in' do
+      subject(:user) { nil }
+
+      it 'contains only user related object manager attributes' do
+        get '/api/v1/signshow', params: {}, as: :json
+
+        expect(json_response['models'].keys).to match_array(%w[User])
+      end
+    end
   end
 
   describe 'GET /auth/sso (single sign-on)' do

+ 11 - 4
spec/system/js/q_unit_spec.rb

@@ -2,7 +2,8 @@
 
 require 'rails_helper'
 
-RSpec.describe 'QUnit', authenticated_as: false, set_up: true, time_zone: 'Europe/London', type: :system do
+RSpec.describe 'QUnit', time_zone: 'Europe/London', type: :system do
+
   matcher :pass_qunit_test do
     match do
       actual.has_css?('.total', wait: 120)
@@ -55,9 +56,15 @@ RSpec.describe 'QUnit', authenticated_as: false, set_up: true, time_zone: 'Europ
           end
 
   files.each do |elem|
-    it elem.humanize do
-      visit "/tests_#{elem}"
-      expect(page).to pass_qunit_test
+    context "when testing #{elem.humanize}", authenticated_as: :user do
+      # Some tests require an authenticated session.
+      let(:needs_user) { elem.include?('form') }
+      let(:user)       { needs_user ? create(:agent) : false }
+
+      it "#{elem.humanize} qunit tests" do
+        visit "/tests_#{elem}"
+        expect(page).to pass_qunit_test
+      end
     end
   end
 end