Added preferences attribute to disable update of setting via rest if system is a online system.

This commit is contained in:
Martin Edenhofer 2015-07-16 15:36:59 +02:00
parent 73e9ccb7b4
commit 940373f171
7 changed files with 342 additions and 31 deletions

View file

@ -280,22 +280,30 @@ class App.ControllerTabs extends App.Controller
render: ->
@html App.view('generic/tabs')(
@el = @html App.view('generic/tabs')(
header: @header
subHeader: @subHeader
tabs: @tabs
)
# insert content
for tab in @tabs
@el.find('.tab-content').append('<div class="tab-pane" id="' + tab.target + '"></div>')
@el.find('.tab-content').append("<div class=\"tab-pane\" id=\"#{tab.target}\"></div>")
if tab.controller
params = tab.params || {}
params.el = @el.find( '#' + tab.target )
params.name = tab.name
params.target = tab.target
params.el = @el.find( "##{tab.target}" )
new tab.controller( params )
# check if tabs need to be hidden
if @tabs.length <= 1
@el.find('.nav-tabs').addClass('hide')
# set last or first tab to active
@lastActiveTab = @Config.get('lastTab')
if @lastActiveTab && @el.find('.nav-tabs li a[href="' + @lastActiveTab + '"]')[0]
@el.find('.nav-tabs li a[href="' + @lastActiveTab + '"]').tab('show')
if @lastActiveTab && @el.find(".nav-tabs li a[href=#{@lastActiveTab}]")[0]
@el.find(".nav-tabs li a[href=#{@lastActiveTab}]").tab('show')
else
@el.find('.nav-tabs li:first a').tab('show')

View file

@ -26,21 +26,30 @@ class App.SettingsArea extends App.Controller
area: @area
)
# filter online service settings
if App.Config.get('system_online_service')
settings = _.filter(settings, (setting) ->
return if setting.online_service
return if setting.preferences && setting.preferences.online_service_disable
setting
)
return if _.isEmpty(settings)
# sort by prio
settings = _.sortBy( settings, (setting) ->
return if !setting.preferences
setting.preferences.prio
)
html = $('<div></div>')
elements = []
for setting in settings
if setting.name is 'product_logo'
item = new App.SettingsAreaLogo( setting: setting )
else
item = new App.SettingsAreaItem( setting: setting )
html.append( item.el )
elements.push item.el
@html html
@html elements
class App.SettingsAreaItem extends App.Controller
events:
@ -67,13 +76,13 @@ class App.SettingsAreaItem extends App.Controller
# item
@html App.view('settings/item')(
setting: @setting,
setting: @setting
)
new App.ControllerForm(
el: @el.find('.form-item'),
model: { configure_attributes: @configure_attributes, className: '' },
autofocus: false,
model: { configure_attributes: @configure_attributes, className: '' }
autofocus: false
)
update: (e) =>
@ -103,7 +112,6 @@ class App.SettingsAreaItem extends App.Controller
@setting.save(
done: =>
ui.formEnable(e)
App.Event.trigger 'notify', {
type: 'success'
msg: App.i18n.translateContent('Update successful!')
@ -112,7 +120,6 @@ class App.SettingsAreaItem extends App.Controller
# rerender ui || get new collections and session data
if @setting.preferences
if @setting.preferences.render
ui.render()
App.Event.trigger( 'ui:rerender' )
@ -121,6 +128,11 @@ class App.SettingsAreaItem extends App.Controller
App.Auth.loginCheck()
fail: =>
ui.formEnable(e)
App.Event.trigger 'notify', {
type: 'error'
msg: App.i18n.translateContent('Can\'t update item!')
timeout: 2000
}
)
class App.SettingsAreaLogo extends App.Controller

View file

@ -5,7 +5,7 @@ class Branding extends App.ControllerTabs
return if !@authenticate()
@title 'Branding', true
@tabs = [
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'System::Branding' } },
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'System::Branding' } }
]
@render()
@ -15,12 +15,13 @@ class System extends App.ControllerTabs
super
return if !@authenticate()
@title 'System', true
@tabs = [
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'System::Base' } },
{ name: 'Services', 'target': 'services', controller: App.SettingsArea, params: { area: 'System::Services' } },
{ name: 'Storage', 'target': 'storage', controller: App.SettingsArea, params: { area: 'System::Storage' } },
{ name: 'Frontend', 'target': 'ui', controller: App.SettingsArea, params: { area: 'System::UI' } },
]
@tabs = []
if !App.Config.get('system_online_service')
@tabs.push { name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'System::Base' } }
@tabs.push { name: 'Services', 'target': 'services', controller: App.SettingsArea, params: { area: 'System::Services' } }
if !App.Config.get('system_online_service')
@tabs.push { name: 'Storage', 'target': 'storage', controller: App.SettingsArea, params: { area: 'System::Storage' } }
@tabs.push { name: 'Frontend', 'target': 'ui', controller: App.SettingsArea, params: { area: 'System::UI' } }
@render()
class Security extends App.ControllerTabs
@ -30,11 +31,10 @@ class Security extends App.ControllerTabs
return if !@authenticate()
@title 'Security', true
@tabs = [
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Security::Base' } },
# { name: 'Authentication', 'target': 'auth', controller: App.SettingsArea, params: { area: 'Security::Authentication' } },
{ name: 'Password', 'target': 'password', controller: App.SettingsArea, params: { area: 'Security::Password' } },
{ name: 'Third-Party Applications', 'target': 'third_party_auth', controller: App.SettingsArea, params: { area: 'Security::ThirdPartyAuthentication' } },
# { name: 'Session', 'target': 'session', controller: '' },
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Security::Base' } }
# { name: 'Authentication', 'target': 'auth', controller: App.SettingsArea, params: { area: 'Security::Authentication' } }
{ name: 'Password', 'target': 'password', controller: App.SettingsArea, params: { area: 'Security::Password' } }
{ name: 'Third-Party Applications', 'target': 'third_party_auth', controller: App.SettingsArea, params: { area: 'Security::ThirdPartyAuthentication' } }
]
@render()
@ -45,8 +45,8 @@ class Import extends App.ControllerTabs
return if !@authenticate()
@title 'Import', true
@tabs = [
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Import::Base' } },
{ name: 'OTRS', 'target': 'otrs', controller: App.SettingsArea, params: { area: 'Import::OTRS' } },
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Import::Base' } }
{ name: 'OTRS', 'target': 'otrs', controller: App.SettingsArea, params: { area: 'Import::OTRS' } }
]
@render()
@ -57,9 +57,8 @@ class Ticket extends App.ControllerTabs
return if !@authenticate()
@title 'Ticket', true
@tabs = [
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Ticket::Base' } },
{ name: 'Number', 'target': 'number', controller: App.SettingsArea, params: { area: 'Ticket::Number' } },
# { name: 'Sender Format', 'target': 'sender-format', controller: App.SettingsArea, params: { area: 'Ticket::SenderFormat' } },
{ name: 'Base', 'target': 'base', controller: App.SettingsArea, params: { area: 'Ticket::Base' } }
{ name: 'Number', 'target': 'number', controller: App.SettingsArea, params: { area: 'Ticket::Number' } }
]
@render()

