cancancan-neo4j 1.3.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b821f07db8166fa92473a7d8924c9470bad5b9db
|
4
|
+
data.tar.gz: 48e04822f77521760f66645710c6225239e1fcd1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b82da9b848670f03c1de9b948389c89b011788d108d800dc70fb335dee87b5ac277cb05fdcdf0692de785b1b4eab4b470936898b854463c82ff4f8baa4f488d9
|
7
|
+
data.tar.gz: 5e4446edc1a3278ecbf06e94f4d98cefe0bfb20482d663a0aff497bb02bd989c9bdaa538d784c823dfce4ffe0f42f19f092851f27b491722f94a4d91dd948afa
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'cancancan/neo4j/cypher_constructor_helper'
|
2
2
|
require 'cancancan/neo4j/rule_cypher'
|
3
3
|
require 'cancancan/neo4j/cypher_constructor'
|
4
|
+
require 'cancancan/neo4j/single_rule_cypher'
|
4
5
|
|
5
6
|
module CanCan
|
6
7
|
module ModelAdapters
|
@@ -9,6 +10,9 @@ module CanCan
|
|
9
10
|
def database_records
|
10
11
|
return @model_class.where('false') if @rules.empty?
|
11
12
|
override_scope
|
13
|
+
if (rule = logical_single_can_rule)
|
14
|
+
return records_for_single_rule(rule)
|
15
|
+
end
|
12
16
|
records_for_multiple_rules.distinct
|
13
17
|
end
|
14
18
|
|
@@ -54,6 +58,17 @@ module CanCan
|
|
54
58
|
|
55
59
|
private
|
56
60
|
|
61
|
+
def logical_single_can_rule
|
62
|
+
return @rules.first if @rules.size == 1
|
63
|
+
return unless @rules.all?(&:base_behavior)
|
64
|
+
@rules.find { |rule| rule.conditions.blank? }
|
65
|
+
end
|
66
|
+
|
67
|
+
def records_for_single_rule(rule)
|
68
|
+
CanCanCan::Neo4j::SingleRuleCypher.new(rule, @model_class)
|
69
|
+
.records
|
70
|
+
end
|
71
|
+
|
57
72
|
def records_for_multiple_rules
|
58
73
|
con = CanCanCan::Neo4j::CypherConstructor.new(construct_cypher_options)
|
59
74
|
if (scope = con.scope)
|
@@ -22,11 +22,10 @@ module CanCanCan
|
|
22
22
|
.present?
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def path_end_var(relationship, conditions)
|
26
26
|
with_var = variable_in_path?(relationship, conditions)
|
27
27
|
target_class = relationship.target_class
|
28
|
-
|
29
|
-
path_node(target_class, var_label)
|
28
|
+
with_var ? var_name(target_class) : ''
|
30
29
|
end
|
31
30
|
end
|
32
31
|
end
|
@@ -16,7 +16,7 @@ module CanCanCan
|
|
16
16
|
def initialize_path
|
17
17
|
model_class = @options[:model_class]
|
18
18
|
var_label = CypherConstructorHelper.var_name(model_class)
|
19
|
-
var_label +=
|
19
|
+
var_label += index_sub_str
|
20
20
|
@options[:var_label] = var_label
|
21
21
|
@path = CypherConstructorHelper.path_node(model_class, var_label)
|
22
22
|
end
|
@@ -35,12 +35,18 @@ module CanCanCan
|
|
35
35
|
|
36
36
|
private
|
37
37
|
|
38
|
+
def index_sub_str
|
39
|
+
index = @options[:index]
|
40
|
+
return '' unless index
|
41
|
+
('_' + (index + 1).to_s)
|
42
|
+
end
|
43
|
+
|
38
44
|
def rule_conditions_blank?
|
39
45
|
@options[:rule].conditions.blank?
|
40
46
|
end
|
41
47
|
|
42
48
|
def condition_for_rule_without_conditions
|
43
|
-
@rule_conditions = @options[:rule].base_behavior ? '
|
49
|
+
@rule_conditions = @options[:rule].base_behavior ? '' : '(false)'
|
44
50
|
end
|
45
51
|
|
46
52
|
def construct_cypher_options
|
@@ -61,10 +67,17 @@ module CanCanCan
|
|
61
67
|
def update_path_with_rel(conditions, rel)
|
62
68
|
rel_length = conditions.delete(:rel_length) if conditions
|
63
69
|
arrow_cypher = rel.arrow_cypher(nil, {}, false, false, rel_length)
|
64
|
-
node_label =
|
70
|
+
node_label = path_end_node(rel, conditions)
|
65
71
|
@path += (arrow_cypher + node_label)
|
66
72
|
end
|
67
73
|
|
74
|
+
def path_end_node(rel, conditions)
|
75
|
+
label = CypherConstructorHelper.path_end_var(rel, conditions)
|
76
|
+
label += '_01' if !label.blank? && @path.include?("#{label}:")
|
77
|
+
@options[:con_var_label] = label
|
78
|
+
CypherConstructorHelper.path_node(rel.target_class, label)
|
79
|
+
end
|
80
|
+
|
68
81
|
def cypher_for_relation_conditions(conditions, relationship)
|
69
82
|
if conditions.is_a?(Hash)
|
70
83
|
conditions.each do |key, con|
|
@@ -81,7 +94,7 @@ module CanCanCan
|
|
81
94
|
end
|
82
95
|
|
83
96
|
def merge_conditions(key, value, base_class)
|
84
|
-
var_name = var_label_for_conditions
|
97
|
+
var_name = var_label_for_conditions
|
85
98
|
if key == :id
|
86
99
|
merge_condition_for_id(var_name, base_class, value)
|
87
100
|
else
|
@@ -89,10 +102,8 @@ module CanCanCan
|
|
89
102
|
end
|
90
103
|
end
|
91
104
|
|
92
|
-
def var_label_for_conditions
|
93
|
-
|
94
|
-
return @options[:var_label] if condition_keys.include?(key)
|
95
|
-
CypherConstructorHelper.var_name(base_class)
|
105
|
+
def var_label_for_conditions
|
106
|
+
@options[:con_var_label] || @options[:var_label]
|
96
107
|
end
|
97
108
|
|
98
109
|
def merge_condition_for_id(var_name, base_class, value)
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'cancancan/neo4j/cypher_constructor_helper'
|
2
|
+
|
3
|
+
module CanCanCan
|
4
|
+
module Neo4j
|
5
|
+
# Return records for single cancan rule
|
6
|
+
class SingleRuleCypher
|
7
|
+
attr_reader :rule, :model_class
|
8
|
+
def initialize(rule, model_class)
|
9
|
+
@rule = rule
|
10
|
+
@model_class = model_class
|
11
|
+
end
|
12
|
+
|
13
|
+
def records
|
14
|
+
conds = rule.conditions
|
15
|
+
return conds if conds.is_a?(::Neo4j::ActiveNode::Query::QueryProxy)
|
16
|
+
return records_for_no_conditions if conds.blank?
|
17
|
+
records_for_hash_conditions
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def records_for_no_conditions
|
23
|
+
if rule.base_behavior
|
24
|
+
model_class.all
|
25
|
+
else
|
26
|
+
model_class.where('false')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def records_for_hash_conditions
|
31
|
+
cypher = CanCanCan::Neo4j::RuleCypher.new(rule: rule,
|
32
|
+
model_class: model_class,
|
33
|
+
index: nil)
|
34
|
+
model_class.new_query
|
35
|
+
.match(cypher.path)
|
36
|
+
.where(cypher.rule_conditions)
|
37
|
+
.proxy_as(model_class, var_lable)
|
38
|
+
.distinct
|
39
|
+
end
|
40
|
+
|
41
|
+
def var_lable
|
42
|
+
CypherConstructorHelper.var_name(model_class)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cancancan-neo4j
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Amit Suryavanshi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
@@ -152,6 +152,7 @@ files:
|
|
152
152
|
- lib/cancancan/neo4j/cypher_constructor.rb
|
153
153
|
- lib/cancancan/neo4j/cypher_constructor_helper.rb
|
154
154
|
- lib/cancancan/neo4j/rule_cypher.rb
|
155
|
+
- lib/cancancan/neo4j/single_rule_cypher.rb
|
155
156
|
- lib/cancancan/neo4j/version.rb
|
156
157
|
homepage: https://github.com/CanCanCommunity/cancancan-neo4j
|
157
158
|
licenses:
|