Browse Source

Fixes #4219 - Do not save wizard data in ldap configuration.

Rolf Schmidt 2 years ago
parent
commit
c30463d1a0

+ 10 - 9
app/assets/javascripts/app/controllers/_integration/ldap.coffee

@@ -281,6 +281,7 @@ class ConnectionWizard extends App.ControllerWizardModal
     super
 
     @wizardConfig = @config || {}
+    @wizardData   = {}
 
     if @container
       @el.addClass('modal--local')
@@ -478,11 +479,11 @@ class ConnectionWizard extends App.ControllerWizardModal
           roles[role.id] = role.displayName()
 
         # update wizard data
-        @wizardConfig.wizardData= {}
-        @wizardConfig.wizardData.backend_user_attributes = data.user_attributes
-        @wizardConfig.wizardData.backend_groups = data.groups
-        @wizardConfig.wizardData.user_attributes = user_attributes
-        @wizardConfig.wizardData.roles = roles
+        @wizardData = {}
+        @wizardData.backend_user_attributes = data.user_attributes
+        @wizardData.backend_groups = data.groups
+        @wizardData.user_attributes = user_attributes
+        @wizardData.roles = roles
 
         for key in ['user_uid', 'user_filter', 'group_uid', 'group_filter']
           @wizardConfig[key] ?= data[key]
@@ -577,8 +578,8 @@ class ConnectionWizard extends App.ControllerWizardModal
 
   buildRowUserAttribute: (source, dest) =>
     el = $(App.view('integration/ldap_user_attribute_row')())
-    el.find('.js-ldapAttribute').html(@createSelection('source', @wizardConfig.wizardData.backend_user_attributes, source, true))
-    el.find('.js-userAttribute').html(@createSelection('dest', @wizardConfig.wizardData.user_attributes, dest))
+    el.find('.js-ldapAttribute').html(@createSelection('source', @wizardData.backend_user_attributes, source, true))
+    el.find('.js-userAttribute').html(@createSelection('dest', @wizardData.user_attributes, dest))
     el
 
   buildRowsGroupRole: (group_role_map) =>
@@ -590,8 +591,8 @@ class ConnectionWizard extends App.ControllerWizardModal
 
   buildRowGroupRole: (source, dest) =>
     el = $(App.view('integration/ldap_group_role_row')())
-    el.find('.js-ldapList').html(@createAutocompletion('source', @wizardConfig.wizardData.backend_groups, source))
-    el.find('.js-roleList').html(@createSelection('dest', @wizardConfig.wizardData.roles, dest))
+    el.find('.js-ldapList').html(@createAutocompletion('source', @wizardData.backend_groups, source))
+    el.find('.js-roleList').html(@createSelection('dest', @wizardData.roles, dest))
     el
 
   createSelection: (name, options, selected, unknown) ->

+ 12 - 0
db/migrate/20220822075554_issue4219_ldap_wizard.rb

@@ -0,0 +1,12 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+class Issue4219LdapWizard < ActiveRecord::Migration[6.1]
+  def change
+    return if !Setting.exists?(name: 'system_init_done')
+
+    LdapSource.find_each do |source|
+      source.preferences.delete(:wizardData)
+      source.save!
+    end
+  end
+end

+ 17 - 0
spec/db/migrate/issue_4219_ldap_wizard_spec.rb

@@ -0,0 +1,17 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe Issue4219LdapWizard, type: :db_migration do
+  let(:ldap) { create(:ldap_source) }
+
+  before do
+    ldap.preferences['wizardData'] = { a: 1 }
+    ldap.save!
+    migrate
+  end
+
+  it 'does remove wizard data from ldap sources' do
+    expect(ldap.reload.preferences).not_to have_key('wizardData')
+  end
+end

+ 0 - 33
spec/factories/ldap_source.rb

@@ -16,39 +16,6 @@ FactoryBot.define do
           'base_dn'          => 'dc=foo,dc=example,dc=com',
           'bind_user'        => ENV['IMPORT_LDAP_USER'],
           'bind_pw'          => ENV['IMPORT_LDAP_PASSWORD'],
-          'wizardData'       =>
-                                { 'backend_user_attributes' =>
-                                                               { 'dn'              => 'dn (e.g., cn=nb,dc=foo,dc=example,dc=com)',
-                                                                 'cn'              => 'cn (e.g., Nicole)',
-                                                                 'sn'              => 'sn (e.g., Braun)',
-                                                                 'uid'             => 'uid (e.g., nb)',
-                                                                 'uidnumber'       => 'uidnumber (e.g., 5000)',
-                                                                 'gidnumber'       => 'gidnumber (e.g., 5000)',
-                                                                 'userpassword'    => 'userpassword (e.g., testnb)',
-                                                                 'homedirectory'   => 'homedirectory (e.g., /home/nb)',
-                                                                 'loginshell'      => 'loginshell (e.g., /bin/sh)',
-                                                                 'gecos'           => 'gecos (e.g., Comments)',
-                                                                 'mail'            => 'mail (e.g., nb@example.com)',
-                                                                 'telephonenumber' => 'telephonenumber (e.g., 110)',
-                                                                 'roomnumber'      => 'roomnumber (e.g., 0200)' },
-                                  'backend_groups'          =>
-                                                               { 'cn=admin,ou=groups,dc=foo,dc=example,dc=com'     => 'cn=admin,ou=groups,dc=foo,dc=example,dc=com',
-                                                                 'cn=1st level,ou=groups,dc=foo,dc=example,dc=com' => 'cn=1st level,ou=groups,dc=foo,dc=example,dc=com',
-                                                                 'cn=2nd level,ou=groups,dc=foo,dc=example,dc=com' => 'cn=2nd level,ou=groups,dc=foo,dc=example,dc=com',
-                                                                 'cn=sales,ou=groups,dc=foo,dc=example,dc=com'     => 'cn=sales,ou=groups,dc=foo,dc=example,dc=com' },
-                                  'user_attributes'         =>
-                                                               { 'login'      => 'Login',
-                                                                 'firstname'  => 'First name',
-                                                                 'lastname'   => 'Last name',
-                                                                 'email'      => 'Email',
-                                                                 'web'        => 'Web',
-                                                                 'phone'      => 'Phone',
-                                                                 'mobile'     => 'Mobile',
-                                                                 'fax'        => 'Fax',
-                                                                 'department' => 'Department',
-                                                                 'address'    => 'Address',
-                                                                 'note'       => 'Note' },
-                                  'roles'                   => { '1' => 'Admin', '2' => 'Agent', '3' => 'Customer' } },
           'user_uid'         => 'uid',
           'user_filter'      => '(objectClass=posixaccount)',
           'group_uid'        => 'dn',