klastera 1.4.3 → 1.4.4.3.1

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: e524bc600751df634962778af44d6b9bd782cabdf7a125a145d2a7efbfbe6950
4
- data.tar.gz: ab457168729e69d5f1ca94f40ea667b78e3610993eaa686998e8aa792f865db1
3
+ metadata.gz: 5360c25a358007e11929e1c705ed18f97538d0a2dcfa7817e838dc422457a3f7
4
+ data.tar.gz: 319361af1415f3337408b376703a6b8e8021975d137be787c4ec8e2ea318ad4f
5
5
  SHA512:
6
- metadata.gz: f30c250c13e081a7aebeb66fce89386638d445a92f5dd995c4855483a45efd7bf7927265980fff8ffcef7ca3e9d3f5fc53c618b05babc92464a6986a8878df84
7
- data.tar.gz: 97007ff678bbc223506ac5fc53814c9b7363c3e45ba4f39455f73d8abdd1012bab6fd7b126b3237cc42b91fbbb6a969061c72ece12549aa1d84ae0810522a43a
6
+ metadata.gz: 56d74c36d8de04066a89ac3d0cb05abfedca150d6e5264872cb1e283138f76e828eadfca43824e7977020898a7a69287f2392b9263a6316eb4cd6b9ca5e8d397
7
+ data.tar.gz: 39917be78a6bac52e0077d0f6cf40e915c2c11fd360d79ee51881fec65577c21093c9080f06e3b74cbcc0f514b0cc6cca1bbc8b0e6720eca23b0fc08203e56f0
@@ -0,0 +1,5 @@
1
+ module Klastera
2
+ class ClusterEntity < ActiveRecord::Base
3
+ include Klastera::Concerns::Clusterizable
4
+ end
5
+ end
@@ -1,13 +1,16 @@
1
1
  module Klastera::Concerns::Clusterizable
2
2
  extend ActiveSupport::Concern
3
+
3
4
  included do
5
+ class MutipleClustersOperationError < StandardError; end
6
+
4
7
  belongs_to :cluster
5
8
 
6
9
  has_many :cluster_entities, as: :entity, class_name: Klastera::ClusterEntity
7
10
  accepts_nested_attributes_for :cluster_entities, reject_if: :all_blank, allow_destroy: true
8
11
 
9
- validates :cluster_id, presence: true, if: proc { self.try(:cluster_id) && self.organization.required_suborganization_mode? }
10
- validate :at_least_one_cluster_entity, if: proc { self.organization.required_suborganization_mode? }
12
+ validates :cluster_id, presence: true, if: -> { cluster_id.present? && organization.present? && organization.required_suborganization_mode? }
13
+ validate :at_least_one_cluster_entity, if: -> { organization.present? && organization.required_suborganization_mode? }
11
14
  validate :uniqueness_of_cluster_entity_record
12
15
 
13
16
  scope :includes_cluster, -> { includes(cluster_entities: :cluster) }
@@ -18,6 +21,10 @@ module Klastera::Concerns::Clusterizable
18
21
  end
19
22
  end
20
23
 
24
+ def allow_multiple_clusters?(default=:one)
25
+ organization.present? && organization.cluster_cardinality_of(self.class, default: default) == :many
26
+ end
27
+
21
28
  ##
22
29
  # This is a legacy method and we don't recommend using it.
23
30
  # Implement directly Klastera.entity_clusters_string_list instead of this method.
@@ -25,7 +32,7 @@ module Klastera::Concerns::Clusterizable
25
32
  ##
26
33
  def clusters_string_separated_by(separator,attribute=:name)
27
34
  Klastera.entity_clusters_string_list!(
28
- self.cluster_entities, separator, attribute
35
+ cluster_entities, separator, attribute
29
36
  )
30
37
  end
31
38
 
@@ -1,7 +1,7 @@
1
1
  module Klastera::Concerns::Organization
2
2
  extend ActiveSupport::Concern
3
3
  included do
4
-
4
+ serialize :cluster_config
5
5
  has_many :clusters
6
6
 
