marty 0.5.27 → 0.5.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/components/marty/grid.rb +0 -4
- data/app/models/marty/import_type.rb +9 -1
- data/lib/marty/permissions.rb +50 -52
- data/lib/marty/version.rb +1 -1
- data/spec/models/import_type_spec.rb +77 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6599f34a4823efc8be3d05feef0d3fc937219e6
|
4
|
+
data.tar.gz: 41c960a54860d1c94d2138148725fdc5575c33f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7b66c7ca4c79c298aae4a82f38a20d856c83c94800575328062aba071aeb4f21f2f63b81a1af77a6ae2106eac838e694c1a9fcf0041b27922d03b3715afb88b
|
7
|
+
data.tar.gz: 6394925740fc4739765409d35205a57b6fc20fafa6089686b5438b35a49839c0c2c013eb8ccf843c7b45cff6639f55b5288b68dc6b94044f88e789f08bed1586
|
@@ -19,6 +19,14 @@ class Marty::ImportType < Marty::Base
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
before_validation do
|
23
|
+
# Fix issue with blank strings in popup edit form or grid
|
24
|
+
# being interpreted as a function
|
25
|
+
self.cleaner_function = nil if self.cleaner_function.blank?
|
26
|
+
self.validation_function = nil if self.validation_function.blank?
|
27
|
+
self.preprocess_function = nil if self.preprocess_function.blank?
|
28
|
+
end
|
29
|
+
|
22
30
|
belongs_to :role
|
23
31
|
|
24
32
|
validates_presence_of :name, :db_model_name, :role_id
|
@@ -26,7 +34,7 @@ class Marty::ImportType < Marty::Base
|
|
26
34
|
validates_with ImportTypeValidator
|
27
35
|
|
28
36
|
def get_model_class
|
29
|
-
db_model_name.constantize
|
37
|
+
db_model_name.constantize if db_model_name
|
30
38
|
end
|
31
39
|
|
32
40
|
def allow_import?
|
data/lib/marty/permissions.rb
CHANGED
@@ -1,64 +1,62 @@
|
|
1
|
-
module Marty
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
1
|
+
module Marty::Permissions
|
2
|
+
# Make sure there are admin and user_manager roles,
|
3
|
+
# even if hosting app doesn't define them
|
4
|
+
REQ_ROLES = [:admin, :user_manager]
|
5
|
+
ALL_ROLES = Rails.configuration.marty.roles.to_set.merge(REQ_ROLES)
|
6
|
+
|
7
|
+
# Call using following format
|
8
|
+
# has_marty_permissions create: [:dev, :admin],
|
9
|
+
# read: :any,
|
10
|
+
# update: :admin,
|
11
|
+
# delete: []
|
12
|
+
#
|
13
|
+
# :any gives permission to the action if user belongs to at least 1 role
|
14
|
+
def has_marty_permissions(attrs)
|
15
|
+
raise "bad attrs" unless attrs.is_a?(Hash)
|
16
|
+
raise "unknown role" unless
|
17
|
+
attrs.values.flatten.to_set.subset? (ALL_ROLES << :any)
|
18
|
+
|
19
|
+
self.define_singleton_method(:marty_permissions) { attrs }
|
20
|
+
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
+
def current_user_roles
|
23
|
+
roles = Mcfly.whodunnit.roles rescue []
|
24
|
+
roles.map {|r| r.name.to_sym}.to_set
|
25
|
+
end
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
roles.map {|r| r.name.to_sym}.to_set
|
26
|
-
end
|
27
|
+
def can_perform_action?(action)
|
28
|
+
return false unless self.respond_to?(:marty_permissions)
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
+
roles = self.current_user_roles
|
31
|
+
roles = roles << :any if self.has_any_perm?
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
+
aroles = self.marty_permissions[action.to_sym] || []
|
34
|
+
# TODO: Use code below when switching to Ruby 2.1
|
35
|
+
# Set[ *aroles].intersect? roles.to_set
|
36
|
+
(Set[ *aroles] & roles.to_set).length > 0
|
37
|
+
end
|
33
38
|
|
34
|
-
|
35
|
-
|
36
|
-
# Set[ *aroles].intersect? roles.to_set
|
37
|
-
(Set[ *aroles] & roles.to_set).length > 0
|
38
|
-
end
|
39
|
+
def can_perform_actions
|
40
|
+
return [] unless self.respond_to?(:marty_permissions)
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
roles = self.current_user_roles
|
43
|
+
roles = roles << :any if self.has_any_perm?
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
+
self.marty_permissions.map { |action, aroles|
|
46
|
+
# TODO: Use code below when switching to Ruby 2.1
|
47
|
+
#action if Set[ *aroles].intersect? roles.to_set
|
48
|
+
action if (Set[ *aroles] & roles.to_set).length > 0
|
49
|
+
}.compact
|
50
|
+
end
|
45
51
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
}.compact
|
52
|
+
# generate has_xxx_perm? methods for all permissions.
|
53
|
+
Rails.configuration.marty.roles.each { |role|
|
54
|
+
define_method("has_#{role}_perm?") do
|
55
|
+
current_user_roles.member? role
|
51
56
|
end
|
57
|
+
}
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
define_method("has_#{role}_perm?") do
|
56
|
-
current_user_roles.member? role
|
57
|
-
end
|
58
|
-
}
|
59
|
-
|
60
|
-
def has_any_perm?
|
61
|
-
!(current_user_roles & ALL_ROLES).empty?
|
62
|
-
end
|
59
|
+
def has_any_perm?
|
60
|
+
!(current_user_roles & ALL_ROLES).empty?
|
63
61
|
end
|
64
62
|
end
|
data/lib/marty/version.rb
CHANGED
@@ -0,0 +1,77 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Marty
|
4
|
+
class Marty::ARTestModel < ActiveRecord::Base
|
5
|
+
def self.import_cleaner
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.import_validator
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Marty::TestModel
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ImportType do
|
16
|
+
let(:role_id) { Marty::Role.first.id }
|
17
|
+
|
18
|
+
before(:each) do
|
19
|
+
@import = ImportType.new
|
20
|
+
@import.name = "Test1"
|
21
|
+
@import.db_model_name = "Marty::ARTestModel"
|
22
|
+
@import.role_id = role_id
|
23
|
+
@import.save!
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "validations" do
|
27
|
+
it "require name, db_model and role" do
|
28
|
+
it = ImportType.new
|
29
|
+
expect(it).to_not be_valid
|
30
|
+
expect(it.errors[:name].any?).to be true
|
31
|
+
expect(it.errors[:db_model_name].any?).to be true
|
32
|
+
expect(it.errors[:role_id].any?).to be true
|
33
|
+
end
|
34
|
+
|
35
|
+
it "require a unique name" do
|
36
|
+
it = ImportType.new
|
37
|
+
it.name = "Test1"
|
38
|
+
it.db_model_name = "Marty::ARTestModel"
|
39
|
+
it.role_id = role_id
|
40
|
+
expect(it).to_not be_valid
|
41
|
+
expect(it.errors[:name].any?).to be true
|
42
|
+
end
|
43
|
+
|
44
|
+
it "require an ActiveRecord model for the db_model_name" do
|
45
|
+
it = ImportType.new
|
46
|
+
it.name = "Test1"
|
47
|
+
it.db_model_name = "Marty::TestModel"
|
48
|
+
it.role_id = role_id
|
49
|
+
expect(it).to_not be_valid
|
50
|
+
expect(it.errors[:base][0]).to eq "bad model name"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "do not fail on blank strings for functions" do
|
54
|
+
@import.cleaner_function = ""
|
55
|
+
@import.validation_function = " "
|
56
|
+
@import.preprocess_function = " "
|
57
|
+
|
58
|
+
expect(@import).to be_valid
|
59
|
+
@import.save!
|
60
|
+
expect(@import.cleaner_function).to be nil
|
61
|
+
expect(@import.validation_function).to be nil
|
62
|
+
expect(@import.preprocess_function).to be nil
|
63
|
+
end
|
64
|
+
|
65
|
+
it "require valid functions for cleaner/validation/preprocess" do
|
66
|
+
@import.cleaner_function = "import_cleaner"
|
67
|
+
@import.validation_function = "import_validator"
|
68
|
+
expect(@import).to be_valid
|
69
|
+
|
70
|
+
@import.preprocess_function = "missing_func"
|
71
|
+
expect(@import).to_not be_valid
|
72
|
+
expect(@import.errors[:base][0]).
|
73
|
+
to eq "unknown class method missing_func"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
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.
|
4
|
+
version: 0.5.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arman Bostani
|
@@ -14,7 +14,7 @@ authors:
|
|
14
14
|
autorequire:
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
|
-
date: 2016-02-
|
17
|
+
date: 2016-02-09 00:00:00.000000000 Z
|
18
18
|
dependencies:
|
19
19
|
- !ruby/object:Gem::Dependency
|
20
20
|
name: pg
|
@@ -541,6 +541,7 @@ files:
|
|
541
541
|
- spec/lib/xl_styles_spec.rb
|
542
542
|
- spec/models/api_auth_spec.rb
|
543
543
|
- spec/models/config_spec.rb
|
544
|
+
- spec/models/import_type_spec.rb
|
544
545
|
- spec/models/posting_spec.rb
|
545
546
|
- spec/models/promise_spec.rb
|
546
547
|
- spec/models/script_spec.rb
|