marty 0.5.23 → 0.5.24

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: 6b8269306b02f3bb10f11bd047f2e783cd872aab
4
- data.tar.gz: 2f155d91d17c1762e9d3a3afb39b42767cad4c66
3
+ metadata.gz: a4034d6478ed76aa60f6a538c7b2e4162052101a
4
+ data.tar.gz: 76aac79be02a18505f8ac6d917ffc585894c9b3d
5
5
  SHA512:
6
- metadata.gz: 6f4f8bc5924257516deebc50da556db5610de1847cf9ad5eb1897bd20121e26cdd4c9b4763f5a60cad8af76559f70cc2ba8d95d7858cb0345aee1da8e71eb21b
7
- data.tar.gz: 26f820934252d3b4896e98fb334a345e803cb673666639022c112bcf2bcbea1fe91de39c45f3e7d29ab6e4cf2ed2a2aa740f96fb3b82447b5cd5e782f2278a73
6
+ metadata.gz: 809d837cfd29bbcda4d114e4db80b2c157139f0bbc70099d412684fed373fab2b74a8e6ed33c352e78e72392707d77b2b1fc1dcbc7f5227b1a3f913dac9f6a82
7
+ data.tar.gz: eea002896bfbbce23e51a2f710f21247900f802d594b183a8dfcd9d26792cf407d691f6c90bebf7ef7c29af90ab4238d91dee5369f1519194079cae050f5e509
@@ -0,0 +1,72 @@
1
+ class Marty::ConfigView < Marty::Grid
2
+ has_marty_permissions \
3
+ create: :admin,
4
+ read: :admin,
5
+ update: :admin,
6
+ delete: :admin
7
+
8
+ include Marty::Extras::Layout
9
+
10
+ def configure(c)
11
+ super
12
+
13
+ c.title = I18n.t('config', default: "Config")
14
+ c.model = "Marty::Config"
15
+ c.columns = [:key, :value, :description]
16
+
17
+ c.enable_extended_search = false
18
+ c.data_store.sorters = {property: :key, direction: 'ASC'}
19
+ end
20
+
21
+ # need a getter / setter to call the []= and [] methods now
22
+ # since value is no longer stored as is
23
+ def my_jsonb_getter
24
+ lambda { |r| Marty::Config[r.key].to_json }
25
+ end
26
+
27
+ def my_jsonb_setter
28
+ lambda { |r, v|
29
+ decoded = ActiveSupport::JSON.decode(v) rescue nil
30
+ r.set_value(decoded)
31
+ }
32
+ end
33
+
34
+ def default_fields_for_forms
35
+ [
36
+ :key,
37
+ {
38
+ name: :value,
39
+ width: "100%",
40
+ height: 150,
41
+ xtype: :textareafield,
42
+ auto_scroll: true,
43
+ spellcheck: false,
44
+ allow_blank: false,
45
+ field_style: {
46
+ font_family: 'courier new',
47
+ font_size: '12px'
48
+ },
49
+ getter: my_jsonb_getter,
50
+ setter: my_jsonb_setter,
51
+ },
52
+ textarea_field(:description),
53
+ ]
54
+ end
55
+
56
+ column :key do |c|
57
+ c.flex = 1
58
+ end
59
+
60
+ column :value do |c|
61
+ c.flex = 3
62
+ c.getter = my_jsonb_getter
63
+ c.setter = my_jsonb_setter
64
+ end
65
+ column :description do |c|
66
+ c.flex = 1
67
+ c.width = 200
68
+ end
69
+
70
+ end
71
+
72
+ ConfigView = Marty::ConfigView
@@ -41,6 +41,20 @@ module Marty
41
41
  hbox({flex: 1, border: false}.merge(params))
42
42
  end
43
43
 
44
+ def textarea_field(name, options={})
45
+ {
46
+ name: name,
47
+ width: "100%",
48
+ height: 150,
49
+ xtype: :textareafield,
50
+ auto_scroll: true,
51
+ spellcheck: false,
52
+ field_style: {
53
+ font_family: 'courier new',
54
+ font_size: '12px'
55
+ },
56
+ } + options
57
+ end
44
58
  end
