klastera 1.1.2 → 1.1.3

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
  SHA256:
3
- metadata.gz: a198ff3af2a7b61a6a111ba1531bb1e5075cd7ff32a74a6db06b0b27a9a450cb
4
- data.tar.gz: 4b7548d0a282a24f72bb96ddd51b9339240f1752d9ca3b9be6d84682546c00ad
3
+ metadata.gz: 5852cf2afca5ca451495ec4edfc3424c2eef664b6f848bf0bf7160570cefc8e5
4
+ data.tar.gz: 8d7cdd33fa148b3aa6186953c6e20b49570442229150684da761d6e82c5511c8
5
5
  SHA512:
6
- metadata.gz: a37bd5892c61181db82859cbb32aa0801e4521b2a5a56cb2f561462b675ae2152916208fc786cee8e18c4141755982a0004cde10751303d5b9bdd41bc632a76a
7
- data.tar.gz: cf022a0d10ab1903c527c22efa485993e58f18dee5f1f98cd285a86132baecb6006459659c1c6b3446678dbcbf7bc866a492114daf04423699fcf18f130f2649
6
+ metadata.gz: 5044d1067b784b9b2a51fc77ddbd173478fc6b157126f13162ae329f4e276a449de01a2f0ef9318bf0dc8371ef933da9ff17e2d9f454446b0e4454663895168d
7
+ data.tar.gz: a3d59a38ba31e0686e17ce57172ce999527cb0b1f900ae5f93cb5e737c6b42f3e165ad448dfeb4c8a178873c90a354c0c55c67755b6b0228bc5c8ceec57dce11
@@ -5,6 +5,10 @@ module Klastera::Concerns::ClusterFilter
5
5
  include ActiveModel::Model
6
6
  include ActiveModel::Validations::Callbacks
7
7
  attr_accessor :cluster_id
8
+
9
+ def kcluster_id
10
+ self.cluster_id == 'without_cluster' ? nil : self.cluster_id
11
+ end
8
12
  end
9
13
 
10
14
  module ClassMethods
@@ -7,7 +7,7 @@
7
7
  <%=yield(f)%>
8
8
 
9
9
  <% if cluster_organization.is_in_cluster_mode? %>
10
- <% cluster_collection = cluster_clusters.map{|c|[c.name,c.id]} %>
10
+ <% cluster_collection = cluster_clusters.map{|c|[c.name,(c.id||c.nid)]} %>
11
11
  <% if cluster_collection.size > 1 %>
12
12
  <div class="inline-label-control-block">
13
13
  <%= f.input :cluster_id, collection: cluster_collection, prompt: t('klastera.clusters.all'), label: false, wrapper: false %>
@@ -1,5 +1,6 @@
1
1
  es:
2
2
  klastera:
3
+ without_cluster: Sin cluster
3
4
  cluster:
4
5
  title: Cluster
5
6
  id: Cluster ID
@@ -1,3 +1,3 @@
1
1
  module Klastera
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
data/lib/klastera.rb CHANGED
@@ -14,8 +14,18 @@ module Klastera
14
14
  scope_klass = scope_klass.where(organization_id: organization)
15
15
 
16
16
  session_clusters(user,organization) do |clusters|
17
- or_without_cluster = organization.required_suborganization_mode? ? "" : " OR cluster_id IS NULL "
18
- scope_klass = scope_klass.where("cluster_id IN (?)#{or_without_cluster}",clusters.map{|c|c.id})
17
+ clusters = clusters.reject{|c|c.id.blank?}
18
+ with_clusters = nil; without_clusters = nil
19
+
20
+ if organization.required_suborganization_mode? || clusters.present?
21
+ with_clusters = "#{scope.table_name}.cluster_id IN (#{clusters.map(&:id).join(',')})"
22
+ end
23
+
24
+ if organization.optional_mode?
25
+ without_clusters = "#{with_clusters.blank? ? '' : ' OR ' }#{scope.table_name}.cluster_id IS NULL"
26
+ end
27
+
28
+ scope_klass = scope_klass.where("#{with_clusters}#{without_clusters}")
19
29
  end
20
30
 
21
31
  scope_klass
@@ -38,10 +48,11 @@ module Klastera
38
48
  def session_clusters(user,organization)
39
49
  clusters = []
40
50
  if organization.is_in_cluster_mode?
41
- unless user.can_admin_clusters? || organization.optional_mode?
51
+ unless user.can_admin_clusters?
42
52
  # TODO: 1: return a Cluster::ActiveRecord_Relation and then remove to_a in ::Cluster.of line
43
53
  # TODO: 2: fix call to ::Cluster instead of Klastera::Cluster
44
54
  clusters = ::ClusterUser.of(user,organization).map{|cu|::Cluster.find(cu.cluster_id)}
55
+ clusters << ::Cluster.new({nid: :without_cluster, name: I18n.t('klastera.without_cluster')}) if organization.optional_mode?
45
56
  else
46
57
  # TODO: remove "to_a" after ClusterUser.of result became a Cluster::ActiveRecord_Relation object
47
58
  clusters = ::Cluster.of(organization).to_a
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.1.2
4
+ version: 1.1.3
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-04-06 00:00:00.000000000 Z
11
+ date: 2020-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails