klastera 1.3.2 → 1.3.3.1
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 +4 -4
- data/lib/klastera/version.rb +1 -1
- data/lib/klastera.rb +36 -18
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7fae7d83f8b939309532cb345a38bc9c4f76bfca455b16ccda6ad17283f6851e
|
4
|
+
data.tar.gz: f62a4b00a2c526c47b95464263dcca6de69d880b6095fdba41204fd14eff66b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 591f79de0e4332c44454b172eee9aea5491cfbee45ed2d942f67841a6918ff22323d0f0219e15ee60709672de8e190e9d466a822b96eb82b213dfecec5b22647
|
7
|
+
data.tar.gz: bb1b6e5ec7c8c4795f1662f7d0d9e58a758f0594547bd2ac64408efcb77a02fef103a0f1c349a6243d0023620f2fc23c631761f78ea5ced6a2c9640428b215eb
|
data/lib/klastera/version.rb
CHANGED
data/lib/klastera.rb
CHANGED
@@ -8,7 +8,8 @@ module Klastera
|
|
8
8
|
UNCLUSTERED_ENTITY = 'without_cluster'
|
9
9
|
KLSTR_HELPERS = %i[
|
10
10
|
cluster_user cluster_organization user_has_more_than_one_cluster cluster_scope cluster_of_my_own
|
11
|
-
user_clusters_string_list set_collection_before_group_by_entity
|
11
|
+
user_clusters_string_list set_collection_before_group_by_entity same_cluster_scope
|
12
|
+
cluster_scope_through_of
|
12
13
|
]
|
13
14
|
|
14
15
|
class << self
|
@@ -41,7 +42,7 @@ module Klastera
|
|
41
42
|
##
|
42
43
|
#
|
43
44
|
#
|
44
|
-
def set_collection_before_group_by_entity!(active_record_collection,entity_params,organization)
|
45
|
+
def set_collection_before_group_by_entity!(active_record_collection,entity_params,organization,include_nil_by_rule=true)
|
45
46
|
entity_params_keys = [:entity_name,:entity_attribute,:entity_id,:entity_id_attribute,:unamed]
|
46
47
|
entity_params[:entity_id] ||= nil #Ensures the entity_id attribute presence even if there is no filter
|
47
48
|
entity_params = entity_params.slice(*entity_params_keys).values
|
@@ -54,7 +55,8 @@ module Klastera
|
|
54
55
|
active_record_collection = Klastera.filter_clusterized!(
|
55
56
|
active_record_collection,
|
56
57
|
entity_params[2],
|
57
|
-
organization
|
58
|
+
organization,
|
59
|
+
include_nil_by_rule
|
58
60
|
)
|
59
61
|
end
|
60
62
|
yield( active_record_collection, entity_params_keys.zip(entity_params).to_h )
|
@@ -64,14 +66,14 @@ module Klastera
|
|
64
66
|
#
|
65
67
|
# In order to this work, the active_record_collection argument should be a cluster_scope! return.
|
66
68
|
#
|
67
|
-
def filter_clusterized!(active_record_collection,cluster_id,organization)
|
69
|
+
def filter_clusterized!(active_record_collection,cluster_id,organization,include_nil_by_rule=true)
|
68
70
|
if organization.is_in_cluster_mode? && cluster_id.present?
|
69
71
|
# Ensures that an array of ids is used in the statement
|
70
|
-
cluster_array = cluster_id.is_a?(Array) ? cluster_id : [cluster_id]
|
72
|
+
cluster_array = cluster_id.is_a?(Array) ? cluster_id.dup : [cluster_id]
|
71
73
|
# If we receive a UNCLUSTERED_ENTITY request, it means that we should filter by entities without clusters.
|
72
74
|
# The optional_mode?(show/use) condition add to this method an ambivalent use,
|
73
75
|
# where you can filter a unique value or multiple including NULL ones.
|
74
|
-
cluster_array << nil if cluster_array.delete(UNCLUSTERED_ENTITY) || organization.optional_mode?
|
76
|
+
cluster_array << nil if include_nil_by_rule || cluster_id == UNCLUSTERED_ENTITY && ( cluster_array.delete(UNCLUSTERED_ENTITY) || organization.optional_mode? )
|
75
77
|
active_record_collection = active_record_collection.where(cluster_entities: { cluster_id: cluster_array.uniq })
|
76
78
|
# You should use a block with clusterable data only
|
77
79
|
yield(active_record_collection) if block_given?
|
@@ -90,7 +92,7 @@ module Klastera
|
|
90
92
|
# Ensures that an array of id is used in the statement
|
91
93
|
cluster_ids = cluster_id.is_a?(Array) ? cluster_id : [cluster_id]
|
92
94
|
else
|
93
|
-
clusters = cluster_of!(user
|
95
|
+
clusters = cluster_of!(organization,user)
|
94
96
|
cluster_ids = clusters.map(&:id).compact
|
95
97
|
end
|
96
98
|
|
@@ -124,12 +126,10 @@ module Klastera
|
|
124
126
|
if cluster_id.present?
|
125
127
|
cluster_ids = cluster_id.is_a?(Array) ? cluster_id : [cluster_id]
|
126
128
|
else
|
127
|
-
clusters = cluster_of!(user
|
129
|
+
clusters = cluster_of!(organization,user)
|
128
130
|
cluster_ids = clusters.map(&:id).compact.sort
|
129
131
|
end
|
130
132
|
|
131
|
-
scope_klass = scope_klass.select("DISTINCT ON (#{scope.table_name}.id) #{scope.table_name}.id, #{scope.table_name}.*, clusters.*")
|
132
|
-
|
133
133
|
if organization.required_suborganization_mode?# || cluster_id # If cluster_id is passed NULL clusters are expected, rigth?
|
134
134
|
scope_klass = scope_klass.where( cluster_entities: { cluster_id: cluster_ids } )
|
135
135
|
else
|
@@ -141,6 +141,18 @@ module Klastera
|
|
141
141
|
scope_klass.where(organization_id: organization)
|
142
142
|
end
|
143
143
|
|
144
|
+
#
|
145
|
+
# Filter non-clustered entity through a clusterized one
|
146
|
+
#
|
147
|
+
def cluster_scope_through_of!(relation,cluster_entity_klass,scope_klass,user,organization,cluster_id=nil)
|
148
|
+
scope_class(scope_klass).joins(relation => :cluster_entities).where(
|
149
|
+
organization_id: organization,
|
150
|
+
"#{relation}_id" => same_cluster_scope!(
|
151
|
+
cluster_entity_klass, user, organization, cluster_id
|
152
|
+
)
|
153
|
+
)
|
154
|
+
end
|
155
|
+
|
144
156
|
##
|
145
157
|
# TODO:
|
146
158
|
# Implement a validation to ensure that
|
@@ -156,9 +168,11 @@ module Klastera
|
|
156
168
|
# Returns a Cluster::ActiveRecord_Relation if the organization is using the cluster mode.
|
157
169
|
# Use this only to get current_user/organization clusters
|
158
170
|
#
|
159
|
-
def cluster_of!(user
|
171
|
+
def cluster_of!(organization,user)
|
160
172
|
# A cluster user with role Root or Admin retrieve every cluster of its organizations
|
161
|
-
|
173
|
+
# Thats why we pass a nil object to avoid user filter, but if you pass a nil user as argument
|
174
|
+
# The result is the same as if the user was a admin, BE CAREFUL!
|
175
|
+
and_this_user = user.try(:can_admin_clusters?) ? nil : user
|
162
176
|
# We weill return a cluster active record collection that can be filtered
|
163
177
|
active_record_collection = ::ClusterUser.clusters_of(organization,and_this_user)
|
164
178
|
# Add a empty cluster instance to handle models without a cluster assignation.
|
@@ -186,7 +200,7 @@ module Klastera
|
|
186
200
|
# cluster_of! needs a user and a organization. that why we perfomed this logic here
|
187
201
|
#
|
188
202
|
def user_clusters_string_list!(user,organization,cluster_entities,separator,attribute=:name)
|
189
|
-
@clusters_session ||=
|
203
|
+
@clusters_session ||= Klastera.cluster_of!(organization,user)
|
190
204
|
self.entity_clusters_string_list!(cluster_entities, separator, attribute, @clusters_session.map(&:id))
|
191
205
|
end
|
192
206
|
end
|
@@ -227,8 +241,8 @@ module Klastera
|
|
227
241
|
[ :cluster_id ].concat( ::ClusterFilter.attributes )
|
228
242
|
end
|
229
243
|
|
230
|
-
def filter_clusterized(active_record_collection,cluster_id)
|
231
|
-
Klastera.filter_clusterized!(active_record_collection, cluster_id, cluster_organization)
|
244
|
+
def filter_clusterized(active_record_collection,cluster_id,include_nil_by_rule=true)
|
245
|
+
Klastera.filter_clusterized!(active_record_collection, cluster_id, cluster_organization, include_nil_by_rule)
|
232
246
|
end
|
233
247
|
|
234
248
|
def cluster_scope(scope,cluster_id=nil)
|
@@ -239,8 +253,12 @@ module Klastera
|
|
239
253
|
Klastera.same_cluster_scope!(scope, cluster_user, cluster_organization, cluster_id)
|
240
254
|
end
|
241
255
|
|
256
|
+
def cluster_scope_through_of(relation,cluster_entity_klass,scope_klass,cluster_id=nil)
|
257
|
+
Klastera.cluster_scope_through_of!(relation, cluster_entity_klass, scope_klass, cluster_user, cluster_organization, cluster_id )
|
258
|
+
end
|
259
|
+
|
242
260
|
def cluster_of_my_own
|
243
|
-
Klastera.cluster_of!(cluster_user
|
261
|
+
Klastera.cluster_of!(cluster_organization,cluster_user)
|
244
262
|
end
|
245
263
|
|
246
264
|
def user_clusters_string_list(object_entity,separator,attribute=:name)
|
@@ -253,8 +271,8 @@ module Klastera
|
|
253
271
|
)
|
254
272
|
end
|
255
273
|
|
256
|
-
def set_collection_before_group_by_entity(active_record_collection,entity_params,&block)
|
257
|
-
Klastera.set_collection_before_group_by_entity!(active_record_collection, params, cluster_organization, &block)
|
274
|
+
def set_collection_before_group_by_entity(active_record_collection,entity_params,include_nil_by_rule=true,&block)
|
275
|
+
Klastera.set_collection_before_group_by_entity!(active_record_collection, params, cluster_organization, include_nil_by_rule, &block)
|
258
276
|
end
|
259
277
|
|
260
278
|
included do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: klastera
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gino Barahona
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -127,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
127
|
- !ruby/object:Gem::Version
|
128
128
|
version: '0'
|
129
129
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
130
|
+
rubygems_version: 3.0.8
|
131
131
|
signing_key:
|
132
132
|
specification_version: 4
|
133
133
|
summary: Clusterization Engine
|