7
7
  validates :use_cluster_as, inclusion: { in: ::Cluster::MODES.map{|m|m.to_s}, message: I18n.t('klastera.clusters.wrong_option') }, if: proc{ use_cluster_as.present? }
@@ -11,6 +11,17 @@ module Klastera::Concerns::Organization
11
11
  self.use_cluster_as.to_s.to_sym
12
12
  end
13
13
 
14
+ def cluster_cardinality_of(entity, default: :many)
15
+ if cluster_config.is_a?(Hash)
16
+ entities_cardinality = cluster_config[:entities]&.[](:cardinality)||{}
17
+ entity = entity.to_s.to_sym
18
+ if entities_cardinality.has_key?(entity)
19
+ default = entities_cardinality[entity]
20
+ end
21
+ end
22
+ default.to_s.to_sym
23
+ end
24
+
14
25
  ##
15
26
  # Return a boolean if one of three of options was set in organization
16
27
  # As useless option you can retrieve the value passing false as argument.
@@ -11,29 +11,29 @@ module Klastera::Concerns::User
11
11
 
12
12
  has_many :cluster_users, inverse_of: :user, class_name: ::ClusterUser.to_s
13
13
  accepts_nested_attributes_for :cluster_users, reject_if: :all_blank, allow_destroy: true
14
- validates :cluster_role, presence: true, if: proc{ self.organization.is_in_cluster_mode? }
15
- validates :cluster_role, inclusion: { in: CLUSTER_ROLES , message: I18n.t('klastera.clusters.wrong_option') }, if: proc{ cluster_role.present? }
16
- validate :at_least_one_role, if: proc{ self.use_cluster? && self.try(:need_cluster_assignation?) }
14
+ validates :cluster_role, presence: true, if: -> { organization.present? && organization.is_in_cluster_mode? }
15
+ validates :cluster_role, inclusion: { in: CLUSTER_ROLES , message: I18n.t('klastera.clusters.wrong_option') }, if: -> { cluster_role.present? }
16
+ validate :at_least_one_role, if: -> { use_cluster? && try(:need_cluster_assignation?) }
17
17
 
18
- def use_cluster?; self.cluster_role.present?; end
18
+ def use_cluster?; cluster_role.present?; end
19
19
 
20
- def is_a_cluster_root?; self.cluster_role == CLUSTER_ROOT; end
21
- def is_a_cluster_admin?; self.cluster_role == CLUSTER_ADMIN; end
22
- def is_a_cluster_user?; self.cluster_role == CLUSTER_USER; end
20
+ def is_a_cluster_root?; cluster_role == CLUSTER_ROOT; end
21
+ def is_a_cluster_admin?; cluster_role == CLUSTER_ADMIN; end
22
+ def is_a_cluster_user?; cluster_role == CLUSTER_USER; end
23
23
 
24
24
  def need_cluster_assignation?
25
- self.try(:organization).try(:required_suborganization_mode?) && self.is_a_cluster_user?
25
+ organization.present? && organization.required_suborganization_mode? && is_a_cluster_user?
26
26
  end
27
27
 
28
28
  def can_admin_clusters?
29
- self.organization.is_in_cluster_mode? && ( self.is_a_cluster_admin? || self.is_a_cluster_root? )
29
+ organization.present? && organization.is_in_cluster_mode? && ( is_a_cluster_admin? || is_a_cluster_root? )
30
30
  end
31
31
 
32
32
  #
33
33
  # It tells if this user should see what they cluster role or organization dictates
34
34
  # Adminers and users from show cluster modes skip cluster clause
35
35
  def cannot_skip_cluster_clause?
36
- ! ( self.is_a_cluster_admin? || self.is_a_cluster_root? || ( self.organization.optional_suborganization_mode? && self.cluster_users.blank? ) )
36
+ ! ( is_a_cluster_admin? || is_a_cluster_root? || ( organization.present? && organization.optional_suborganization_mode? && cluster_users.blank? ) )
37
37
  end
38
38
 
39
39
  #
@@ -43,9 +43,9 @@ module Klastera::Concerns::User
43
43
  # cluster_id is present (on show/use mode organizations).
44
44
  #
