klastera 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/klastera/application_controller.rb +1 -5
- data/app/controllers/klastera/clusters_controller.rb +2 -6
- data/app/models/klastera/cluster_filter.rb +5 -0
- data/app/models/klastera/concerns/cluster.rb +11 -11
- data/app/models/klastera/concerns/cluster_filter.rb +21 -0
- data/app/models/klastera/concerns/cluster_user.rb +3 -3
- data/app/models/klastera/concerns/clusterizable.rb +14 -0
- data/app/models/klastera/concerns/organization.rb +2 -6
- data/app/models/klastera/concerns/transfer.rb +1 -1
- data/app/models/klastera/concerns/user.rb +3 -12
- data/app/views/klastera/clusters/_form_transfer.html.erb +3 -3
- data/app/views/klastera/clusters/_table.html.erb +1 -1
- data/app/views/layouts/klastera/_cluster_filter.html.erb +23 -0
- data/app/views/layouts/klastera/_cluster_role.html.erb +2 -1
- data/app/views/layouts/klastera/_cluster_selector.html.erb +23 -0
- data/app/views/layouts/klastera/_cluster_user_fields.html.erb +1 -1
- data/app/views/layouts/klastera/_nested_cluster_user.html.erb +1 -1
- data/app/views/layouts/klastera/_options.html.erb +2 -2
- data/config/locales/es.yml +11 -6
- data/db/migrate/20200326111219_add_cluster_options_to_organizations.rb +0 -14
- data/db/migrate/20200330010551_create_klastera_cluster_users.rb +2 -2
- data/lib/klastera/version.rb +1 -1
- data/lib/klastera.rb +111 -1
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12536c20cf2d30bd60e704036cd40ffc688caee158a0802fa39713e6e46c4c49
|
4
|
+
data.tar.gz: 5b945c20beba1467597764507a6aaa373287c3c50663fa0d115f92d4d310d47b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a6d3198aa48188ad3d7e847070a23bd84876de19f81ddcc34d44ed906ab274f2b678c4228e023bc2294ba36defb49a1518cb057905675ad97a243f7bf5c8b27
|
7
|
+
data.tar.gz: 76183a671d08a2eca8885425562a7e93e2196c72f6405984239a28cd872ef53d83f16dd78a3a48b720b2a6ad15a5d72e3912a83928e5099fc0756c2d6c46ce75
|
@@ -5,12 +5,8 @@ module Klastera
|
|
5
5
|
before_action :set_xhr_render_session
|
6
6
|
before_action :check_access_to_cluster_admin
|
7
7
|
|
8
|
-
def current_organization
|
9
|
-
super
|
10
|
-
end
|
11
|
-
|
12
8
|
def check_access_to_cluster_admin
|
13
|
-
unless
|
9
|
+
unless cluster_user.can_admin_clusters?
|
14
10
|
redirect_to main_app.root_path, flash: { alert: t('klastera.messages.access_cluster_admin') }
|
15
11
|
end
|
16
12
|
end
|
@@ -49,17 +49,13 @@ module Klastera
|
|
49
49
|
@cluster = ::Cluster.find(params[:id])
|
50
50
|
end
|
51
51
|
|
52
|
-
###
|
53
|
-
# We are assuming that the main application
|
54
|
-
# has have implemented current_organization
|
55
|
-
###
|
56
52
|
def set_clusters
|
57
|
-
@clusters =
|
53
|
+
@clusters = cluster_organization.clusters
|
58
54
|
end
|
59
55
|
|
60
56
|
def cluster_params
|
61
57
|
parameters = params.require(:cluster).permit(:nid, :name, :color, :order)
|
62
|
-
parameters[:organization_id]=
|
58
|
+
parameters[:organization_id]=cluster_organization.id
|
63
59
|
parameters
|
64
60
|
end
|
65
61
|
end
|
@@ -8,14 +8,14 @@ module Klastera::Concerns::Cluster
|
|
8
8
|
|
9
9
|
attr_reader :last_record
|
10
10
|
|
11
|
-
MODES = [ :
|
11
|
+
MODES = [ :required_suborganization, :optional_suborganization, :optional_filter ].freeze
|
12
12
|
|
13
|
-
default_scope { order(id: :desc) }
|
14
13
|
belongs_to :organization, class_name: Klastera.organization_class
|
15
14
|
|
16
|
-
scope :
|
17
|
-
|
18
|
-
|
15
|
+
scope :of, -> (organization,except_ids=[]) {
|
16
|
+
_scope = where(organization: organization)
|
17
|
+
_scope = _scope.where.not(id: except_ids) unless except_ids.blank?
|
18
|
+
_scope
|
19
19
|
}
|
20
20
|
|
21
21
|
validates :name, presence: true
|
@@ -29,15 +29,15 @@ module Klastera::Concerns::Cluster
|
|
29
29
|
end
|
30
30
|
|
31
31
|
def siblings
|
32
|
-
|
32
|
+
::Cluster.of(self.organization,[self.id])
|
33
33
|
end
|
34
34
|
|
35
|
-
def
|
36
|
-
self.organization.
|
35
|
+
def is_the_last_record_in_required_suborganization_mode?
|
36
|
+
self.organization.required_suborganization_mode? && self.siblings.blank?
|
37
37
|
end
|
38
38
|
|
39
39
|
def required_transfer?
|
40
|
-
self.organization.
|
40
|
+
self.organization.required_suborganization_mode?
|
41
41
|
end
|
42
42
|
|
43
43
|
def has_related_entities_using_it?
|
@@ -46,8 +46,8 @@ module Klastera::Concerns::Cluster
|
|
46
46
|
|
47
47
|
def can_transfer_and_destroy?
|
48
48
|
can_destroy = true
|
49
|
-
if
|
50
|
-
errors.add(:last_record, I18n.t('klastera.messages.
|
49
|
+
if is_the_last_record_in_required_suborganization_mode?
|
50
|
+
errors.add(:last_record, I18n.t('klastera.messages.cant_delete_the_last_record_in_required_suborganization_mode'))
|
51
51
|
can_destroy = false
|
52
52
|
end
|
53
53
|
can_destroy
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Klastera::Concerns::ClusterFilter
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
include ActiveModel::Model
|
6
|
+
include ActiveModel::Validations::Callbacks
|
7
|
+
attr_accessor :cluster_id
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def attr_accessor(*vars)
|
12
|
+
@attributes ||= []
|
13
|
+
@attributes.concat vars
|
14
|
+
super(*vars)
|
15
|
+
end
|
16
|
+
|
17
|
+
def attributes
|
18
|
+
@attributes
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -10,9 +10,9 @@ module Klastera::Concerns::ClusterUser
|
|
10
10
|
validates :user_id, presence: true
|
11
11
|
validates :cluster_id, presence: true
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
scope :of, -> (user,organization) {
|
14
|
+
includes(:cluster).where(user_id: user, "clusters.organization_id": organization)
|
15
|
+
}
|
16
16
|
end
|
17
17
|
|
18
18
|
module ClassMethods
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Klastera::Concerns::Clusterizable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
attr_accessor :lonely_cluster
|
5
|
+
belongs_to :cluster
|
6
|
+
validates :cluster_id, presence: true, if: proc { self.organization.required_suborganization_mode? }
|
7
|
+
end
|
8
|
+
|
9
|
+
module ClassMethods
|
10
|
+
def cluster_params
|
11
|
+
[ :cluster_id, :lonely_cluster ]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -21,21 +21,17 @@ module Klastera::Concerns::Organization
|
|
21
21
|
( return_the_mode ? ( is_active ? cluster_mode : false ) : is_active )
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def required_suborganization_mode?
|
25
25
|
cluster_mode == ::Cluster::MODES.first
|
26
26
|
end
|
27
27
|
|
28
|
-
def
|
28
|
+
def optional_suborganization_mode?
|
29
29
|
cluster_mode == ::Cluster::MODES.second
|
30
30
|
end
|
31
31
|
|
32
32
|
def optional_filter_mode?
|
33
33
|
cluster_mode == ::Cluster::MODES.third
|
34
34
|
end
|
35
|
-
|
36
|
-
def cluster_is_required?
|
37
|
-
self.suborganization_mode? || self.required_filter_mode?
|
38
|
-
end
|
39
35
|
end
|
40
36
|
|
41
37
|
module ClassMethods
|
@@ -21,7 +21,7 @@ module Klastera::Concerns::Transfer
|
|
21
21
|
#
|
22
22
|
# If you see this, please fixe it. Thanks
|
23
23
|
#
|
24
|
-
if current_cluster.class.name != 'Cluster' || current_cluster.try(:
|
24
|
+
if current_cluster.class.name != 'Cluster' || current_cluster.try(:is_the_last_record_in_required_suborganization_mode?)
|
25
25
|
errors.add(:current_cluster, I18n.t('klastera.messages.current_cluster.cant_transfer'))
|
26
26
|
elsif self.required_transfer? && new_cluster_id.present? && new_cluster.nil?
|
27
27
|
errors.add(:new_cluster_id, I18n.t('klastera.messages.new_cluster_id.nil'))
|
@@ -3,8 +3,6 @@ module Klastera::Concerns::User
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
|
6
|
-
## @@current_organization = nil
|
7
|
-
|
8
6
|
CLUSTER_ROOT = 'root'.freeze
|
9
7
|
CLUSTER_ADMIN = 'admin'.freeze
|
10
8
|
CLUSTER_USER = 'user'.freeze
|
@@ -15,7 +13,7 @@ module Klastera::Concerns::User
|
|
15
13
|
accepts_nested_attributes_for :cluster_users, reject_if: :all_blank, allow_destroy: true
|
16
14
|
validates :cluster_role, presence: true, if: proc{ self.organization.is_in_cluster_mode? }
|
17
15
|
validates :cluster_role, inclusion: { in: CLUSTER_ROLES , message: I18n.t('klastera.clusters.wrong_option') }, if: proc{ cluster_role.present? }
|
18
|
-
validate :at_least_one_role, if: proc{ self.use_cluster? && self.need_cluster_assignation? }
|
16
|
+
validate :at_least_one_role, if: proc{ self.use_cluster? && self.try(:need_cluster_assignation?) }
|
19
17
|
before_destroy do |record|
|
20
18
|
end
|
21
19
|
|
@@ -30,22 +28,15 @@ module Klastera::Concerns::User
|
|
30
28
|
def is_not_a_cluster_user?; ! self.is_a_cluster_user?; end
|
31
29
|
|
32
30
|
def need_cluster_assignation?
|
33
|
-
self.organization.is_in_cluster_mode? && self.
|
31
|
+
self.try(:organization).try(:is_in_cluster_mode?) && self.is_a_cluster_user?
|
34
32
|
end
|
35
33
|
|
36
34
|
def can_admin_clusters?
|
37
35
|
self.organization.is_in_cluster_mode? && ( self.is_a_cluster_admin? || self.is_a_cluster_root? )
|
38
36
|
end
|
39
37
|
|
40
|
-
# def __current_organization
|
41
|
-
# @@current_organization
|
42
|
-
# end
|
43
|
-
|
44
|
-
# def __current_organization=(organization)
|
45
|
-
# @@current_organization = organization
|
46
|
-
# end
|
47
|
-
|
48
38
|
private
|
39
|
+
|
49
40
|
def at_least_one_role
|
50
41
|
if cluster_users.none?
|
51
42
|
errors.add(:base, I18n.t('klastera.user.you_need_add_at_least_one_cluster'))
|
@@ -8,9 +8,9 @@
|
|
8
8
|
<div class="row">
|
9
9
|
<% if can_transfer_and_destroy %>
|
10
10
|
<div class="col-xs-12">
|
11
|
-
<div class="alert alert-<%=
|
12
|
-
<i class="fa fa-2x fa-<%=
|
13
|
-
<p class="margin-top-5 fa-1-2x"><%=t("klastera.clusters.transfer.#{
|
11
|
+
<div class="alert alert-<%=cluster_organization.required_suborganization_mode? ? :warning : :info %> text-center">
|
12
|
+
<i class="fa fa-2x fa-<%=cluster_organization.required_suborganization_mode? ? :warning : 'info-circle' %> float-none"></i>
|
13
|
+
<p class="margin-top-5 fa-1-2x"><%=t("klastera.clusters.transfer.#{cluster_organization.required_suborganization_mode? ? :required : :optional}")%></p>
|
14
14
|
</div>
|
15
15
|
</div>
|
16
16
|
<div class="col-xs-12">
|
@@ -11,7 +11,7 @@
|
|
11
11
|
</thead>
|
12
12
|
<tbody>
|
13
13
|
<% @clusters.each do |cluster| %>
|
14
|
-
<tr>
|
14
|
+
<tr class="middle-align-rows">
|
15
15
|
<td class="text-center cluster-id"><%= cluster.id %></td>
|
16
16
|
<td class="text-center cluster-order"><%= cluster.order %></td>
|
17
17
|
<td class="text-center cluster-color">
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<%= simple_form_for(@filter, url: url, remote: true) do |f| %>
|
2
|
+
|
3
|
+
<div class="inline-buttons-block top">
|
4
|
+
<%= button_tag(t('klastera.actions.filter'), class: 'btn btn-primary btn-sm float-right', data: { disable_with: "<i class='fa fa-spinner spin'></i>" }) %>
|
5
|
+
</div>
|
6
|
+
|
7
|
+
<%=yield(f)%>
|
8
|
+
|
9
|
+
<% if cluster_organization.is_in_cluster_mode? %>
|
10
|
+
<% cluster_collection = cluster_clusters %>
|
11
|
+
<% if cluster_collection.size > 1 %>
|
12
|
+
<div class="inline-label-control-block">
|
13
|
+
<%= f.input :cluster_id, collection: cluster_collection, prompt: t('klastera.clusters.all'), label: false, wrapper: false %>
|
14
|
+
<label class="control-label"><%=t('klastera.cluster.title')%>:</label>
|
15
|
+
</div>
|
16
|
+
<% end %>
|
17
|
+
<% end %>
|
18
|
+
|
19
|
+
<div class="inline-buttons-block bottom">
|
20
|
+
<%= button_tag(t('klastera.actions.filter'), class: 'btn btn-primary btn-sm float-right', data: { disable_with: "<i class='fa fa-spinner spin'></i>" }) %>
|
21
|
+
</div>
|
22
|
+
|
23
|
+
<% end %>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
<% user_cluster_roles = user_cluster_roles.nil? ? User::CLUSTER_ROLES : user_cluster_roles %>
|
2
|
-
<%
|
2
|
+
<% other_visibility_reason = other_visibility_reason.nil? ? false : other_visibility_reason %>
|
3
|
+
<% if @user.try(:organization).try(:is_in_cluster_mode?) || other_visibility_reason %>
|
3
4
|
<div class="form-group">
|
4
5
|
<%= f.label t('klastera.cluster_role') %>
|
5
6
|
<%= f.select :cluster_role, user_cluster_roles.map{|r|[t("klastera.roles.#{r}"),r]}, { include_blank: true }, { class: 'form-control' } %>
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<% other_visibility_reason = other_visibility_reason.nil? ? false : other_visibility_reason %>
|
2
|
+
<% if cluster_organization.is_in_cluster_mode? || other_visibility_reason %>
|
3
|
+
<%
|
4
|
+
cluster_collection = cluster_clusters
|
5
|
+
label = t('klastera.cluster.id')
|
6
|
+
%>
|
7
|
+
<% if f.is_a?(SimpleForm::FormBuilder) %>
|
8
|
+
<% if cluster_collection.size == 1 %>
|
9
|
+
<%= f.input :lonely_cluster, as: :hidden, html_input: { value: true } %>
|
10
|
+
<% else %>
|
11
|
+
<%= f.input :cluster_id, collection: cluster_collection, label: label %>
|
12
|
+
<% end %>
|
13
|
+
<% else %>
|
14
|
+
<% if cluster_collection.size == 1 %>
|
15
|
+
<%= f.hidden_field :lonely_cluster, value: true %>
|
16
|
+
<% else %>
|
17
|
+
<div class="form-group">
|
18
|
+
<%= f.label label %>
|
19
|
+
<%= f.select :cluster_id, cluster_collection, { include_blank: true }, { class: 'form-control' } %>
|
20
|
+
</div>
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
23
|
+
<% end %>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<tr class="nested-fields">
|
2
2
|
<td class="field">
|
3
|
-
<%= f.select :cluster_id,
|
3
|
+
<%= f.select :cluster_id, @user.organization.clusters.map{|c|[c.name,c.id]}, { include_blank: true }, { class: 'form-control' } %>
|
4
4
|
</td>
|
5
5
|
<td class="action vertical-align-middle" width="44">
|
6
6
|
<%= link_to_remove_association f, class: 'btn btn-danger btn-xs text-danger' do %>
|
@@ -6,8 +6,8 @@
|
|
6
6
|
data-toggle="popover"
|
7
7
|
data-content="<%=
|
8
8
|
t('klastera.help.popover.content',
|
9
|
-
m1:t('klastera.help.
|
10
|
-
m2:t('klastera.help.
|
9
|
+
m1:t('klastera.help.required_suborganization', t: t('klastera.required_suborganization'), e: t('klastera.clusters.entities')),
|
10
|
+
m2:t('klastera.help.optional_suborganization', t: t('klastera.optional_suborganization'), e: t('klastera.clusters.entities')),
|
11
11
|
m3:t('klastera.help.optional_filter', t: t('klastera.optional_filter'), e: t('klastera.clusters.entities'))
|
12
12
|
)%>"
|
13
13
|
>
|
data/config/locales/es.yml
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
es:
|
2
2
|
klastera:
|
3
|
+
cluster:
|
4
|
+
title: Cluster
|
5
|
+
id: Cluster ID
|
3
6
|
user:
|
4
7
|
add_cluster: Agregar cluster
|
5
|
-
you_need_add_at_least_one_cluster:
|
8
|
+
you_need_add_at_least_one_cluster: Esta organización usa clusters en modo obligatorio. Asigne un cluster al usuario por favor.
|
6
9
|
assign_cluster_role: Asignar role
|
7
10
|
cluster_root_asignation:
|
8
11
|
title: Asignación Routing Super Admin
|
@@ -20,10 +23,11 @@ es:
|
|
20
23
|
cluster_color: Color
|
21
24
|
organization_name: Organización
|
22
25
|
use_cluster_as: Activar y usar cluster como
|
23
|
-
|
24
|
-
|
26
|
+
required_suborganization: Sub-organización Obligatorio
|
27
|
+
optional_suborganization: Sub-organización Opcional
|
25
28
|
optional_filter: Filtro opcional
|
26
29
|
clusters:
|
30
|
+
all: Todos
|
27
31
|
title: Clusters
|
28
32
|
siblings: Seleccione un cluster
|
29
33
|
cant_delete: No se puede eliminar
|
@@ -42,6 +46,7 @@ es:
|
|
42
46
|
required: Para eliminar el Cluster es necesario asignar las entidades asociadas a un nuevo Cluster
|
43
47
|
optional: Entidades asociadas al Cluster pueden quedar sin asignar o ser asignadas a un nuevo Cluster
|
44
48
|
actions:
|
49
|
+
filter: Filtrar
|
45
50
|
cancel: Cancelar
|
46
51
|
add: Agregar
|
47
52
|
delete: Eliminar
|
@@ -52,7 +57,7 @@ es:
|
|
52
57
|
updated: Actualizado
|
53
58
|
messages:
|
54
59
|
record_action_successfully: Registro %{a} exitosamente
|
55
|
-
|
60
|
+
cant_delete_the_last_record_in_required_suborganization_mode: No se puede eliminar el único cluster de esta organización
|
56
61
|
new_cluster_id:
|
57
62
|
nil: Cluster no existe
|
58
63
|
same: Cluster no puede ser el mismo
|
@@ -63,8 +68,8 @@ es:
|
|
63
68
|
popover:
|
64
69
|
title: Descripción de cada opción
|
65
70
|
content: "<ul class='klastera-option-help'><li>%{m1}</li><li>%{m2}</li><li>%{m3}</li></ul>"
|
66
|
-
|
67
|
-
|
71
|
+
required_suborganization: "<b>%{t}</b>: Obliga definir un cluster en las entidades %{e} ."
|
72
|
+
optional_suborganization: "<b>%{t}</b>: Permite definir un cluster en las entidades %{e}."
|
68
73
|
optional_filter: "<b>%{t}</b>: Permite definir un cluster en las entidades %{e} de forma opcional."
|
69
74
|
activemodel:
|
70
75
|
attributes:
|
@@ -2,19 +2,5 @@ class AddClusterOptionsToOrganizations < ActiveRecord::Migration
|
|
2
2
|
def change
|
3
3
|
add_column :organizations, :use_cluster_as, :string
|
4
4
|
add_index :organizations, :use_cluster_as, using: :btree
|
5
|
-
#add_column :organizations, :use_cluster_as_suborganization, :boolean, default: false
|
6
|
-
#add_column :organizations, :use_cluster_as_required_filter, :boolean, default: false
|
7
|
-
#add_column :organizations, :use_cluster_as_optional_filter, :boolean, default: false
|
8
|
-
end
|
9
|
-
|
10
|
-
def migrate(direction)
|
11
|
-
super
|
12
|
-
if direction == :up
|
13
|
-
execute <<-SQL
|
14
|
-
-- COMMENT ON COLUMN "organizations"."use_cluster_as_suborganization" IS 'force_cluster';
|
15
|
-
-- COMMENT ON COLUMN "organizations"."use_cluster_as_required_filter" IS 'use_cluster';
|
16
|
-
-- COMMENT ON COLUMN "organizations"."use_cluster_as_optional_filter" IS 'show_cluster';
|
17
|
-
SQL
|
18
|
-
end
|
19
5
|
end
|
20
6
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class CreateKlasteraClusterUsers < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :cluster_users do |t|
|
4
|
-
t.integer :user_id
|
5
|
-
t.
|
4
|
+
t.integer :user_id, null: false
|
5
|
+
t.integer :cluster_id, null: false
|
6
6
|
end
|
7
7
|
add_column :users, :cluster_role, :string
|
8
8
|
end
|
data/lib/klastera/version.rb
CHANGED
data/lib/klastera.rb
CHANGED
@@ -2,4 +2,114 @@ require "klastera/engine"
|
|
2
2
|
|
3
3
|
module Klastera
|
4
4
|
mattr_accessor :organization_class
|
5
|
-
|
5
|
+
|
6
|
+
class RelatedClusterEntityComplianceError < StandardError; end
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def cluster_scope!(user,organization,scope,includes=[])
|
11
|
+
scope_klass = scope_class(scope)
|
12
|
+
raise RelatedClusterEntityComplianceError, "attribute cluster_id was not found in #{scope_klass}" unless scope_klass.try(:column_names).try(:include?,'cluster_id')
|
13
|
+
scope_klass = scope_klass.includes(includes) if includes.present?
|
14
|
+
scope_klass = scope_klass.where(organization_id: organization)
|
15
|
+
|
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})
|
19
|
+
end
|
20
|
+
|
21
|
+
scope_klass
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# TODO:
|
26
|
+
# Implement a validation to ensure that
|
27
|
+
# object is a ActiveRecord::Base class
|
28
|
+
#
|
29
|
+
##
|
30
|
+
def scope_class(object)
|
31
|
+
object
|
32
|
+
end
|
33
|
+
|
34
|
+
##
|
35
|
+
#
|
36
|
+
#
|
37
|
+
##
|
38
|
+
def session_clusters(user,organization)
|
39
|
+
clusters = []
|
40
|
+
if organization.is_in_cluster_mode?
|
41
|
+
unless user.can_admin_clusters?
|
42
|
+
# TODO: return a Cluster::ActiveRecord_Relation and then remove to_a in ::Cluster.of line
|
43
|
+
clusters = ::ClusterUser.of(user,organization).map{|cu|cu.cluster}
|
44
|
+
else
|
45
|
+
# TODO: remove "to_a" after ClusterUser.of result became a Cluster::ActiveRecord_Relation object
|
46
|
+
clusters = ::Cluster.of(organization).to_a
|
47
|
+
end
|
48
|
+
yield(clusters) if block_given?
|
49
|
+
end
|
50
|
+
clusters
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
included do
|
55
|
+
if respond_to?(:helper_method)
|
56
|
+
helper_method :cluster_scope
|
57
|
+
helper_method :user_cluster
|
58
|
+
helper_method :cluster_user
|
59
|
+
helper_method :cluster_organization
|
60
|
+
helper_method :cluster_clusters
|
61
|
+
end
|
62
|
+
if respond_to?(:hide_action)
|
63
|
+
hide_action :cluster_scope
|
64
|
+
hide_action :cluster_scope=
|
65
|
+
hide_action :user_cluster
|
66
|
+
hide_action :user_cluster=
|
67
|
+
hide_action :cluster_user
|
68
|
+
hide_action :cluster_user=
|
69
|
+
hide_action :cluster_organization
|
70
|
+
hide_action :cluster_organization=
|
71
|
+
hide_action :cluster_clusters
|
72
|
+
hide_action :cluster_clusters=
|
73
|
+
end
|
74
|
+
before_action :set_the_lonely_cluster, only: %i[ create update ]
|
75
|
+
end
|
76
|
+
|
77
|
+
def set_the_lonely_cluster
|
78
|
+
form_model = params[:controller].singularize
|
79
|
+
parameters = params.require( form_model ) rescue nil
|
80
|
+
lonely_cluster = parameters.blank? ? false : parameters.permit( :lonely_cluster ).present?
|
81
|
+
if lonely_cluster
|
82
|
+
params[form_model][:cluster_id] = ::ClusterUser.of(cluster_user,cluster_organization).first.try(:cluster_id)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def cluster_scope(scope,includes=[])
|
87
|
+
Klastera.cluster_scope!(cluster_user,cluster_organization,scope,includes)
|
88
|
+
end
|
89
|
+
|
90
|
+
def cluster_user
|
91
|
+
current_user
|
92
|
+
end
|
93
|
+
|
94
|
+
def cluster_organization
|
95
|
+
current_organization
|
96
|
+
end
|
97
|
+
|
98
|
+
def cluster_clusters
|
99
|
+
Klastera.session_clusters(cluster_user,cluster_organization).map{|c|[c.name,c.id]}
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_cluster_filter
|
103
|
+
@filter = ::ClusterFilter.new(cluster_filter_params)
|
104
|
+
end
|
105
|
+
|
106
|
+
def cluster_filter_params
|
107
|
+
parameters = params.require(:cluster_filter) rescue nil
|
108
|
+
return {} if parameters.blank?
|
109
|
+
parameters.permit(*cluster_filter_permit_params)
|
110
|
+
end
|
111
|
+
|
112
|
+
def cluster_filter_permit_params
|
113
|
+
[ :cluster_id ].concat( ::ClusterFilter.attributes )
|
114
|
+
end
|
115
|
+
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.0
|
4
|
+
version: 1.1.0
|
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-
|
11
|
+
date: 2020-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -58,9 +58,12 @@ files:
|
|
58
58
|
- app/helpers/klastera/application_helper.rb
|
59
59
|
- app/helpers/klastera/clusters_helper.rb
|
60
60
|
- app/models/klastera/cluster.rb
|
61
|
+
- app/models/klastera/cluster_filter.rb
|
61
62
|
- app/models/klastera/cluster_user.rb
|
62
63
|
- app/models/klastera/concerns/cluster.rb
|
64
|
+
- app/models/klastera/concerns/cluster_filter.rb
|
63
65
|
- app/models/klastera/concerns/cluster_user.rb
|
66
|
+
- app/models/klastera/concerns/clusterizable.rb
|
64
67
|
- app/models/klastera/concerns/organization.rb
|
65
68
|
- app/models/klastera/concerns/transfer.rb
|
66
69
|
- app/models/klastera/concerns/user.rb
|
@@ -76,7 +79,9 @@ files:
|
|
76
79
|
- app/views/klastera/clusters/new.html.erb
|
77
80
|
- app/views/klastera/clusters/transfer.html.erb
|
78
81
|
- app/views/klastera/clusters/update.js.erb
|
82
|
+
- app/views/layouts/klastera/_cluster_filter.html.erb
|
79
83
|
- app/views/layouts/klastera/_cluster_role.html.erb
|
84
|
+
- app/views/layouts/klastera/_cluster_selector.html.erb
|
80
85
|
- app/views/layouts/klastera/_cluster_user_fields.html.erb
|
81
86
|
- app/views/layouts/klastera/_nested_cluster_user.html.erb
|
82
87
|
- app/views/layouts/klastera/_options.html.erb
|