ez-permissions 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ez/permissions/dsl.rb +21 -15
- data/lib/ez/permissions/resource.rb +2 -2
- data/lib/ez/permissions/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6145e511809044ca7673cfd275fa009fbfad5a5dfccd9457469116bf6039a0ad
|
4
|
+
data.tar.gz: aaac5b48a4fa790de8df4f97ee86b4b42c52c5d130a24289c1876a298f7d1691
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d8bc79ec20592692ca6c4a62096c8a6d166dec53e3514f53da77271cf80c83292e3fd8dfc3bec25dd11771abe70b632e365b7a646aa597b1fc8f3e18a54b96
|
7
|
+
data.tar.gz: bd6f64a211c6b233c673a74ef2992531794045a56025d7fa6dbec8326290caeb3b1647109105408300a8a960f33f094fd5492cb79b8c324b5132cebce8b9408d
|
data/lib/ez/permissions/dsl.rb
CHANGED
@@ -26,33 +26,31 @@ module Ez
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def add(name, options = {})
|
29
|
-
if self.class.resource(name)
|
30
|
-
return message("[WARN] Ez::Permissions resource [#{name}] has been already defined!")
|
31
|
-
end
|
29
|
+
return message("Resource [#{name}] has been already defined!") if self.class.resource(name)
|
32
30
|
|
33
31
|
resource = Ez::Permissions::Resource.new(name, options)
|
34
32
|
|
33
|
+
@resources << resource
|
34
|
+
|
35
|
+
return unless seed_to_db(resource)
|
36
|
+
|
35
37
|
message(
|
36
|
-
"
|
37
|
-
|
38
|
+
"Resource [#{name}] has been successfully registred with actions: [#{resource.actions.join(', ')}]",
|
39
|
+
'SUCCESS'
|
38
40
|
)
|
39
|
-
|
40
|
-
@resources << resource
|
41
|
-
seed_to_db resource
|
42
41
|
end
|
43
42
|
|
44
43
|
private
|
45
44
|
|
46
|
-
def message(txt)
|
47
|
-
|
45
|
+
def message(txt, level = 'WARN')
|
46
|
+
return if Ez::Permissions.config.mute_stdout
|
47
|
+
|
48
|
+
STDOUT.puts("[#{level}] Ez::Permissions: #{txt}")
|
48
49
|
end
|
49
50
|
|
50
51
|
def seed_to_db(resource)
|
51
52
|
return unless try_db_connection
|
52
|
-
|
53
|
-
return unless ActiveRecord::Base.connection.data_source_exists?(Ez::Permissions.config.permissions_table_name)
|
54
|
-
|
55
|
-
return unless resource.actions
|
53
|
+
return unless check_permissions_table
|
56
54
|
|
57
55
|
resource.actions.each do |action|
|
58
56
|
Ez::Permissions::Permission.where(
|
@@ -65,7 +63,15 @@ module Ez
|
|
65
63
|
def try_db_connection
|
66
64
|
ActiveRecord::Base.connection
|
67
65
|
rescue ActiveRecord::NoDatabaseError
|
68
|
-
|
66
|
+
message('Database does not exist')
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_permissions_table
|
71
|
+
permissions_table = Ez::Permissions.config.permissions_table_name
|
72
|
+
return true if ActiveRecord::Base.connection.data_source_exists?(permissions_table)
|
73
|
+
|
74
|
+
message("Table #{permissions_table} does not exists. Please, check migrations")
|
69
75
|
false
|
70
76
|
end
|
71
77
|
end
|
@@ -10,7 +10,7 @@ module Ez
|
|
10
10
|
def initialize(name, options = {})
|
11
11
|
@name = name
|
12
12
|
@model = options.fetch(:model, nil)
|
13
|
-
@actions = process_actions(options.fetch(:actions,
|
13
|
+
@actions = process_actions(options.fetch(:actions, []))
|
14
14
|
end
|
15
15
|
|
16
16
|
def <=>(other)
|
@@ -20,7 +20,7 @@ module Ez
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def process_actions(actions)
|
23
|
-
return ACTIONS
|
23
|
+
return ACTIONS if actions.empty?
|
24
24
|
|
25
25
|
actions.map { |action| action == :crud ? ACTIONS : action }.flatten
|
26
26
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ez-permissions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Volodya Sveredyuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ez-core
|