zendesk_apps_support 1.11.0 → 1.12.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1af9b7ff78ef619e400492c4e98711a9e3a1014
4
- data.tar.gz: 897349bef78c52a54a97759a4b1dfb66d82c235e
3
+ metadata.gz: d9d77a73de7a3e75fcae675994285e086f9c86cc
4
+ data.tar.gz: a4451063938bc04fa59d98831b05b6939c6eb2ab
5
5
  SHA512:
6
- metadata.gz: 49de33216f17a4a87460689156ad783291c73821501e89feb2da7347677474d2828742c5488a04621e34810be8cc6e20175810545e9f4bee895f3782a234c5df
7
- data.tar.gz: f0a266f0584d30542bcf4056069467986e3e0850f31b10ca90f25dc4ffd6211c529aff92f015e8092c94a46b95bbd111db31f7384ffa0fe00df6d144f516fb58
6
+ metadata.gz: f2dd54326aa0dab31f9c6b5325378e088a38ec8b655d1409eba64eb6864db08cdb2d867706afbe468bf36c25315f15d17273e54fd76a7e58f6db4c01b3960672
7
+ data.tar.gz: 7ed3221747e4b490502da442caeae6c0e82f3d806c2f2ea51b3a49360ab7ea226bc0e926a8a4c09ad2c64dcb662f8ce6c55c9b99f86c7f393eca5e148a629a33
@@ -9,12 +9,15 @@ en:
9
9
  jshint:
10
10
  one: 'JSHint error in %{file}: %{errors}'
11
11
  other: 'JSHint errors in %{file}: %{errors}'
12
+ missing_location_and_requirements: Missing app location or requirements
12
13
  manifest_not_json: manifest is not proper JSON. %{errors}
13
14
  missing_manifest: Could not find manifest.json
15
+ missing_requirements: Could not find requirements.json
14
16
  manifest_keys:
15
17
  missing:
16
18
  one: 'Missing required field in manifest: %{missing_keys}'
17
19
  other: 'Missing required fields in manifest: %{missing_keys}'
20
+ requirements_not_json: requirements.json is not proper JSON. %{errors}
18
21
  oauth_keys:
19
22
  missing:
20
23
  one: 'Missing required oauth field in manifest: %{missing_keys}'
@@ -5,6 +5,7 @@ title: "Apps Support"
5
5
  packages:
6
6
  - default
7
7
  - apps_support
8
+ - classic
8
9
 
9
10
  parts:
10
11
  - translation:
@@ -15,6 +16,10 @@ parts:
15
16
  key: "txt.apps.admin.error.app_build.jshint.other"
16
17
  title: "App builder job: JSHint error messages"
17
18
  value: "JSHint errors in %{file}: %{errors}"
19
+ - translation:
20
+ key: "txt.apps.admin.error.app_build.missing_location_and_requirements"
21
+ title: "App builder job: missing location and requirements error"
22
+ value: "Missing app location or requirements"
18
23
  - translation:
19
24
  key: "txt.apps.admin.error.app_build.manifest_not_json"
20
25
  title: "App builder job: manifest is invalid JSON error"
@@ -23,6 +28,10 @@ parts:
23
28
  key: "txt.apps.admin.error.app_build.missing_manifest"
24
29
  title: "App builder job: missing manifest error"
25
30
  value: "Could not find manifest.json"
31
+ - translation:
32
+ key: "txt.apps.admin.error.app_build.missing_requirements"
33
+ title: "App builder job: missing requirements error"
34
+ value: "Could not find requirements.json"
26
35
  - translation:
27
36
  key: "txt.apps.admin.error.app_build.manifest_keys.missing.one"
28
37
  title: "App builder job: missing manifest fields error"
@@ -31,6 +40,10 @@ parts:
31
40
  key: "txt.apps.admin.error.app_build.manifest_keys.missing.other"
32
41
  title: "App builder job: missing manifest fields error"
33
42
  value: "Missing required fields in manifest: %{missing_keys}"
43
+ - translation:
44
+ key: "txt.apps.admin.error.app_build.requirements_not_json"
45
+ title: "App builder job: requirements file is invalid JSON error"
46
+ value: "requirements.json is not proper JSON. %{errors}"
34
47
  - translation:
35
48
  key: "txt.apps.admin.error.app_build.oauth_keys.missing.one"
36
49
  title: "App builder job: missing oauth fields error"
