foreman_templates 9.1.0 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/api/v2/template_controller.rb +3 -3
- data/app/controllers/ui_template_syncs_controller.rb +8 -2
- data/app/views/template_sync_settings/show.json.rabl +2 -2
- data/db/migrate/20211122154929_templates_settings_category_to_dsl.rb +5 -0
- data/lib/foreman_templates/engine.rb +71 -5
- data/lib/foreman_templates/version.rb +1 -1
- data/lib/foreman_templates.rb +15 -0
- data/webpack/__mocks__/foremanReact/components/Pagination/index.js +2 -0
- data/webpack/components/TemplateSyncResult/TemplateSyncResultHelpers.js +2 -2
- data/webpack/components/TemplateSyncResult/TemplateSyncResultReducer.js +1 -1
- data/webpack/components/TemplateSyncResult/__tests__/__snapshots__/TemplateSyncResultReducer.test.js.snap +2 -2
- data/webpack/components/TemplateSyncResult/components/SyncResultList.js +11 -6
- data/webpack/components/TemplateSyncResult/components/__tests__/SyncResultList.test.js +1 -1
- data/webpack/components/TemplateSyncResult/components/__tests__/__snapshots__/SyncResultList.test.js.snap +3 -9
- metadata +4 -4
- data/app/models/setting/template_sync.rb +0 -115
- data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +0 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bda8e472a4ae76b0f1480738e9059423a249c4156842deebc385baa2f3c2a5ca
|
|
4
|
+
data.tar.gz: bb04b38ce6791e62f90fcea5a177d38ca62402e6c3037e7f3ed85c416f91696c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3c35d3ca52df290a50a3e1788ea654a0588067ab02278a5b77829bfaec46d8c855ae36f554a608eaf8e9c5797b650d5be1a95ed4e7f8486c905e601068180fc5
|
|
7
|
+
data.tar.gz: b58a200b8374f22481e1397949cc4126315234b6238ce08895acedb628c826515ce9ab514b85942b8388350f0e8939b0d088ccc6641fc4b3b84a1fc65ef16961
|
|
@@ -17,9 +17,9 @@ module Api
|
|
|
17
17
|
|
|
18
18
|
api :POST, "/templates/import/", N_("Initiate Import")
|
|
19
19
|
param :prefix, String, :required => false, :desc => N_("The string all imported templates should begin with.")
|
|
20
|
-
param :associate,
|
|
20
|
+
param :associate, ForemanTemplates.associate_types.keys, :required => false, :desc => N_("Associate to OS's, Locations & Organizations. Options are: always, new or never.")
|
|
21
21
|
param :force, :bool, :required => false, :desc => N_("Update templates that are locked")
|
|
22
|
-
param :lock,
|
|
22
|
+
param :lock, ForemanTemplates.lock_types.keys + ["true", "false", "0", "1"], :required => false, :desc => N_("Lock imported templates")
|
|
23
23
|
param :verbose, :bool, :required => false, :desc => N_("Show template diff in response")
|
|
24
24
|
param_group :foreman_template_sync_params
|
|
25
25
|
param_group :taxonomies, ::Api::V2::BaseController
|
|
@@ -32,7 +32,7 @@ module Api
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
api :POST, "/templates/export", N_("Initiate Export")
|
|
35
|
-
param :metadata_export_mode,
|
|
35
|
+
param :metadata_export_mode, ForemanTemplates.metadata_export_mode_types.keys, :required => false, :desc => N_("Specify how to handle metadata")
|
|
36
36
|
param :commit_msg, String, :desc => N_("Custom commit message for templates export")
|
|
37
37
|
param_group :foreman_template_sync_params
|
|
38
38
|
param_group :taxonomies, ::Api::V2::BaseController
|
|
@@ -8,8 +8,8 @@ class UiTemplateSyncsController < ApplicationController
|
|
|
8
8
|
end
|
|
9
9
|
|
|
10
10
|
def sync_settings
|
|
11
|
-
import_settings =
|
|
12
|
-
export_settings =
|
|
11
|
+
import_settings = setting_definitions(ForemanTemplates::IMPORT_SETTING_NAMES)
|
|
12
|
+
export_settings = setting_definitions(ForemanTemplates::EXPORT_SETTING_NAMES)
|
|
13
13
|
@results = OpenStruct.new(:import => import_settings, :export => export_settings)
|
|
14
14
|
end
|
|
15
15
|
|
|
@@ -45,4 +45,10 @@ class UiTemplateSyncsController < ApplicationController
|
|
|
45
45
|
def render_errors(messages, severity = 'danger')
|
|
46
46
|
render :json => { :error => { :errors => { :base => messages }, full_messages: messages, :severity => severity } }, :status => :unprocessable_entity
|
|
47
47
|
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def setting_definitions(short_names)
|
|
52
|
+
short_names.map { |name| Foreman.settings.find("template_sync_#{name}") }
|
|
53
|
+
end
|
|
48
54
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
object @setting
|
|
2
2
|
|
|
3
3
|
node do |setting|
|
|
4
|
-
{ :name => setting.
|
|
4
|
+
{ :name => setting.name.delete_prefix('template_sync_') }
|
|
5
5
|
end
|
|
6
6
|
|
|
7
7
|
attributes :id, :value, :description, :settings_type, :default, :full_name
|
|
8
8
|
|
|
9
9
|
node do |setting|
|
|
10
|
-
{ :selection => setting.
|
|
10
|
+
{ :selection => (setting.select_values || {}).map { |key, label| { value: key, label: label } } }
|
|
11
11
|
end
|
|
@@ -10,10 +10,6 @@ module ForemanTemplates
|
|
|
10
10
|
class Engine < ::Rails::Engine
|
|
11
11
|
engine_name 'foreman_templates'
|
|
12
12
|
|
|
13
|
-
initializer 'foreman_templates.load_default_settings', :before => :load_config_initializers do
|
|
14
|
-
require_dependency File.expand_path('../../app/models/setting/template_sync.rb', __dir__) if (Setting.table_exists? rescue(false))
|
|
15
|
-
end
|
|
16
|
-
|
|
17
13
|
initializer "foreman_templates.add_rabl_view_path" do
|
|
18
14
|
Rabl.configure do |config|
|
|
19
15
|
config.view_paths << ForemanTemplates::Engine.root.join('app', 'views')
|
|
@@ -28,10 +24,78 @@ module ForemanTemplates
|
|
|
28
24
|
|
|
29
25
|
initializer 'foreman_templates.register_plugin', :before => :finisher_hook do
|
|
30
26
|
Foreman::Plugin.register :foreman_templates do
|
|
31
|
-
requires_foreman '>=
|
|
27
|
+
requires_foreman '>= 3.2'
|
|
32
28
|
|
|
33
29
|
apipie_documented_controllers ["#{ForemanTemplates::Engine.root}/app/controllers/api/v2/*.rb"]
|
|
34
30
|
|
|
31
|
+
settings do
|
|
32
|
+
category(:template_sync, N_('Template Sync')) do
|
|
33
|
+
setting('template_sync_verbose',
|
|
34
|
+
type: :boolean,
|
|
35
|
+
description: N_('Choose verbosity for Rake task importing templates'),
|
|
36
|
+
default: false,
|
|
37
|
+
full_name: N_('Verbosity'))
|
|
38
|
+
setting('template_sync_associate',
|
|
39
|
+
type: :string,
|
|
40
|
+
description: N_('Associate templates to OS, organization and location'),
|
|
41
|
+
default: 'new',
|
|
42
|
+
full_name: N_('Associate'),
|
|
43
|
+
collection: -> { ForemanTemplates.associate_types })
|
|
44
|
+
setting('template_sync_prefix',
|
|
45
|
+
type: :string,
|
|
46
|
+
description: N_('The string that will be added as prefix to imported templates'),
|
|
47
|
+
default: "",
|
|
48
|
+
full_name: N_('Prefix'))
|
|
49
|
+
setting('template_sync_dirname',
|
|
50
|
+
type: :string,
|
|
51
|
+
description: N_('The directory within the Git repo containing the templates'),
|
|
52
|
+
default: '/',
|
|
53
|
+
full_name: N_('Dirname'))
|
|
54
|
+
setting('template_sync_filter',
|
|
55
|
+
type: :string,
|
|
56
|
+
description: N_('Import/export names matching this regex (case-insensitive; snippets are not filtered)'),
|
|
57
|
+
default: '',
|
|
58
|
+
full_name: N_('Filter'))
|
|
59
|
+
setting('template_sync_repo',
|
|
60
|
+
type: :string,
|
|
61
|
+
description: N_('Target path to import/export. Different protocols can be used, for example /tmp/dir, git://example.com, https://example.com, ssh://example.com. When exporting to /tmp, note that production deployments may be configured to use private tmp.'),
|
|
62
|
+
default: 'https://github.com/theforeman/community-templates.git',
|
|
63
|
+
full_name: N_('Repo'))
|
|
64
|
+
setting('template_sync_negate',
|
|
65
|
+
type: :boolean,
|
|
66
|
+
description: N_('Negate the filter for import/export'),
|
|
67
|
+
default: false,
|
|
68
|
+
full_name: N_('Negate'))
|
|
69
|
+
setting('template_sync_branch',
|
|
70
|
+
type: :string,
|
|
71
|
+
description: N_('Default branch in Git repo'),
|
|
72
|
+
default: '',
|
|
73
|
+
full_name: N_('Branch'))
|
|
74
|
+
setting('template_sync_metadata_export_mode',
|
|
75
|
+
type: :string,
|
|
76
|
+
description: N_('Default metadata export mode, refresh re-renders metadata, keep will keep existing metadata, remove exports template without metadata'),
|
|
77
|
+
default: 'refresh',
|
|
78
|
+
full_name: N_('Metadata export mode'),
|
|
79
|
+
collection: -> { ForemanTemplates.metadata_export_mode_types })
|
|
80
|
+
setting('template_sync_force',
|
|
81
|
+
type: :boolean,
|
|
82
|
+
description: N_('Should importing overwrite locked templates?'),
|
|
83
|
+
default: false,
|
|
84
|
+
full_name: N_('Force import'))
|
|
85
|
+
setting('template_sync_lock',
|
|
86
|
+
type: :string,
|
|
87
|
+
description: N_('How to handle lock for imported templates?'),
|
|
88
|
+
default: 'keep',
|
|
89
|
+
full_name: N_('Lock templates'),
|
|
90
|
+
collection: -> { ForemanTemplates.lock_types })
|
|
91
|
+
setting('template_sync_commit_msg',
|
|
92
|
+
type: :string,
|
|
93
|
+
description: N_('Custom commit message for templates export'),
|
|
94
|
+
default: 'Templates export made by a Foreman user',
|
|
95
|
+
full_name: N_('Commit message'))
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
35
99
|
security_block :templates do
|
|
36
100
|
permission :import_templates, {
|
|
37
101
|
:"api/v2/template" => [:import],
|
|
@@ -58,6 +122,8 @@ module ForemanTemplates
|
|
|
58
122
|
end
|
|
59
123
|
|
|
60
124
|
config.to_prepare do
|
|
125
|
+
Setting::NOT_STRIPPED << 'template_sync_prefix'
|
|
126
|
+
|
|
61
127
|
Template.include ForemanTemplates::TemplateExtensions
|
|
62
128
|
end
|
|
63
129
|
end
|
data/lib/foreman_templates.rb
CHANGED
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
require 'foreman_templates/engine'
|
|
2
2
|
|
|
3
3
|
module ForemanTemplates
|
|
4
|
+
BASE_SETTING_NAMES = %w(repo branch dirname filter negate).freeze
|
|
5
|
+
IMPORT_SETTING_NAMES = (BASE_SETTING_NAMES | %w(prefix associate force lock)).freeze
|
|
6
|
+
EXPORT_SETTING_NAMES = (BASE_SETTING_NAMES | %w(metadata_export_mode commit_msg)).freeze
|
|
7
|
+
|
|
8
|
+
def self.associate_types
|
|
9
|
+
{ 'always' => _('Always'), 'new' => _('New'), 'never' => _('Never') }
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def self.lock_types
|
|
13
|
+
{ 'lock' => _('Lock'), 'keep_lock_new' => _('Keep, lock new'), 'keep' => _('Keep, do not lock new'), 'unlock' => _('Unlock') }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.metadata_export_mode_types
|
|
17
|
+
{ 'refresh' => _('Refresh'), 'keep' => _('Keep'), 'remove' => _('Remove') }
|
|
18
|
+
end
|
|
4
19
|
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// move to some sort of pagination helper in core
|
|
2
2
|
export const templatesPage = (templates, pagination) => {
|
|
3
|
-
const offset = (pagination.page - 1) * pagination.
|
|
3
|
+
const offset = (pagination.page - 1) * pagination.per_page;
|
|
4
4
|
|
|
5
|
-
return templates.slice(offset, offset + pagination.
|
|
5
|
+
return templates.slice(offset, offset + pagination.per_page);
|
|
6
6
|
};
|
|
@@ -4,7 +4,7 @@ exports[`TemplateSyncResultReducer should return initial state 1`] = `
|
|
|
4
4
|
Object {
|
|
5
5
|
"pagination": Object {
|
|
6
6
|
"page": 1,
|
|
7
|
-
"
|
|
7
|
+
"per_page": 20,
|
|
8
8
|
},
|
|
9
9
|
"resultAction": "",
|
|
10
10
|
"templates": Array [],
|
|
@@ -27,7 +27,7 @@ Object {
|
|
|
27
27
|
"branch": "master",
|
|
28
28
|
"pagination": Object {
|
|
29
29
|
"page": 1,
|
|
30
|
-
"
|
|
30
|
+
"per_page": 20,
|
|
31
31
|
},
|
|
32
32
|
"repo": "https://github.com/theforeman/community-templates.git",
|
|
33
33
|
"resultAction": "import",
|
|
@@ -2,13 +2,19 @@ import React from 'react';
|
|
|
2
2
|
import { ListView } from 'patternfly-react';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
|
|
5
|
-
import Pagination from 'foremanReact/components/Pagination
|
|
5
|
+
import Pagination from 'foremanReact/components/Pagination';
|
|
6
6
|
|
|
7
7
|
import SyncedTemplate from './SyncedTemplate';
|
|
8
8
|
import { templatesPage } from '../TemplateSyncResultHelpers';
|
|
9
9
|
import ListViewHeader from './ListViewHeader';
|
|
10
10
|
|
|
11
|
-
const SyncResultList = ({
|
|
11
|
+
const SyncResultList = ({
|
|
12
|
+
pagination,
|
|
13
|
+
pagination: { page, per_page: perPage },
|
|
14
|
+
pageChange,
|
|
15
|
+
templates,
|
|
16
|
+
editPaths,
|
|
17
|
+
}) => (
|
|
12
18
|
<ListView>
|
|
13
19
|
<ListViewHeader />
|
|
14
20
|
{templatesPage(templates, pagination).map((template, idx) => (
|
|
@@ -19,11 +25,10 @@ const SyncResultList = ({ pagination, pageChange, templates, editPaths }) => (
|
|
|
19
25
|
/>
|
|
20
26
|
))}
|
|
21
27
|
<Pagination
|
|
22
|
-
viewType="list"
|
|
23
28
|
itemCount={templates.length}
|
|
24
|
-
pagination={pagination}
|
|
25
29
|
onChange={pageChange}
|
|
26
|
-
|
|
30
|
+
page={page}
|
|
31
|
+
perPage={perPage}
|
|
27
32
|
/>
|
|
28
33
|
</ListView>
|
|
29
34
|
);
|
|
@@ -31,7 +36,7 @@ const SyncResultList = ({ pagination, pageChange, templates, editPaths }) => (
|
|
|
31
36
|
SyncResultList.propTypes = {
|
|
32
37
|
pagination: PropTypes.shape({
|
|
33
38
|
page: PropTypes.number,
|
|
34
|
-
|
|
39
|
+
per_page: PropTypes.number,
|
|
35
40
|
}).isRequired,
|
|
36
41
|
pageChange: PropTypes.func.isRequired,
|
|
37
42
|
templates: PropTypes.array.isRequired,
|
|
@@ -88,17 +88,11 @@ exports[`SyncResultList should render 1`] = `
|
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
/>
|
|
91
|
-
<
|
|
92
|
-
dropdownButtonId="template-sync-result-dropdown"
|
|
91
|
+
<Pagination
|
|
93
92
|
itemCount={5}
|
|
94
93
|
onChange={[Function]}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"page": 1,
|
|
98
|
-
"perPage": 20,
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
viewType="list"
|
|
94
|
+
page={1}
|
|
95
|
+
perPage={20}
|
|
102
96
|
/>
|
|
103
97
|
</ListView>
|
|
104
98
|
`;
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: foreman_templates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 9.
|
|
4
|
+
version: 9.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Greg Sutcliffe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-02-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: diffy
|
|
@@ -69,7 +69,6 @@ files:
|
|
|
69
69
|
- app/controllers/ui_template_syncs_controller.rb
|
|
70
70
|
- app/helpers/foreman_templates_helper.rb
|
|
71
71
|
- app/models/concerns/foreman_templates/template_extensions.rb
|
|
72
|
-
- app/models/setting/template_sync.rb
|
|
73
72
|
- app/services/foreman_templates/action.rb
|
|
74
73
|
- app/services/foreman_templates/cleaner.rb
|
|
75
74
|
- app/services/foreman_templates/export_result.rb
|
|
@@ -89,6 +88,7 @@ files:
|
|
|
89
88
|
- app/views/ui_template_syncs/template_import_results.json.rabl
|
|
90
89
|
- config/routes.rb
|
|
91
90
|
- db/migrate/20180627134929_change_lock_setting.rb
|
|
91
|
+
- db/migrate/20211122154929_templates_settings_category_to_dsl.rb
|
|
92
92
|
- lib/foreman_templates.rb
|
|
93
93
|
- lib/foreman_templates/engine.rb
|
|
94
94
|
- lib/foreman_templates/version.rb
|
|
@@ -99,7 +99,7 @@ files:
|
|
|
99
99
|
- webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js
|
|
100
100
|
- webpack/__mocks__/foremanReact/common/helpers.js
|
|
101
101
|
- webpack/__mocks__/foremanReact/components/Layout/LayoutSelectors.js
|
|
102
|
-
- webpack/__mocks__/foremanReact/components/Pagination/
|
|
102
|
+
- webpack/__mocks__/foremanReact/components/Pagination/index.js
|
|
103
103
|
- webpack/__mocks__/foremanReact/components/common/forms/CommonForm.js
|
|
104
104
|
- webpack/__mocks__/foremanReact/components/common/forms/ForemanForm.js
|
|
105
105
|
- webpack/__mocks__/foremanReact/components/common/forms/TextField.js
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
class Setting
|
|
2
|
-
class TemplateSync < ::Setting
|
|
3
|
-
self.include_root_in_json = false
|
|
4
|
-
|
|
5
|
-
def self.common_stripped_names
|
|
6
|
-
%w(verbose repo branch dirname filter negate)
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def self.import_stripped_names
|
|
10
|
-
%w(prefix associate force lock)
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def self.export_stripped_names
|
|
14
|
-
%w(metadata_export_mode commit_msg)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def self.import_setting_names(except = [])
|
|
18
|
-
map_prefix omit_settings(common_stripped_names + import_stripped_names, except)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def self.export_setting_names(except = [])
|
|
22
|
-
map_prefix omit_settings(common_stripped_names + export_stripped_names, except)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def self.map_prefix(stripped_names)
|
|
26
|
-
stripped_names.map { |item| "template_sync_#{item}" }
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def self.omit_settings(setting_names, except_array)
|
|
30
|
-
setting_names.reject { |name| except_array.include? name }
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def self.associate_types
|
|
34
|
-
{
|
|
35
|
-
'always' => _('Always'),
|
|
36
|
-
'new' => _('New'),
|
|
37
|
-
'never' => _('Never')
|
|
38
|
-
}
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def self.lock_types
|
|
42
|
-
{
|
|
43
|
-
'lock' => _('Lock'),
|
|
44
|
-
'keep_lock_new' => _('Keep, lock new'),
|
|
45
|
-
'keep' => _('Keep, do not lock new'),
|
|
46
|
-
'unlock' => _('Unlock')
|
|
47
|
-
}
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def self.metadata_export_mode_types
|
|
51
|
-
{
|
|
52
|
-
'refresh' => _('Refresh'),
|
|
53
|
-
'keep' => _('Keep'),
|
|
54
|
-
'remove' => _('Remove')
|
|
55
|
-
}
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def short_name
|
|
59
|
-
name.split('template_sync_').last
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def selection
|
|
63
|
-
selection_method = name.split('template_sync_').last.concat('_types')
|
|
64
|
-
return transformed_selection(selection_method) if self.class.respond_to?(selection_method)
|
|
65
|
-
|
|
66
|
-
[]
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def self.load_defaults
|
|
70
|
-
return unless super
|
|
71
|
-
|
|
72
|
-
%w(template_sync_filter template_sync_branch template_sync_prefix).each { |s| Setting::BLANK_ATTRS << s }
|
|
73
|
-
Setting::NOT_STRIPPED << 'template_sync_prefix'
|
|
74
|
-
|
|
75
|
-
self.transaction do
|
|
76
|
-
[
|
|
77
|
-
self.set('template_sync_verbose', N_('Choose verbosity for Rake task importing templates'), false, N_('Verbosity')),
|
|
78
|
-
self.set('template_sync_associate', N_('Associate templates to OS, organization and location'), 'new', N_('Associate'), nil, { :collection => Proc.new { self.associate_types } }),
|
|
79
|
-
self.set('template_sync_prefix', N_('The string that will be added as prefix to imported templates'), "", N_('Prefix')),
|
|
80
|
-
self.set('template_sync_dirname', N_('The directory within the Git repo containing the templates'), '/', N_('Dirname')),
|
|
81
|
-
self.set('template_sync_filter', N_('Import/export names matching this regex (case-insensitive; snippets are not filtered)'), '', N_('Filter')),
|
|
82
|
-
self.set('template_sync_repo', N_('Target path to import/export. Different protocols can be used, for example /tmp/dir, git://example.com, https://example.com, ssh://example.com. When exporting to /tmp, note that production deployments may be configured to use private tmp.'), 'https://github.com/theforeman/community-templates.git', N_('Repo')),
|
|
83
|
-
self.set('template_sync_negate', N_('Negate the filter for import/export'), false, N_('Negate')),
|
|
84
|
-
self.set('template_sync_branch', N_('Default branch in Git repo'), '', N_('Branch')),
|
|
85
|
-
self.set('template_sync_metadata_export_mode', N_('Default metadata export mode, refresh re-renders metadata, keep will keep existing metadata, remove exports template without metadata'), 'refresh', N_('Metadata export mode'), nil, { :collection => Proc.new { self.metadata_export_mode_types } }),
|
|
86
|
-
self.set('template_sync_force', N_('Should importing overwrite locked templates?'), false, N_('Force import')),
|
|
87
|
-
self.set('template_sync_lock', N_('How to handle lock for imported templates?'), 'keep', N_('Lock templates'), nil, { :collection => Proc.new { self.lock_types } }),
|
|
88
|
-
self.set('template_sync_commit_msg', N_('Custom commit message for templates export'), 'Templates export made by a Foreman user', N_('Commit message'))
|
|
89
|
-
].compact.each { |s| self.create! s.update(:category => "Setting::TemplateSync") }
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
true
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
def validate_template_sync_associate(record)
|
|
96
|
-
values = record.class.associate_types.keys
|
|
97
|
-
if record.value && !values.include?(record.value)
|
|
98
|
-
record.errors[:base] << (_("template_sync_associate must be one of %s") % values.join(', '))
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
def validate_template_sync_metadata_export_mode(record)
|
|
103
|
-
values = record.class.metadata_export_mode_types.keys
|
|
104
|
-
if record.value && !values.include?(record.value)
|
|
105
|
-
record.errors[:base] << (_("template_sync_metadata_export_mode must be one of %s") % values.join(', '))
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
private
|
|
110
|
-
|
|
111
|
-
def transformed_selection(selection_method)
|
|
112
|
-
self.class.public_send(selection_method).map { |key, translated| { :value => key, :label => translated } }
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
end
|