45
59
  end
46
60
  end
@@ -7,6 +7,7 @@ require 'marty/import_type_view'
7
7
  require 'marty/user_view'
8
8
  require 'marty/promise_view'
9
9
  require 'marty/api_auth_view'
10
+ require 'marty/config_view'
10
11
 
11
12
  class Marty::MainAuthApp < Marty::AuthApp
12
13
  extend ::Marty::Permissions
@@ -53,6 +54,7 @@ class Marty::MainAuthApp < Marty::AuthApp
53
54
  menu: [
54
55
  :import_type_view,
55
56
  :user_view,
57
+ :config_view,
56
58
  :api_auth_view,
57
59
  :reload_scripts,
58
60
  ],
@@ -150,6 +152,14 @@ class Marty::MainAuthApp < Marty::AuthApp
150
152
  !self.class.has_user_manager_perm?
151
153
  end
152
154
 
155
+ action :config_view do |a|
156
+ a.text = I18n.t("config_view")
157
+ a.handler = :netzke_load_component_by_action
158
+ a.icon = :cog
159
+ a.disabled = !self.class.has_admin_perm? &&
160
+ !self.class.has_user_manager_perm?
161
+ end
162
+
153
163
  action :api_auth_view do |a|
154
164
  a.text = I18n.t("api_auth_view", default: "API Authorization")
155
165
  a.handler = :netzke_load_component_by_action
@@ -256,6 +266,7 @@ class Marty::MainAuthApp < Marty::AuthApp
256
266
  end
257
267
  component :import_type_view
258
268
  component :user_view
269
+ component :config_view
259
270
  component :api_auth_view do |c|
260
271
  c.disabled = Marty::Util.warped?
261
272
  end
@@ -0,0 +1,52 @@
1
+ class Marty::Config < Marty::Base
2
+ class ConfigValidator < ActiveModel::Validator
3
+ def validate(entry)
4
+ v = entry.get_value
5
+ entry.errors[:base] = "bad JSON value" if !v
6
+ v
7
+ end
8
+ end
9
+
10
+ validates_presence_of :key, :value
11
+ validates_uniqueness_of :key
12
+ validates_with ConfigValidator
13
+
14
+ delorean_fn :lookup, sig: 1 do
15
+ |key|
16
+ self[key]
17
+ end
18
+
19
+ def get_value
20
+ self.value[0]
21
+ end
22
+
23
+ def set_value(v)
24
+ self.value = [v]
25
+ end
26
+
27
+ def self.[]=(key, value)
28
+ entry = find_by_key(key)
29
+ if !entry
30
+ entry = self.new
31
+ entry.key = key
32
+ end
33
+ entry.set_value(value)
34
+ entry.save!
35
+
36
+ value
37
+ end
38
+
39
+ def self.[](key)
40
+ entry = find_by_key(key)
41
+ entry and entry.get_value
42
+ end
43
+
44
+ def self.del(key)
45
+ entry = find_by_key(key)
46
+ if entry
47
+ result = entry.get_value
48
+ entry.destroy
49
+ result
50
+ end
51
+ end
52
+ end
@@ -8,6 +8,8 @@ class Marty::User < Marty::Base
8
8
  validates_format_of :login, :with => /\A[a-z0-9_\-@\.]*\z/i
9
9
  validates_length_of :login, :firstname, :lastname, maximum: 100
10
10
 
11
+ MARTY_IMPORT_UNIQUENESS = [:login]
12
+
11
13
  has_many :user_roles, dependent: :destroy
12
14
  has_many :roles, through: :user_roles
13
15
 
@@ -8,6 +8,7 @@ en:
8
8
  fields: Fields
9
9
  updated_at: Updated At
10
10
  user_view: User Management
11
+ config_view: Configuration
11
12
  reports: Reports
12
13
  import_synonym: Import Synonyms
13
14
  import_type: Import Types
