Fixed updating of settings. Fixed showing of ranges in settings widget.

This commit is contained in:
Martin Edenhofer 2015-09-06 13:41:31 +02:00
parent a8d644af28
commit 50a4b7155f
3 changed files with 301 additions and 79 deletions

View file

@ -43,8 +43,11 @@ get config setting
=end
def self.get(name)
logger.debug "Setting.get(#{name.inspect})"
load
if load
logger.debug "Setting.get(#{name.inspect}) # no cache"
else
logger.debug "Setting.get(#{name.inspect}) # from cache"
end
@@current[:settings_config][name]
end
@ -75,7 +78,7 @@ reset config setting to default
# check if config is already generated
if @@current[:settings_config]
return @@current[:settings_config] if cache_valid?
return false if cache_valid?
end
# read all config settings
@ -95,7 +98,7 @@ reset config setting to default
# store for class requests
cache(config)
config
true
end
# set initial value in state_initial
@ -123,7 +126,7 @@ reset config setting to default
# check if cache is still valid
def self.cache_valid?
if @@lookup_at && @@lookup_at > Time.zone.now - @@lookup_timeout
logger.debug 'Setting.cache_valid?: cache_id has beed set within last 2 minutes'
#logger.debug 'Setting.cache_valid?: cache_id has beed set within last 2 minutes'
return true
end
change_id = Cache.get('Setting::ChangeId')
@ -138,7 +141,7 @@ reset config setting to default
# convert state ot hash to be able to store it as store
def state_check
return if state.class == Hash && state.key?(:value)
return if state.respond_to?('has_key?') && state.key?(:value)
self.state = { value: state }
end
end

View file

@ -0,0 +1,207 @@
class UpdateSettings3 < ActiveRecord::Migration
def up
Setting.create_or_update(
title: 'Maximal failed logins',
name: 'password_max_login_failed',
area: 'Security::Password',
description: 'Maximal failed logins after account is inactive.',
options: {
form: [
{
display: '',
null: true,
name: 'password_max_login_failed',
tag: 'select',
options: {
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => '10',
11 => '11',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
},
},
],
},
state: 10,
frontend: true
)
Setting.create_or_update(
title: 'Max. Email Size',
name: 'postmaster_max_size',
area: 'Email::Base',
description: 'Maximal size in MB of emails.',
options: {
form: [
{
display: '',
null: true,
name: 'postmaster_max_size',
tag: 'select',
options: {
1 => ' 1',
2 => ' 2',
3 => ' 3',
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => ' 10',
15 => ' 15',
20 => ' 20',
25 => ' 25',
30 => ' 30',
35 => ' 35',
40 => ' 40',
45 => ' 45',
50 => ' 50',
60 => ' 60',
70 => ' 70',
80 => ' 80',
90 => ' 90',
100 => '100',
125 => '125',
150 => '150',
},
},
],
},
state: 10,
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Ticket Number Increment',
name: 'ticket_number_increment',
area: 'Ticket::Number',
description: '-',
options: {
form: [
{
display: 'Checksum',
null: true,
name: 'checksum',
tag: 'boolean',
options: {
true => 'yes',
false => 'no',
},
},
{
display: 'Min. size of number',
null: true,
name: 'min_size',
tag: 'select',
options: {
1 => ' 1',
2 => ' 2',
3 => ' 3',
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => '10',
11 => '11',
12 => '12',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
},
},
],
},
state: {
checksum: false,
min_size: 5,
},
frontend: false
)
Setting.create_or_update(
title: 'Minimal size',
name: 'password_min_size',
area: 'Security::Password',
description: 'Password need to have at least minimal size of characters.',
options: {
form: [
{
display: '',
null: true,
name: 'password_min_size',
tag: 'select',
options: {
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => '10',
11 => '11',
12 => '12',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
},
},
],
},
state: 6,
frontend: true
)
options = {}
(10..99).each {|item|
options[item] = item
}
system_id = rand(10..99)
current = Setting.find_by(name: 'system_id')
if current
system_id = Setting.get('system_id')
end
Setting.create_or_update(
title: 'SystemID',
name: 'system_id',
area: 'System::Base',
description: 'Defines the system identifier. Every ticket number contains this ID. This ensures that only tickets which belong to your system will be processed as follow-ups (useful when communicating between two instances of Zammad).',
options: {
form: [
{
display: '',
null: true,
name: 'system_id',
tag: 'select',
options: options,
},
],
},
state: system_id,
preferences: { online_service_disable: true },
frontend: true
)
end
end

View file

@ -93,7 +93,11 @@ Setting.create_if_not_exists(
preferences: { prio: 2 },
frontend: true
)
options = {}
(10..99).each {|item|
options[item] = item
}
system_id = rand(10..99)
Setting.create_if_not_exists(
title: 'SystemID',
name: 'system_id',
@ -106,16 +110,11 @@ Setting.create_if_not_exists(
null: true,
name: 'system_id',
tag: 'select',
options: {
'10' => '10',
'11' => '11',
'12' => '12',
'13' => '13',
},
options: options,
},
],
},
state: '10',
state: system_id,
preferences: { online_service_disable: true },
frontend: true
)
@ -615,15 +614,23 @@ Setting.create_if_not_exists(
name: 'password_min_size',
tag: 'select',
options: {
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => '10',
11 => '11',
12 => '12',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
},
},
],
@ -688,22 +695,22 @@ Setting.create_if_not_exists(
name: 'password_max_login_failed',
tag: 'select',
options: {
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
13 => 13,
14 => 14,
15 => 15,
16 => 16,
17 => 17,
18 => 18,
19 => 19,
20 => 20,
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => '10',
11 => '11',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
},
},
],
@ -869,26 +876,26 @@ Setting.create_if_not_exists(
name: 'min_size',
tag: 'select',
options: {
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
13 => 13,
14 => 14,
15 => 15,
16 => 16,
17 => 17,
18 => 18,
19 => 19,
20 => 20,
1 => ' 1',
2 => ' 2',
3 => ' 3',
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => '10',
11 => '11',
12 => '12',
13 => '13',
14 => '14',
15 => '15',
16 => '16',
17 => '17',
18 => '18',
19 => '19',
20 => '20',
},
},
],
@ -1070,26 +1077,31 @@ Setting.create_if_not_exists(
name: 'postmaster_max_size',
tag: 'select',
options: {
1 => 1,
2 => 2,
3 => 3,
4 => 4,
5 => 5,
6 => 6,
7 => 7,
8 => 8,
9 => 9,
10 => 10,
11 => 11,
12 => 12,
13 => 13,
14 => 14,
15 => 15,
16 => 16,
17 => 17,
18 => 18,
19 => 19,
20 => 20,
1 => ' 1',
2 => ' 2',
3 => ' 3',
4 => ' 4',
5 => ' 5',
6 => ' 6',
7 => ' 7',
8 => ' 8',
9 => ' 9',
10 => ' 10',
15 => ' 15',
20 => ' 20',
25 => ' 25',
30 => ' 30',
35 => ' 35',
40 => ' 40',
45 => ' 45',
50 => ' 50',
60 => ' 60',
70 => ' 70',
80 => ' 80',
90 => ' 90',
100 => '100',
125 => '125',
150 => '150',
},
},
],