@@ -3,20 +3,22 @@ module ZendeskAppsSupport
3
3
  require 'zendesk_apps_support/sass_functions'
4
4
  require 'zendesk_apps_support/engine'
5
5
 
6
- autoload :AppFile, 'zendesk_apps_support/app_file'
7
- autoload :BuildTranslation, 'zendesk_apps_support/build_translation'
8
- autoload :I18n, 'zendesk_apps_support/i18n'
9
- autoload :Package, 'zendesk_apps_support/package'
10
- autoload :AppVersion, 'zendesk_apps_support/app_version'
11
- autoload :StylesheetCompiler, 'zendesk_apps_support/stylesheet_compiler'
6
+ autoload :AppFile, 'zendesk_apps_support/app_file'
7
+ autoload :BuildTranslation, 'zendesk_apps_support/build_translation'
8
+ autoload :I18n, 'zendesk_apps_support/i18n'
9
+ autoload :Package, 'zendesk_apps_support/package'
10
+ autoload :AppVersion, 'zendesk_apps_support/app_version'
11
+ autoload :StylesheetCompiler, 'zendesk_apps_support/stylesheet_compiler'
12
12
 
13
13
  module Validations
14
14
  autoload :ValidationError, 'zendesk_apps_support/validations/validation_error'
15
+ autoload :Package, 'zendesk_apps_support/validations/package'
15
16
  autoload :Manifest, 'zendesk_apps_support/validations/manifest'
16
17
  autoload :Source, 'zendesk_apps_support/validations/source'
17
18
  autoload :Templates, 'zendesk_apps_support/validations/templates'
18
19
  autoload :Translations, 'zendesk_apps_support/validations/translations'
19
20
  autoload :JSHintValidationError, 'zendesk_apps_support/validations/validation_error'
20
21
  autoload :Stylesheets, 'zendesk_apps_support/validations/stylesheets'
22
+ autoload :Requirements, 'zendesk_apps_support/validations/requirements'
21
23
  end
22
24
  end
@@ -8,7 +8,7 @@ module ZendeskAppsSupport
8
8
 
9
9
  DEFAULT_LAYOUT = Erubis::Eruby.new( File.read(File.expand_path('../assets/default_template.html.erb', __FILE__)) )
10
10
  DEFAULT_SCSS = File.read(File.expand_path('../assets/default_styles.scss', __FILE__))
11
- SRC_TEMPLATE = Erubis::Eruby.new( File.read(File.expand_path('../assets/src.js.erb', __FILE__)) )
11
+ SRC_TEMPLATE = Erubis::Eruby.new( File.read(File.expand_path('../assets/src.js.erb', __FILE__)) )
12
12
 
13
13
  attr_reader :root, :warnings
14
14
 
@@ -18,11 +18,24 @@ module ZendeskAppsSupport
18
18
  end
19
19
 
20
20
  def validate
21
- Validations::Manifest.call(self) +
22
- Validations::Source.call(self) +
23
- Validations::Templates.call(self) +
24
- Validations::Translations.call(self) +
25
- Validations::Stylesheets.call(self)
21
+ [].tap do |errors|
22
+
23
+ errors << Validations::Package.call(self)
24
+ errors << Validations::Manifest.call(self)
25
+ errors << Validations::Translations.call(self)
26
+
27
+ if has_location?
28
+ errors << Validations::Source.call(self)
29
+ errors << Validations::Templates.call(self)
30
+ errors << Validations::Stylesheets.call(self)
31
+ end
32
+
33
+ if has_requirements?
34
+ errors << Validations::Requirements.call(self)
35
+ end
36
+
37
+ errors.flatten!
38
+ end
26
39
  end
27
40
 
28
41
  def files
@@ -38,11 +51,15 @@ module ZendeskAppsSupport
38
51
  end
39
52
 
40
53
  def manifest_json
41
- JSON.parse(File.read(File.join(root, "manifest.json")), :symbolize_names => true)
54
+ read_json("manifest.json")
55
+ end
56
+
57
+ def requirements_json
58
+ read_json("requirements.json")
42
59
  end
43
60
 
44
61
  def translations
45
- JSON.parse(File.read(File.join(root, "translations/en.json")))
62
+ read_json("translations/en.json", false)
46
63
  end
47
64
 
48
65
  def app_translations
@@ -51,7 +68,7 @@ module ZendeskAppsSupport
51
68
 
52
69
  def readified_js(app_name, app_id, asset_url_prefix, settings={})
