klastera 1.5.2.5 → 1.5.3
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
- metadata +9 -81
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -3
- data/Rakefile +0 -37
- data/app/assets/javascripts/klastera/application.js +0 -13
- data/app/assets/javascripts/klastera/clusters.js +0 -2
- data/app/assets/stylesheets/klastera/clusters.scss +0 -46
- data/app/controllers/klastera/application_controller.rb +0 -29
- data/app/controllers/klastera/clusters_controller.rb +0 -60
- data/app/helpers/klastera/application_helper.rb +0 -40
- data/app/models/klastera/cluster.rb +0 -5
- data/app/models/klastera/cluster_entity.rb +0 -5
- data/app/models/klastera/cluster_filter.rb +0 -5
- data/app/models/klastera/cluster_user.rb +0 -5
- data/app/models/klastera/concerns/cluster.rb +0 -67
- data/app/models/klastera/concerns/cluster_entity.rb +0 -18
- data/app/models/klastera/concerns/cluster_filter.rb +0 -22
- data/app/models/klastera/concerns/cluster_user.rb +0 -41
- data/app/models/klastera/concerns/clusterizable.rb +0 -57
- data/app/models/klastera/concerns/organization.rb +0 -49
- data/app/models/klastera/concerns/transfer.rb +0 -45
- data/app/models/klastera/concerns/user.rb +0 -77
- data/app/models/klastera/transfer.rb +0 -5
- data/app/views/klastera/clusters/_filter.html.erb +0 -0
- data/app/views/klastera/clusters/_form.html.erb +0 -22
- data/app/views/klastera/clusters/_form_transfer.html.erb +0 -34
- data/app/views/klastera/clusters/_table.html.erb +0 -33
- data/app/views/klastera/clusters/create.js.erb +0 -1
- data/app/views/klastera/clusters/destroy.js.erb +0 -6
- data/app/views/klastera/clusters/edit.html.erb +0 -10
- data/app/views/klastera/clusters/index.html.erb +0 -21
- data/app/views/klastera/clusters/new.html.erb +0 -10
- data/app/views/klastera/clusters/transfer.html.erb +0 -10
- data/app/views/klastera/clusters/update.js.erb +0 -1
- data/app/views/layouts/klastera/_cluster_entity_fields.html.erb +0 -10
- data/app/views/layouts/klastera/_cluster_filter.html.erb +0 -23
- data/app/views/layouts/klastera/_cluster_role.html.erb +0 -48
- data/app/views/layouts/klastera/_cluster_selector.html.erb +0 -21
- data/app/views/layouts/klastera/_cluster_user_fields.html.erb +0 -10
- data/app/views/layouts/klastera/_nested_cluster_entity.html.erb +0 -43
- data/app/views/layouts/klastera/_nested_cluster_user.html.erb +0 -22
- data/app/views/layouts/klastera/_options.html.erb +0 -21
- data/config/locales/es.yml +0 -96
- data/config/routes.rb +0 -7
- data/db/migrate/20200324203929_create_klastera_clusters.rb +0 -12
- data/db/migrate/20200326111219_add_cluster_options_to_organizations.rb +0 -6
- data/db/migrate/20200330010551_create_klastera_cluster_users.rb +0 -9
- data/db/migrate/20200330221601_add_order_field_to_clusters.rb +0 -5
- data/db/migrate/20200518142609_create_klastera_cluster_entities.rb +0 -8
- data/db/migrate/20200908180057_add_cluster_config_to_organization.rb +0 -5
- data/db/migrate/20220602222332_add_unique_index_to_cluster_entities.rb +0 -5
- data/db/migrate/20250429110829_add_entity_id_index_to_cluster_entities.rb +0 -6
- data/db/migrate/20250429110830_add_entity_id_index_and_entity_type_index_to_cluster_entities.klastera.rb +0 -7
- data/lib/klastera/engine.rb +0 -5
- data/lib/klastera/version.rb +0 -3
- data/lib/klastera.rb +0 -236
- data/lib/tasks/klastera_tasks.rake +0 -32
- data/test/controllers/klastera/clusters_controller_test.rb +0 -52
- data/test/fixtures/klastera/cluster_users.yml +0 -9
- data/test/fixtures/klastera/clusters.yml +0 -11
- data/test/integration/navigation_test.rb +0 -8
- data/test/klastera_test.rb +0 -7
- data/test/models/klastera/cluster_test.rb +0 -9
- data/test/models/klastera/cluster_user_test.rb +0 -9
- data/test/test_helper.rb +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26024cfbeac47db7de270c9281e98d197b377f53c4122fb4a6eec246dae615cb
|
4
|
+
data.tar.gz: f452de2debec0cc4c34549ec98f5dcd387cbb8d32102ed6924ff06ccc89b90cd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '096e198a76a0d1f12b83339d76d9fc6f83c64ac3b893b5dafc5ef1b77f4179aee49b146e1be92d2f9ae9b572c4d108dbc3bb9ba80c78a6404459850a1dcd4265'
|
7
|
+
data.tar.gz: 416ef7b6a278be2686cf613b5ea5382bd728a480486217f2a2b3511677d93b4631a0818cc08a1a94f74bcf7bc57c7598a3f871a901f14f116b817f8b4ec1dcfe
|
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.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gino Barahona
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 6.1.3
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 6.1.3
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pg
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,76 +44,12 @@ email:
|
|
44
44
|
executables: []
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
|
-
files:
|
48
|
-
- MIT-LICENSE
|
49
|
-
- README.rdoc
|
50
|
-
- Rakefile
|
51
|
-
- app/assets/javascripts/klastera/application.js
|
52
|
-
- app/assets/javascripts/klastera/clusters.js
|
53
|
-
- app/assets/stylesheets/klastera/clusters.scss
|
54
|
-
- app/controllers/klastera/application_controller.rb
|
55
|
-
- app/controllers/klastera/clusters_controller.rb
|
56
|
-
- app/helpers/klastera/application_helper.rb
|
57
|
-
- app/models/klastera/cluster.rb
|
58
|
-
- app/models/klastera/cluster_entity.rb
|
59
|
-
- app/models/klastera/cluster_filter.rb
|
60
|
-
- app/models/klastera/cluster_user.rb
|
61
|
-
- app/models/klastera/concerns/cluster.rb
|
62
|
-
- app/models/klastera/concerns/cluster_entity.rb
|
63
|
-
- app/models/klastera/concerns/cluster_filter.rb
|
64
|
-
- app/models/klastera/concerns/cluster_user.rb
|
65
|
-
- app/models/klastera/concerns/clusterizable.rb
|
66
|
-
- app/models/klastera/concerns/organization.rb
|
67
|
-
- app/models/klastera/concerns/transfer.rb
|
68
|
-
- app/models/klastera/concerns/user.rb
|
69
|
-
- app/models/klastera/transfer.rb
|
70
|
-
- app/views/klastera/clusters/_filter.html.erb
|
71
|
-
- app/views/klastera/clusters/_form.html.erb
|
72
|
-
- app/views/klastera/clusters/_form_transfer.html.erb
|
73
|
-
- app/views/klastera/clusters/_table.html.erb
|
74
|
-
- app/views/klastera/clusters/create.js.erb
|
75
|
-
- app/views/klastera/clusters/destroy.js.erb
|
76
|
-
- app/views/klastera/clusters/edit.html.erb
|
77
|
-
- app/views/klastera/clusters/index.html.erb
|
78
|
-
- app/views/klastera/clusters/new.html.erb
|
79
|
-
- app/views/klastera/clusters/transfer.html.erb
|
80
|
-
- app/views/klastera/clusters/update.js.erb
|
81
|
-
- app/views/layouts/klastera/_cluster_entity_fields.html.erb
|
82
|
-
- app/views/layouts/klastera/_cluster_filter.html.erb
|
83
|
-
- app/views/layouts/klastera/_cluster_role.html.erb
|
84
|
-
- app/views/layouts/klastera/_cluster_selector.html.erb
|
85
|
-
- app/views/layouts/klastera/_cluster_user_fields.html.erb
|
86
|
-
- app/views/layouts/klastera/_nested_cluster_entity.html.erb
|
87
|
-
- app/views/layouts/klastera/_nested_cluster_user.html.erb
|
88
|
-
- app/views/layouts/klastera/_options.html.erb
|
89
|
-
- config/locales/es.yml
|
90
|
-
- config/routes.rb
|
91
|
-
- db/migrate/20200324203929_create_klastera_clusters.rb
|
92
|
-
- db/migrate/20200326111219_add_cluster_options_to_organizations.rb
|
93
|
-
- db/migrate/20200330010551_create_klastera_cluster_users.rb
|
94
|
-
- db/migrate/20200330221601_add_order_field_to_clusters.rb
|
95
|
-
- db/migrate/20200518142609_create_klastera_cluster_entities.rb
|
96
|
-
- db/migrate/20200908180057_add_cluster_config_to_organization.rb
|
97
|
-
- db/migrate/20220602222332_add_unique_index_to_cluster_entities.rb
|
98
|
-
- db/migrate/20250429110829_add_entity_id_index_to_cluster_entities.rb
|
99
|
-
- db/migrate/20250429110830_add_entity_id_index_and_entity_type_index_to_cluster_entities.klastera.rb
|
100
|
-
- lib/klastera.rb
|
101
|
-
- lib/klastera/engine.rb
|
102
|
-
- lib/klastera/version.rb
|
103
|
-
- lib/tasks/klastera_tasks.rake
|
104
|
-
- test/controllers/klastera/clusters_controller_test.rb
|
105
|
-
- test/fixtures/klastera/cluster_users.yml
|
106
|
-
- test/fixtures/klastera/clusters.yml
|
107
|
-
- test/integration/navigation_test.rb
|
108
|
-
- test/klastera_test.rb
|
109
|
-
- test/models/klastera/cluster_test.rb
|
110
|
-
- test/models/klastera/cluster_user_test.rb
|
111
|
-
- test/test_helper.rb
|
47
|
+
files: []
|
112
48
|
homepage: https://github.com/ginosx/klastera
|
113
49
|
licenses:
|
114
50
|
- MIT
|
115
51
|
metadata: {}
|
116
|
-
post_install_message:
|
52
|
+
post_install_message:
|
117
53
|
rdoc_options: []
|
118
54
|
require_paths:
|
119
55
|
- lib
|
@@ -129,15 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
65
|
version: '0'
|
130
66
|
requirements: []
|
131
67
|
rubygems_version: 3.1.6
|
132
|
-
signing_key:
|
68
|
+
signing_key:
|
133
69
|
specification_version: 4
|
134
70
|
summary: Clusterization Engine
|
135
|
-
test_files:
|
136
|
-
- test/controllers/klastera/clusters_controller_test.rb
|
137
|
-
- test/integration/navigation_test.rb
|
138
|
-
- test/fixtures/klastera/clusters.yml
|
139
|
-
- test/fixtures/klastera/cluster_users.yml
|
140
|
-
- test/test_helper.rb
|
141
|
-
- test/models/klastera/cluster_user_test.rb
|
142
|
-
- test/models/klastera/cluster_test.rb
|
143
|
-
- test/klastera_test.rb
|
71
|
+
test_files: []
|
data/MIT-LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright 2020 Gino Barahona
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
DELETED
data/Rakefile
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'bundler/setup'
|
3
|
-
rescue LoadError
|
4
|
-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
-
end
|
6
|
-
|
7
|
-
require 'rdoc/task'
|
8
|
-
|
9
|
-
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
-
rdoc.rdoc_dir = 'rdoc'
|
11
|
-
rdoc.title = 'Klastera'
|
12
|
-
rdoc.options << '--line-numbers'
|
13
|
-
rdoc.rdoc_files.include('README.rdoc')
|
14
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
-
end
|
16
|
-
|
17
|
-
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
-
load 'rails/tasks/engine.rake'
|
19
|
-
|
20
|
-
|
21
|
-
load 'rails/tasks/statistics.rake'
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
Bundler::GemHelper.install_tasks
|
26
|
-
|
27
|
-
require 'rake/testtask'
|
28
|
-
|
29
|
-
Rake::TestTask.new(:test) do |t|
|
30
|
-
t.libs << 'lib'
|
31
|
-
t.libs << 'test'
|
32
|
-
t.pattern = 'test/**/*_test.rb'
|
33
|
-
t.verbose = false
|
34
|
-
end
|
35
|
-
|
36
|
-
|
37
|
-
task default: :test
|
@@ -1,13 +0,0 @@
|
|
1
|
-
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
-
// listed below.
|
3
|
-
//
|
4
|
-
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
-
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
-
//
|
7
|
-
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
-
// compiled file.
|
9
|
-
//
|
10
|
-
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
-
// about supported directives.
|
12
|
-
//
|
13
|
-
//= require_tree .
|
@@ -1,46 +0,0 @@
|
|
1
|
-
.nested-cluster-user,
|
2
|
-
.nested-cluster-entity {
|
3
|
-
.panel {
|
4
|
-
margin: 0;
|
5
|
-
border-bottom: 0;
|
6
|
-
.panel-heading {
|
7
|
-
padding: 10px 12px 10px 15px;
|
8
|
-
background: none;
|
9
|
-
}
|
10
|
-
}
|
11
|
-
}
|
12
|
-
|
13
|
-
#cluster-remote-table {
|
14
|
-
.cluster-id { width: 70px; }
|
15
|
-
.cluster-order { width: 70px; }
|
16
|
-
.cluster-color { width: 70px; }
|
17
|
-
.odd .colorless { color: #F9F9F9 }
|
18
|
-
.even .colorless { color: #FFF }
|
19
|
-
tr:hover .colorless { color: #444; opacity: 0.2;}
|
20
|
-
}
|
21
|
-
|
22
|
-
#cluster-remote-form {
|
23
|
-
h4.blank-modal-title {
|
24
|
-
margin: 0;
|
25
|
-
line-height: 28px;
|
26
|
-
letter-spacing: 0.05rem;
|
27
|
-
font-size: 21px;
|
28
|
-
font-weight: 400;
|
29
|
-
color: #666;
|
30
|
-
}
|
31
|
-
}
|
32
|
-
|
33
|
-
|
34
|
-
ul.klastera-option-help {
|
35
|
-
padding-left: 20px;
|
36
|
-
list-style-type: disc;
|
37
|
-
}
|
38
|
-
|
39
|
-
ul.klastera-option-help li {
|
40
|
-
margin-bottom: 10px;
|
41
|
-
padding-bottom: 5px;
|
42
|
-
border-bottom: 1px solid #DDD;
|
43
|
-
}
|
44
|
-
|
45
|
-
ul.klastera-option-help li b { color: #8A8A8A; font-weight: 400; }
|
46
|
-
ul.klastera-option-help li b:first-child { color: #2E5F9B; font-weight: bold; }
|
@@ -1,29 +0,0 @@
|
|
1
|
-
module Klastera
|
2
|
-
class ApplicationController < ::ApplicationController
|
3
|
-
protect_from_forgery with: :exception
|
4
|
-
layout :disable_in_xhr_requests
|
5
|
-
before_action :set_xhr_render_session
|
6
|
-
before_action :check_access_to_cluster_admin
|
7
|
-
|
8
|
-
def check_access_to_cluster_admin
|
9
|
-
unless cluster_user.can_admin_clusters?
|
10
|
-
redirect_to main_app.root_path, flash: { alert: t('klastera.messages.access_cluster_admin') }
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
if respond_to?(:skip_after_action)
|
15
|
-
skip_after_action :verify_authorized
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
def disable_in_xhr_requests
|
20
|
-
request.xhr? ? false : nil
|
21
|
-
end
|
22
|
-
|
23
|
-
def set_xhr_render_session
|
24
|
-
return unless request.get?
|
25
|
-
# request.xhr? return nil when this is not a XHR request, but we need a boolean
|
26
|
-
session[:xhr_render] = request.xhr?.present?
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
require_dependency "klastera/application_controller"
|
2
|
-
|
3
|
-
module Klastera
|
4
|
-
class ClustersController < ApplicationController
|
5
|
-
before_action :set_cluster, only: %i[ edit update destroy transfer ]
|
6
|
-
before_action :set_clusters, only: %i[ index ]
|
7
|
-
|
8
|
-
def index; end
|
9
|
-
|
10
|
-
def new
|
11
|
-
@cluster = ::Cluster.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def edit; end
|
15
|
-
|
16
|
-
def transfer
|
17
|
-
@transfer = Transfer.new
|
18
|
-
end
|
19
|
-
|
20
|
-
def create
|
21
|
-
@cluster = ::Cluster.new(cluster_params)
|
22
|
-
if @cluster.save
|
23
|
-
@cluster = ::Cluster.new
|
24
|
-
set_clusters
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def update
|
29
|
-
if @cluster.update(cluster_params)
|
30
|
-
set_clusters
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def destroy
|
35
|
-
new_cluster_id = params.require(:transfer).permit(:new_cluster_id).values.first rescue nil
|
36
|
-
@transfer = Transfer.new( current_cluster: @cluster, new_cluster_id: new_cluster_id )
|
37
|
-
if @transfer.valid?
|
38
|
-
if @transfer.apply!
|
39
|
-
@cluster.destroy
|
40
|
-
end
|
41
|
-
set_clusters
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
def set_cluster
|
47
|
-
@cluster = ::Cluster.find(params[:id])
|
48
|
-
end
|
49
|
-
|
50
|
-
def set_clusters
|
51
|
-
@clusters = cluster_organization.clusters
|
52
|
-
end
|
53
|
-
|
54
|
-
def cluster_params
|
55
|
-
parameters = params.require(:cluster).permit(:nid, :name, :color, :order)
|
56
|
-
parameters[:organization_id]=cluster_organization.id
|
57
|
-
parameters
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Klastera
|
2
|
-
module ApplicationHelper
|
3
|
-
def ac_errors_as_html_list(errors)
|
4
|
-
array_as_html_list(
|
5
|
-
errors.messages.inject([]) do |array,(attr,errors_array)|
|
6
|
-
array.concat(errors_array)
|
7
|
-
array
|
8
|
-
end
|
9
|
-
)
|
10
|
-
end
|
11
|
-
|
12
|
-
def array_as_html_list(array)
|
13
|
-
"<ul style='padding:0;'><li>#{array.join("</li><li>")}</li></ul>".html_safe
|
14
|
-
end
|
15
|
-
|
16
|
-
def method_missing(method, *args, &block)
|
17
|
-
if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
|
18
|
-
if main_app.respond_to?(method)
|
19
|
-
main_app.send(method, *args)
|
20
|
-
else
|
21
|
-
super
|
22
|
-
end
|
23
|
-
else
|
24
|
-
super
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def respond_to?(method, include_priv=false)
|
29
|
-
if method.to_s.end_with?('_path') or method.to_s.end_with?('_url')
|
30
|
-
if main_app.respond_to?(method,include_priv)
|
31
|
-
true
|
32
|
-
else
|
33
|
-
super
|
34
|
-
end
|
35
|
-
else
|
36
|
-
super
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
module Klastera::Concerns::Cluster
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
# 'included do' causes the included code to be evaluated in the
|
4
|
-
# context where it is included (cluster.rb), rather than being
|
5
|
-
# executed in the module's context (klastera/concerns/models/cluster).
|
6
|
-
included do
|
7
|
-
self.table_name = 'clusters'
|
8
|
-
|
9
|
-
attr_reader :last_record
|
10
|
-
|
11
|
-
REQUIRED_MODE = :required_suborganization.freeze
|
12
|
-
OPTIONAL_MODE = :optional_suborganization.freeze
|
13
|
-
MODES = [ REQUIRED_MODE, OPTIONAL_MODE ].freeze
|
14
|
-
|
15
|
-
belongs_to :organization, class_name: Klastera.organization_class
|
16
|
-
has_many :cluster_users
|
17
|
-
has_many :cluster_entities, dependent: :destroy
|
18
|
-
|
19
|
-
scope :of, -> (organization,except_ids=[]) {
|
20
|
-
_scope = where(organization: organization)
|
21
|
-
_scope = _scope.where.not(id: except_ids) unless except_ids.blank?
|
22
|
-
_scope
|
23
|
-
}
|
24
|
-
|
25
|
-
validates :name, presence: true
|
26
|
-
validates :nid, presence: true
|
27
|
-
validates :organization_id, presence: true
|
28
|
-
|
29
|
-
validates_uniqueness_of :nid, scope: [:nid, :organization_id]
|
30
|
-
|
31
|
-
before_destroy do |record|
|
32
|
-
self.can_transfer_and_destroy?
|
33
|
-
end
|
34
|
-
|
35
|
-
def siblings
|
36
|
-
::Cluster.of(self.organization,[self.id])
|
37
|
-
end
|
38
|
-
|
39
|
-
def is_the_last_record_in_required_suborganization_mode?
|
40
|
-
self.organization.required_suborganization_mode? && self.siblings.blank?
|
41
|
-
end
|
42
|
-
|
43
|
-
def required_transfer?
|
44
|
-
self.organization.required_suborganization_mode?
|
45
|
-
end
|
46
|
-
|
47
|
-
def has_related_entities_using_it?
|
48
|
-
self.cluster_entities.size > 0
|
49
|
-
end
|
50
|
-
|
51
|
-
def can_transfer_and_destroy?
|
52
|
-
can_destroy = true
|
53
|
-
if is_the_last_record_in_required_suborganization_mode?
|
54
|
-
errors.add(:last_record, I18n.t('klastera.messages.cant_delete_the_last_record_in_required_suborganization_mode'))
|
55
|
-
can_destroy = false
|
56
|
-
end
|
57
|
-
can_destroy
|
58
|
-
end
|
59
|
-
|
60
|
-
def display_name_nid
|
61
|
-
"#{name} (#{nid==Klastera::UNCLUSTERED_ENTITY ? I18n.t("klastera.#{ Klastera::UNCLUSTERED_ENTITY}") : nid})"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
module ClassMethods
|
66
|
-
end
|
67
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Klastera::Concerns::ClusterEntity
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
self.table_name = 'cluster_entities'
|
6
|
-
belongs_to :entity, polymorphic: true
|
7
|
-
belongs_to :cluster, class_name: "::Cluster"
|
8
|
-
end
|
9
|
-
|
10
|
-
module ClassMethods
|
11
|
-
def left_join_sources_of(scope_klass)
|
12
|
-
scope_klass_arel_table = scope_klass.arel_table
|
13
|
-
scope_klass_arel_table.join(arel_table, Arel::Nodes::OuterJoin).on(
|
14
|
-
scope_klass_arel_table[:id].eq(arel_table[:entity_id]), arel_table[:entity_type].eq(scope_klass.name)
|
15
|
-
).join_sources
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Klastera::Concerns::ClusterFilter
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
include ActiveModel::Model
|
6
|
-
include ActiveModel::Validations::Callbacks
|
7
|
-
|
8
|
-
attr_accessor :cluster_id
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
def attr_accessor(*vars)
|
13
|
-
@attributes ||= []
|
14
|
-
@attributes.concat vars
|
15
|
-
super(*vars)
|
16
|
-
end
|
17
|
-
|
18
|
-
def attributes
|
19
|
-
@attributes
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module Klastera::Concerns::ClusterUser
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
self.table_name = 'cluster_users'
|
6
|
-
belongs_to :user
|
7
|
-
belongs_to :cluster
|
8
|
-
validates :cluster_id, presence: true
|
9
|
-
end
|
10
|
-
|
11
|
-
module ClassMethods
|
12
|
-
##
|
13
|
-
# Return a Cluster::ActiveRecord_Relation of organization (and) user
|
14
|
-
#
|
15
|
-
def clusters_of(organization,and_user=nil)
|
16
|
-
and_user_id = and_user.present? ? { users: { id: and_user } } : {}
|
17
|
-
::Cluster.eager_load(cluster_users: :user).where({ organization_id: organization }.merge(and_user_id) ).order(order: :asc)
|
18
|
-
end
|
19
|
-
|
20
|
-
##
|
21
|
-
# Return a User::ActiveRecord_Relation of organization (and) user
|
22
|
-
#
|
23
|
-
def users_of(organization)
|
24
|
-
::User.eager_load(:cluster_users).where(users: { organization_id: organization } )
|
25
|
-
end
|
26
|
-
|
27
|
-
##
|
28
|
-
# Return a hash of users and its clusters
|
29
|
-
#
|
30
|
-
def users_hash_of(organization)
|
31
|
-
users = {}
|
32
|
-
rows = self.users_of(organization).pluck("users.id AS user_id","cluster_users.cluster_id").uniq
|
33
|
-
rows.each do |row|
|
34
|
-
user_id = row.first
|
35
|
-
users[user_id] ||= []
|
36
|
-
users[user_id] << row.last
|
37
|
-
end
|
38
|
-
users
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,57 +0,0 @@
|
|
1
|
-
module Klastera::Concerns::Clusterizable
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
class MutipleClustersOperationError < StandardError; end
|
6
|
-
|
7
|
-
belongs_to :cluster
|
8
|
-
|
9
|
-
has_many :cluster_entities, as: :entity, class_name: "Klastera::ClusterEntity"
|
10
|
-
accepts_nested_attributes_for :cluster_entities, reject_if: :all_blank, allow_destroy: true
|
11
|
-
|
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? }
|
14
|
-
validate :uniqueness_of_cluster_entity_record
|
15
|
-
|
16
|
-
scope :includes_cluster, -> { includes(cluster_entities: :cluster) }
|
17
|
-
|
18
|
-
def at_least_one_cluster_entity
|
19
|
-
if cluster_entities.length == 0 || cluster_entities.reject{|cluster_entity| cluster_entity._destroy == true}.empty?
|
20
|
-
return errors.add(:cluster_entities, I18n.t('klastera.messages.at_least_one_cluster_entity'))
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def allow_multiple_clusters?(default=:one)
|
25
|
-
organization.present? && organization.cluster_cardinality_of(self.class, default: default) == :many
|
26
|
-
end
|
27
|
-
|
28
|
-
##
|
29
|
-
# This is a legacy method and we don't recommend using it.
|
30
|
-
# Implement directly Klastera.entity_clusters_string_list instead of this method.
|
31
|
-
# TODO: In order to deprecate it, you will need to perform some changes in the main app
|
32
|
-
##
|
33
|
-
def clusters_string_separated_by(separator,attribute=:name)
|
34
|
-
Klastera.entity_clusters_string_list!(
|
35
|
-
cluster_entities, separator, attribute
|
36
|
-
)
|
37
|
-
end
|
38
|
-
|
39
|
-
def has_one_cluster_entity
|
40
|
-
if cluster_entities.length > 1
|
41
|
-
return errors.add(:cluster_entities, I18n.t('klastera.messages.has_one_cluster_entity'))
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def uniqueness_of_cluster_entity_record
|
46
|
-
if cluster_entities.map(&:cluster_id).uniq.size != cluster_entities.size
|
47
|
-
return errors.add(:cluster_entities, I18n.t('klastera.messages.duplicated_cluster_entity') )
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
module ClassMethods
|
53
|
-
def cluster_entity_params
|
54
|
-
[ :cluster_id, { cluster_entities_attributes: [:id, :cluster_id, :_destroy] } ]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|