45
45
  def try_to_clusterify!(role,cluster_ids)
46
- if self.try(:organization).try(:is_in_cluster_mode?)
46
+ if organization.present? && organization.is_in_cluster_mode?
47
47
  self.cluster_role = role
48
- if self.try(:organization).try(:required_suborganization_mode?) || cluster_ids.present?
48
+ if ( organization.present? && organization.required_suborganization_mode? ) || cluster_ids.present?
49
49
  timestamp = DateTime.now.to_i
50
50
  nested_attributes = {}
51
51
  cluster_ids.each do |cluster_id|
@@ -1,6 +1,6 @@
1
1
  <tr class="nested-fields">
2
2
  <td class="field">
3
- <%= f.select :cluster_id, @clusters_session.map{|c|[c.name,c.id]}, { include_blank: true }, { class: 'form-control' } %>
3
+ <%= f.select :cluster_id, @clusters_session.order(:order,:name).map{|c|[c.name,c.id]}, { include_blank: true }, { class: 'form-control' } %>
4
4
  </td>
5
5
  <td class="action vertical-align-middle text-center" width="44">
6
6
  <%= link_to_remove_association f, class: 'btn btn-danger btn-xs text-danger' do %>
@@ -7,7 +7,7 @@
7
7
  <%=yield(f) if block_given? %>
8
8
 
9
9
  <% if cluster_organization.is_in_cluster_mode? %>
10
- <% cluster_collection = cluster_list.map{|c|[c.name,(c.id||c.nid)]} %>
10
+ <% cluster_collection = cluster_list.order(:order, :name).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,6 +1,6 @@
1
1
  <tr class="nested-fields">
2
2
  <td class="field">
3
- <%= f.select :cluster_id, @user.organization.clusters.map{|c|[c.name,c.id]}, { include_blank: true }, { class: 'form-control' } %>
3
+ <%= f.select :cluster_id, @user.organization.clusters.order(:order, :name).map{|c|[c.name,c.id]}, { include_blank: true }, { class: 'form-control' } %>
4
4
  </td>
5
5
  <td class="action vertical-align-middle text-center" width="44">
6
6
  <%= link_to_remove_association f, class: 'btn btn-danger btn-xs text-danger' do %>
@@ -0,0 +1,5 @@
1
+ class AddClusterConfigToOrganization < ActiveRecord::Migration
2
+ def change
3
+ add_column :organizations, :cluster_config, :text
4
+ end
5
+ end
data/lib/klastera.rb CHANGED
@@ -54,7 +54,7 @@ module Klastera
54
54
  end
55
55
  _cluster_entities.map do |ce|
56
56
  ce.cluster.try(attribute)
57
- end.compact.join(separator)
57
+ end.compact.sort.join(separator)
58
58
  end
59
59
 
60
60
  ##
@@ -1,3 +1,3 @@
1
1
  module Klastera
2
- VERSION = "1.4.3"
2
+ VERSION = "1.4.4.3.1"
3
3
  end
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.4.3
4
+ version: 1.4.4.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-08-08 00:00:00.000000000 Z
11
+ date: 2021-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -58,6 +58,7 @@ files:
58
58
  - app/models/klastera/cluster_entity.rb
59
59
  - app/models/klastera/cluster_filter.rb
60
60
  - app/models/klastera/cluster_user.rb
61
+ - app/models/klastera/clusterizable.rb
61
62
  - app/models/klastera/concerns/cluster.rb
62
63
  - app/models/klastera/concerns/cluster_entity.rb
63
64
  - app/models/klastera/concerns/cluster_filter.rb
@@ -93,6 +94,7 @@ files:
93
94
  - db/migrate/20200330010551_create_klastera_cluster_users.rb
94
95
  - db/migrate/20200330221601_add_order_field_to_clusters.rb
95
96
  - db/migrate/20200518142609_create_klastera_cluster_entities.rb
97
+ - db/migrate/20200908180057_add_cluster_config_to_organization.rb
96
98
  - lib/klastera.rb
97
99
  - lib/klastera/engine.rb
98
100
  - lib/klastera/version.rb