53
70
  manifest = manifest_json
54
- source = File.read(File.join(root, "app.js"))
71
+ source = read_file("app.js")
55
72
  name = app_name || manifest[:name] || 'Local App'
56
73
  location = manifest[:location]
57
74
  app_class_name = "app-#{app_id}"
@@ -81,6 +98,18 @@ module ZendeskAppsSupport
81
98
  customer_css = File.exist?(css_file) ? File.read(css_file) : ""
82
99
  end
83
100
 
101
+ def has_location?
102
+ manifest_json[:location]
103
+ end
104
+
105
+ def has_requirements?
106
+ !requirements_json.nil?
107
+ end
108
+
109
+ def is_requirements_only?
110
+ has_requirements? && !has_location?
111
+ end
112
+
84
113
  private
85
114
 
86
115
  def compiled_templates(app_id, asset_url_prefix)
@@ -112,5 +141,17 @@ module ZendeskAppsSupport
112
141
  end
113
142
  files
114
143
  end
144
+
145
+ def read_file(path)
146
+ file_path = File.join(root, path)
147
+ File.read(File.join(root, path))
148
+ end
149
+
150
+ def read_json(path, symbolize_names = true)
151
+ file = read_file(path)
152
+ unless file.nil?
153
+ JSON.parse(read_file(path), :symbolize_names => symbolize_names)
154
+ end
155
+ end
115
156
  end
116
157
  end
@@ -4,7 +4,7 @@ module ZendeskAppsSupport
4
4
  module Validations
5
5
  module Manifest
6
6
 
7
- REQUIRED_MANIFEST_FIELDS = %w( author defaultLocale location frameworkVersion ).freeze
7
+ REQUIRED_MANIFEST_FIELDS = %w( author defaultLocale frameworkVersion ).freeze
8
8
  OAUTH_REQUIRED_FIELDS = %w( client_id client_secret authorize_uri access_token_uri ).freeze
9
9
  LOCATIONS_AVAILABLE = %w( top_bar nav_bar ticket_sidebar new_ticket_sidebar user_sidebar ).freeze
10
10
  TYPES_AVAILABLE = %W( text password checkbox url number multiline hidden ).freeze
@@ -16,18 +16,20 @@ module ZendeskAppsSupport
16
16
  return [ValidationError.new(:missing_manifest)] unless manifest
17
17
 
18
18
  manifest = MultiJson.load(manifest.read)
19
-
20
19
  [].tap do |errors|
21
20
  errors << missing_keys_error(manifest)
22
21
  errors << default_locale_error(manifest, package)
23
- errors << invalid_location_error(manifest)
24
- errors << duplicate_location_error(manifest)
25
22
  errors << invalid_version_error(manifest, package)
26
23
  errors << oauth_error(manifest)
27
24
  errors << parameters_error(manifest)
28
25
  errors << invalid_hidden_parameter_error(manifest)
29
26
  errors << invalid_type_error(manifest)
30
27
  errors << name_as_parameter_name_error(manifest)
28
+
29
+ if package.has_location?
30
+ errors << invalid_location_error(manifest)
31
+ errors << duplicate_location_error(manifest)
32
+ end
31
33
  errors.compact!
32
34
  end
33
35
  rescue MultiJson::DecodeError => e
@@ -0,0 +1,24 @@
1
+ module ZendeskAppsSupport
2
+ module Validations
3
+ module Package
4
+
5
+ class <<self
6
+ def call(package)
7
+ [].tap do |errors|
8
+ errors << has_location_or_requirements(package)
9
+ errors.compact!
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def has_location_or_requirements(package)
16
+ if !package.has_location? && !package.has_requirements?
17
+ ValidationError.new('missing_location_and_requirements')
18
+ end
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,32 @@
1
+ require 'multi_json'
2
+
3
+ module ZendeskAppsSupport
4
+ module Validations
5
+ module Requirements
6
+
7
+ class <<self
8
+ def call(package)
9
+ requirements = package.files.find { |f| f.relative_path == 'requirements.json' }
10
+
11
+ errors = []
12
+
13
+ if requirements && !valid_json?(requirements)
14
+ errors << ValidationError.new(:requirements_not_json)
15
+ end
16
+
17
+ errors
18
+ end
19
+
20
+ private
21
+
22
+ def valid_json? json
23
+ MultiJson.load(json)
24
+ true
25
+ rescue MultiJson::DecodeError
26
+ false
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ def read_fixture_file(file)
2
+ File.read("#{File.dirname(__FILE__)}/validations/fixture/#{file}")
3
+ end
@@ -0,0 +1,22 @@
1
+ {
2
+ "targets": {
3
+ "jira_story_target": {
4
+ "title": "blah",
5
+ "type": "jira_target",
6
+ "active": true,
7
+ "target_url": "http://example.org"
8
+ }
9
+ },
10
+
11
+ "triggers": {
12
+ "submit_trigger": {
13
+ "title": "whatever",
14
+ "position": "whatever",
15
+ "active": true,
16
+ "conditions": {
17
+ "all": [{ "field": "status", "operator": "less_than", "value": "solved" }]
18
+ },
19
+ "actions" : []
20
+ }
21
+ }
22
+ }
@@ -15,7 +15,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
15
15
  def create_package(parameter_hash)
16
16
  params = default_required_params(parameter_hash)
17
17
  manifest = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(params))
18
- mock('Package', :files => [manifest])
18
+ mock('Package', :files => [manifest], :has_location? => true)
19
19
  end
20
20
 
21
21
  it 'should have an error when manifest.json is missing' do
@@ -28,16 +28,16 @@ describe ZendeskAppsSupport::Validations::Manifest do
28
28
 
29
29
  it 'should have an error when required field is missing' do
30
30
  manifest = mock('AppFile', :relative_path => 'manifest.json', :read => "{}")
31
- package = mock('Package', :files => [manifest])
31
+ package = mock('Package', :files => [manifest], :has_location? => true)
32
32
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
33
33
 
34
- errors.first().to_s.should eql 'Missing required fields in manifest: author, defaultLocale, location, frameworkVersion'
34
+ errors.first().to_s.should eql 'Missing required fields in manifest: author, defaultLocale, frameworkVersion'
35
35
  end
36
36
 
37
37
  it 'should have an error when the defaultLocale is invalid' do
38
38
  manifest = { 'defaultLocale' => 'pt-BR-1' }
39
39
  manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
40
- package = mock('Package', :files => [manifest_file])
40
+ package = mock('Package', :files => [manifest_file], :has_location? => true)
41
41
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
42
42
 
43
43
  locale_error = errors.find { |e| e.to_s =~ /default locale/ }
@@ -48,7 +48,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
48
48
  manifest = { 'defaultLocale' => 'pt' }
49
49
  manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
50
50
  translation_files = mock('AppFile', :relative_path => 'translations/en.json')
51
- package = mock('Package', :files => [manifest_file], :translation_files => [translation_files])
51
+ package = mock('Package', :files => [manifest_file], :has_location? => true, :translation_files => [translation_files])
52
52
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
53
53
 
54
54
  locale_error = errors.find { |e| e.to_s =~ /Missing translation file/ }
@@ -58,7 +58,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
58
58
  it 'should have an error when the location is invalid' do
59
59
  manifest = { 'location' => ['ticket_sidebar', 'a_invalid_location'] }
60
60
  manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
61
- package = mock('Package', :files => [manifest_file])
61
+ package = mock('Package', :files => [manifest_file], :has_location? => true)
62
62
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
63
63
 
64
64
  locations_error = errors.find { |e| e.to_s =~ /invalid location/ }
@@ -68,7 +68,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
68
68
  it 'should have an error when there are duplicate locations' do
69
69
  manifest = { 'location' => ['ticket_sidebar', 'ticket_sidebar'] }
70
70
  manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
71
- package = mock('Package', :files => [manifest_file])
71
+ package = mock('Package', :files => [manifest_file], :has_location? => true)
72
72
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
73
73
 
74
74
  locations_error = errors.find { |e| e.to_s =~ /duplicate/ }
@@ -78,7 +78,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
78
78
  it 'should have an error when the version is not supported' do
79
79
  manifest = { 'frameworkVersion' => '0.7' }
80
80
  manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
81
- package = mock('Package', :files => [manifest_file])
81
+ package = mock('Package', :files => [manifest_file], :has_location? => true)
82
82
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
83
83
 
84
84
  version_error = errors.find { |e| e.to_s =~ /not a valid framework version/ }
@@ -95,7 +95,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
95
95
  }
96
96
 
97
97
  manifest_file = mock('AppFile', :relative_path => 'manifest.json', :read => JSON.dump(manifest))
98
- package = mock('Package', :files => [manifest_file])
98
+ package = mock('Package', :files => [manifest_file], :has_location? => true)
99
99
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
100
100
 