View file

@ -3,7 +3,7 @@
<h1><%- @T( @header ) %> <small><%- @T( @subHeader ) %></small></h1>
</div>
</div>
<ul class="nav nav-tabs <% if @tabs.length <= 1: %>hide<% end %>" role="tablist">
<ul class="nav nav-tabs" role="tablist">
<% for tab in @tabs: %>
<li><a href="#<%= tab.target %>" role="tab" data-toggle="tab"><%- @T( tab.name ) %></a></li>
<% end %>

View file

@ -32,11 +32,13 @@ class SettingsController < ApplicationController
# PUT /settings/1
def update
return if deny_if_not_role(Z_ROLENAME_ADMIN)
return if !check_access
model_update_render(Setting, params)
end
# PUT /settings/image/:id
def update_image
return if deny_if_not_role(Z_ROLENAME_ADMIN)
if !params[:logo]
render json: {
@ -91,4 +93,16 @@ class SettingsController < ApplicationController
return if deny_if_not_role(Z_ROLENAME_ADMIN)
model_destory_render(Setting, params)
end
private
def check_access
return true if !Setting.get('system_online_service')
setting = Setting.find(params[:id])
return true if setting.preferences && !setting.preferences[:online_service_disable]
response_access_deny
return
end
end

View file

@ -0,0 +1,262 @@
class AddSettingOnlineService < ActiveRecord::Migration
def up
Setting.create_or_update(
title: 'System Init Done',
name: 'system_init_done',
area: 'Core',
description: 'Defines if application is in init mode.',
options: {},
state: false,
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_or_update(
title: 'Developer System',
name: 'developer_mode',
area: 'Core::Develop',
description: 'Defines if application is in developer mode (useful for developer, all users have the same password, password reset will work without email delivery).',
options: {},
state: false,
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_or_update(
title: 'Online Service',
name: 'system_online_service',
area: 'Core',
description: 'Defines if application is used as online service.',
options: {},
state: false,
preferences: { online_service_disable: true },
frontend: true
)
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: {
'10' => '10',
'11' => '11',
'12' => '12',
'13' => '13',
},
},
],
},
state: '10',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_or_update(
title: 'Fully Qualified Domain Name',
name: 'fqdn',
area: 'System::Base',
description: 'Defines the fully qualified domain name of the system. This setting is used as a variable, #{setting.fqdn} which is found in all forms of messaging used by the application, to build links to the tickets within your system.',
options: {
form: [
{
display: '',
null: false,
name: 'fqdn',
tag: 'input',
},
],
},
state: 'zammad.example.com',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_or_update(
title: 'websocket port',
name: 'websocket_port',
area: 'System::WebSocket',
description: 'Defines the port of the websocket server.',
options: {
form: [
{
display: '',
null: false,
name: 'websocket_port',
tag: 'input',
},
],
},
state: '6042',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_or_update(
title: 'http type',
name: 'http_type',
area: 'System::Base',
description: 'Defines the type of protocol, used by the web server, to serve the application. If https protocol will be used instead of plain http, it must be specified in here. Since this has no affect on the web server\'s settings or behavior, it will not change the method of access to the application and, if it is wrong, it will not prevent you from logging into the application. This setting is used as a variable, #{setting.http_type} which is found in all forms of messaging used by the application, to build links to the tickets within your system.',
options: {
form: [
{
display: '',
null: true,
name: 'http_type',
tag: 'select',
options: {
'https' => 'https',
'http' => 'http',
},
},
],
},
state: 'http',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_or_update(
title: 'Storage Mechanism',
name: 'storage',
area: 'System::Storage',
description: '"Database" stores all attachments in the database (not recommended for storing large amounts of data). "Filesystem" stores the data on the filesystem. You can switch between the modules even on a system that is already in production without any loss of data.',
options: {
form: [
{
display: '',
null: true,
name: 'storage',
tag: 'select',
options: {
'DB' => 'Database',
'FS' => 'Filesystem',
},
},
],
},
state: 'DB',
preferences: { online_service_disable: true },
frontend: false
)
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,
11 => 11,
12 => 12,
13 => 13,
14 => 14,
15 => 15,
16 => 16,
17 => 17,
18 => 18,
19 => 19,
20 => 20,
},
},
],
},
state: 10,
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Notification Sender',
name: 'notification_sender',
area: 'Email::Base',
description: 'Defines the sender of email notifications.',
options: {
form: [
{
display: '',
null: false,
name: 'notification_sender',
tag: 'input',
},
],
},
state: 'Notification Master <noreply@#{config.fqdn}>',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Elasticsearch Endpoint URL',
name: 'es_url',
area: 'SearchIndex::Elasticsearch',
description: 'Define endpoint of Elastic Search.',
state: '',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Elasticsearch Endpoint User',
name: 'es_user',
area: 'SearchIndex::Elasticsearch',
description: 'Define http basic auth user of Elasticsearch.',
state: '',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Elastic Search Endpoint Password',
name: 'es_password',
area: 'SearchIndex::Elasticsearch',
description: 'Define http basic auth password of Elasticsearch.',
state: '',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Elastic Search Endpoint Index',
name: 'es_index',
area: 'SearchIndex::Elasticsearch',
description: 'Define Elasticsearch index name.',
state: 'zammad',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Elastic Search Attachment Extentions',
name: 'es_attachment_ignore',
area: 'SearchIndex::Elasticsearch',
description: 'Define attachment extentions which are ignored for Elasticsearch.',
state: [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe', '.box', '.mbox' ],
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_or_update(
title: 'Elastic Search Attachment Size',
name: 'es_attachment_max_size_in_mb',
area: 'SearchIndex::Elasticsearch',
description: 'Define max. attachment size for Elasticsearch.',
state: 50,
preferences: { online_service_disable: true },
frontend: false
)
end
end

View file

@ -13,6 +13,7 @@ Setting.create_if_not_exists(
description: 'Defines if application is in init mode.',
options: {},
state: false,
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_if_not_exists(
@ -22,6 +23,7 @@ Setting.create_if_not_exists(
description: 'Defines if application is in developer mode (useful for developer, all users have the same password, password reset will work without email delivery).',
options: {},
state: false,
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_if_not_exists(
@ -31,6 +33,7 @@ Setting.create_if_not_exists(
description: 'Defines if application is used as online service.',
options: {},
state: false,
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_if_not_exists(
@ -113,6 +116,7 @@ Setting.create_if_not_exists(
],
},
state: '10',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_if_not_exists(
@ -131,6 +135,7 @@ Setting.create_if_not_exists(
],
},
state: 'zammad.example.com',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_if_not_exists(
@ -149,6 +154,7 @@ Setting.create_if_not_exists(
],
},
state: '6042',
preferences: { online_service_disable: true },
frontend: true
)
Setting.create_if_not_exists(
@ -171,6 +177,7 @@ Setting.create_if_not_exists(
],
},
state: 'http',
preferences: { online_service_disable: true },
frontend: true
)
@ -194,6 +201,7 @@ Setting.create_if_not_exists(
],
},
state: 'DB',
preferences: { online_service_disable: true },
frontend: false
)
@ -1064,6 +1072,7 @@ Setting.create_if_not_exists(
],
},
state: 10,
preferences: { online_service_disable: true },
frontend: false
)
@ -1108,6 +1117,7 @@ Setting.create_if_not_exists(
],
},
state: 'Notification Master <noreply@#{config.fqdn}>',
preferences: { online_service_disable: true },
frontend: false
)
@ -1170,6 +1180,7 @@ Setting.create_if_not_exists(
area: 'SearchIndex::Elasticsearch',
description: 'Define endpoint of Elastic Search.',
state: '',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_if_not_exists(
@ -1178,6 +1189,7 @@ Setting.create_if_not_exists(
area: 'SearchIndex::Elasticsearch',
description: 'Define http basic auth user of Elasticsearch.',
state: '',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_if_not_exists(
@ -1186,6 +1198,7 @@ Setting.create_if_not_exists(
area: 'SearchIndex::Elasticsearch',
description: 'Define http basic auth password of Elasticsearch.',
state: '',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_if_not_exists(
@ -1194,6 +1207,7 @@ Setting.create_if_not_exists(
area: 'SearchIndex::Elasticsearch',
description: 'Define Elasticsearch index name.',
state: 'zammad',
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_if_not_exists(
@ -1202,6 +1216,7 @@ Setting.create_if_not_exists(
area: 'SearchIndex::Elasticsearch',
description: 'Define attachment extentions which are ignored for Elasticsearch.',
state: [ '.png', '.jpg', '.jpeg', '.mpeg', '.mpg', '.mov', '.bin', '.exe', '.box', '.mbox' ],
preferences: { online_service_disable: true },
frontend: false
)
Setting.create_if_not_exists(
@ -1210,6 +1225,7 @@ Setting.create_if_not_exists(
area: 'SearchIndex::Elasticsearch',
description: 'Define max. attachment size for Elasticsearch.',
state: 50,
preferences: { online_service_disable: true },
frontend: false
)