@@ -0,0 +1,11 @@
1
+ class CreateMartyConfigs < ActiveRecord::Migration
2
+ def change
3
+ create_table :marty_configs do |t|
4
+ t.timestamps null: false
5
+
6
+ t.string :key
7
+ t.jsonb :value
8
+ t.text :description
9
+ end
10
+ end
11
+ end
data/lib/marty/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Marty
2
- VERSION = "0.5.23"
2
+ VERSION = "0.5.24"
3
3
  end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ module Marty
4
+ describe Config do
5
+ describe "validations" do
6
+ it "should return valid config value based on key" do
7
+ Marty::Config["TEST 1"] = 2
8
+ expect(Marty::Config.lookup("TEST 1")).to eq(2)
9
+ expect(Marty::Config["TEST 1"]).to eq(2)
10
+ end
11
+
12
+ def testval(val)
13
+ Marty::Config["testval"] = val
14
+ expect(Marty::Config.lookup("testval")).to eq(val)
15
+ expect(Marty::Config["testval"]).to eq(val)
16
+ end
17
+
18
+ it "should handle various structures correctly" do
19
+ testval("[1,2,3]")
20
+ testval("[1,\"2,3\"]")
21
+ testval([1,2,3])
22
+ testval([1,"2,3"])
23
+
24
+ testval({ "key1" => [1,2,3], "keystr" => { "val" => "val"}})
25
+ testval(%Q({ "key1" : [1,2,3], "keystr" : { "val" : "val"}}))
26
+
27
+ testval("123456.1234")
28
+ testval("a string")
29
+ testval("\"a string\"")
30
+ end
31
+
32
+ it "should return nil config value for non-existing key" do
33
+ expect(Marty::Config.lookup("TEST 2")).to eq(nil)
34
+ expect(Marty::Config["TEST 2"]).to eq(nil)
35
+ end
36
+
37
+ it "should handle del" do
38
+ (0..10).each { |i|
39
+ v = {"i" => i}
40
+ Marty::Config["k#{i}"] = v
41
+ expect(Marty::Config["k#{i}"]).to eq(v)
42
+ }
43
+
44
+ (0..10).each { |i|
45
+ Marty::Config.del("k#{i}")
46
+ expect(Marty::Config["k#{i}"]).to eq(nil)
47
+ }
48
+ end
49
+ end
50
+ end
51
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.23
4
+ version: 0.5.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arman Bostani
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-12-28 00:00:00.000000000 Z
15
+ date: 2016-01-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: pg
@@ -161,6 +161,7 @@ files:
161
161
  - app/components/marty/api_auth_view.rb
162
162
  - app/components/marty/auth_app.rb
163
163
  - app/components/marty/auth_app/javascripts/auth_app.js
164
+ - app/components/marty/config_view.rb
164
165
  - app/components/marty/extras/layout.rb
165
166
  - app/components/marty/extras/misc.rb
166
167
  - app/components/marty/form.rb
@@ -361,6 +362,7 @@ files:
361
362
  - app/helpers/marty/script_set.rb
362
363
  - app/models/marty/api_auth.rb
363
364
  - app/models/marty/base.rb
365
+ - app/models/marty/config.rb
364
366
  - app/models/marty/enum.rb
365
367
  - app/models/marty/import_type.rb
366
368
  - app/models/marty/posting.rb
@@ -395,6 +397,7 @@ files:
395
397
  - db/migrate/096_add_user_roles_to_import_types.rb
396
398
  - db/migrate/097_drop_versions.rb
397
399
  - db/migrate/098_create_marty_api_auths.rb
400
+ - db/migrate/099_create_marty_configs.rb
398
401
  - db/seeds.rb
399
402
  - gemini_deprecations.md
400
403
  - lib/marty.rb
@@ -533,6 +536,7 @@ files:
533
536
  - spec/lib/xl_spec.rb
534
537
  - spec/lib/xl_styles_spec.rb
535
538
  - spec/models/api_auth_spec.rb
539
+ - spec/models/config_spec.rb
536
540
  - spec/models/posting_spec.rb
537
541
  - spec/models/promise_spec.rb
538
542
  - spec/models/script_spec.rb