101
101
  hidden_params_error = errors.find { |e| e.to_s =~ /set to hidden and cannot be required/ }
@@ -104,7 +104,7 @@ describe ZendeskAppsSupport::Validations::Manifest do
104
104
 
105
105
  it 'should have an error when manifest is not a valid json' do
106
106
  manifest = mock('AppFile', :relative_path => 'manifest.json', :read => "}")
107
- package = mock('Package', :files => [manifest])
107
+ package = mock('Package', :files => [manifest], :has_location? => true)
108
108
  errors = ZendeskAppsSupport::Validations::Manifest.call(package)
109
109
 
110
110
  errors.first().to_s.should =~ /^manifest is not proper JSON/
@@ -0,0 +1,23 @@
1
+ require 'zendesk_apps_support'
2
+ require 'spec_helper'
3
+
4
+ describe ZendeskAppsSupport::Validations::Requirements do
5
+
6
+ it 'creates an error when the file is not valid JSON' do
7
+ requirements = mock('AppFile', :relative_path => 'requirements.json', :read => "{")
8
+ package = mock('Package', :files => [requirements])
9
+ errors = ZendeskAppsSupport::Validations::Requirements.call(package)
10
+
11
+ errors.first.key.should == :requirements_not_json
12
+ end
13
+
14
+ it "creates no error when the file is valid JSON" do
15
+ requirements = mock('AppFile', :relative_path => 'requirements.json',
16
+ :read => read_fixture_file('requirements.json'))
17
+ package = mock('Package', :files => [requirements])
18
+ errors = ZendeskAppsSupport::Validations::Requirements.call(package)
19
+
20
+ expect(errors).to be_empty
21
+ end
22
+
23
+ end
@@ -1,9 +1,7 @@
1
1
  require 'zendesk_apps_support'
2
+ require 'spec_helper'
2
3
  require 'json'
3
4
 
4
- def read_fixture_file(file)
5
- File.read("#{File.dirname(__FILE__)}/fixture/#{file}")
6
- end
7
5
 
8
6
  describe ZendeskAppsSupport::Validations::Translations do
9
7
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zendesk_apps_support
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.0
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James A. Rosen
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-01-15 00:00:00.000000000 Z
14
+ date: 2014-02-04 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: i18n
@@ -144,6 +144,8 @@ files:
144
144
  - lib/zendesk_apps_support/sass_functions.rb
145
145
  - lib/zendesk_apps_support/stylesheet_compiler.rb
146
146
  - lib/zendesk_apps_support/validations/manifest.rb
147
+ - lib/zendesk_apps_support/validations/package.rb
148
+ - lib/zendesk_apps_support/validations/requirements.rb
147
149
  - lib/zendesk_apps_support/validations/source.rb
148
150
  - lib/zendesk_apps_support/validations/stylesheets.rb
149
151
  - lib/zendesk_apps_support/validations/templates.rb
@@ -166,10 +168,13 @@ files:
166
168
  - spec/build_translation_spec.rb
167
169
  - spec/i18n_spec.rb
168
170
  - spec/package_spec.rb
171
+ - spec/spec_helper.rb
169
172
  - spec/validations/fixture/invalid_en.json
173
+ - spec/validations/fixture/requirements.json
170
174
  - spec/validations/fixture/valid_en.json
171
175
  - spec/validations/jshint_error_spec.rb
172
176
  - spec/validations/manifest_spec.rb
177
+ - spec/validations/requirements_spec.rb
173
178
  - spec/validations/source_spec.rb
174
179
  - spec/validations/stylesheets_spec.rb
175
180
  - spec/validations/templates_spec.rb
@@ -212,10 +217,13 @@ test_files:
212
217
  - spec/build_translation_spec.rb
213
218
  - spec/i18n_spec.rb
214
219
  - spec/package_spec.rb
220
+ - spec/spec_helper.rb
215
221
  - spec/validations/fixture/invalid_en.json
222
+ - spec/validations/fixture/requirements.json
216
223
  - spec/validations/fixture/valid_en.json
217
224
  - spec/validations/jshint_error_spec.rb
218
225
  - spec/validations/manifest_spec.rb
226
+ - spec/validations/requirements_spec.rb
219
227
  - spec/validations/source_spec.rb
220
228
  - spec/validations/stylesheets_spec.rb
221
229
  - spec/validations/templates_spec.rb