klastera 1.5.2.4 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +7 -77
- 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/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
data/lib/klastera/engine.rb
DELETED
data/lib/klastera/version.rb
DELETED
data/lib/klastera.rb
DELETED
@@ -1,236 +0,0 @@
|
|
1
|
-
require "klastera/engine"
|
2
|
-
|
3
|
-
module Klastera
|
4
|
-
mattr_accessor :organization_class
|
5
|
-
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
UNCLUSTERED_POSITION = 9999
|
9
|
-
UNCLUSTERED_ENTITY = 'without_cluster'.freeze
|
10
|
-
KLSTR_HELPERS = %i[ cluster_user cluster_organization cluster_list cluster_scope cluster_scope_through_of user_clusters_string_list cluster_scope_left_join ].freeze
|
11
|
-
|
12
|
-
class << self
|
13
|
-
|
14
|
-
##
|
15
|
-
# TODO:
|
16
|
-
# Implement a validation to ensure that
|
17
|
-
# object is a ActiveRecord::Base class
|
18
|
-
# (or just try to guess how to retrieve the argument class)
|
19
|
-
#
|
20
|
-
##
|
21
|
-
def scope_class(object)
|
22
|
-
object
|
23
|
-
end
|
24
|
-
|
25
|
-
##
|
26
|
-
# Returns which clusters a user can see avoiding unnecessary queries if the cluster restraint doesn't apply
|
27
|
-
#
|
28
|
-
def cluster_list!(organization,user,include_unclustered=true)
|
29
|
-
# Only the cluster mode on and the mandatory user-cluster relation will use a join clause to get the clusters list
|
30
|
-
if organization.is_in_cluster_mode? && user.cannot_skip_cluster_clause?
|
31
|
-
active_record_collection = ::ClusterUser.clusters_of(organization,user)
|
32
|
-
else
|
33
|
-
active_record_collection = ::Cluster.where({ organization_id: organization }).order(order: :asc)
|
34
|
-
end
|
35
|
-
|
36
|
-
active_record_collection = active_record_collection.order(order: :asc)
|
37
|
-
|
38
|
-
if include_unclustered && organization.optional_suborganization_mode? # For show and use modes only
|
39
|
-
active_record_collection.to_a.append(
|
40
|
-
::Cluster.new({nid: UNCLUSTERED_ENTITY, name: I18n.t("klastera.#{UNCLUSTERED_ENTITY}"), order: UNCLUSTERED_POSITION })
|
41
|
-
)
|
42
|
-
end
|
43
|
-
active_record_collection
|
44
|
-
end
|
45
|
-
|
46
|
-
##
|
47
|
-
# Return a string with cluster attribute separated by separator argument
|
48
|
-
# A array of cluster ids can be passed fo filter the result
|
49
|
-
#
|
50
|
-
def entity_clusters_string_list!(cluster_entities,separator,attribute=:name,allowed_cluster_ids=nil)
|
51
|
-
_cluster_entities = cluster_entities.reject(&:nil?)
|
52
|
-
if allowed_cluster_ids.is_a?(Array)
|
53
|
-
_cluster_entities.select!{|ce| allowed_cluster_ids.include?(ce.cluster_id)}
|
54
|
-
end
|
55
|
-
_cluster_entities.map do |ce|
|
56
|
-
ce.cluster.try(attribute)
|
57
|
-
end.compact.sort.join(separator)
|
58
|
-
end
|
59
|
-
|
60
|
-
##
|
61
|
-
# cluster_list! needs a user and a organization. that why we perfomed this logic here
|
62
|
-
#
|
63
|
-
def user_clusters_string_list!(user,organization,cluster_entities,separator,attribute=:name)
|
64
|
-
@clusters_session ||= Klastera.cluster_list!(organization,user)
|
65
|
-
self.entity_clusters_string_list!(cluster_entities, separator, attribute, @clusters_session.map(&:id))
|
66
|
-
end
|
67
|
-
|
68
|
-
#
|
69
|
-
# We will try to avoid cluster clause except when:
|
70
|
-
# 1.- cluster mode is active
|
71
|
-
# AND
|
72
|
-
# 2a.- cluster_filter is present (someone wants to filter by cluster)
|
73
|
-
# OR
|
74
|
-
# 2b.- the current user has some limitations and must checks they cluster relation
|
75
|
-
# - User is having clusters in optional_suborganization mode
|
76
|
-
# - User IS NOT having clusters in required_suborganization mode
|
77
|
-
#
|
78
|
-
# For the other hand, with force_cluster_clause we can skip the previous logic if
|
79
|
-
# cluster_filter_id is present when the optional_suborganization mode is on. BUT!
|
80
|
-
# Be aware that if the cluster_filter is not present, the value of force_cluster_clause
|
81
|
-
# will be overridden by the returned value of cannot_skip_cluster_clause? method.
|
82
|
-
def should_clusterize_scope?(user, organization, cluster_filter=nil, force_cluster_clause=false)
|
83
|
-
should = false # I don't know if this is a good idea
|
84
|
-
if organization.is_in_cluster_mode? && ( cluster_filter.present? || force_cluster_clause = user.cannot_skip_cluster_clause? ) # yes, this is an assignation
|
85
|
-
cluster_ids = []
|
86
|
-
# Set another variable as array to get the cluster id(s)
|
87
|
-
if cluster_filter.present?
|
88
|
-
cluster_ids = cluster_filter.is_a?(Array) ? cluster_filter : [cluster_filter]
|
89
|
-
elsif force_cluster_clause
|
90
|
-
cluster_ids = ::ClusterUser.clusters_of(organization,user).map(&:id)
|
91
|
-
end
|
92
|
-
# We will avoid the query unless cluster_ids is having values OR force_cluster_clause is set (see method description)
|
93
|
-
if cluster_ids.present? || force_cluster_clause
|
94
|
-
# We add the unclustered if the value of cluster_filter have the special without_cluster string or as method description says
|
95
|
-
if cluster_ids.delete(UNCLUSTERED_ENTITY) || ( force_cluster_clause && organization.optional_suborganization_mode? )
|
96
|
-
cluster_ids << nil
|
97
|
-
end
|
98
|
-
should = true
|
99
|
-
end
|
100
|
-
end
|
101
|
-
yield(should,cluster_ids)
|
102
|
-
end
|
103
|
-
|
104
|
-
#
|
105
|
-
# The cleanest and fast way to clusterize a entity!
|
106
|
-
#
|
107
|
-
def cluster_scope!(scope_klass, user, organization, cluster_filter=nil, force_cluster_clause=false)
|
108
|
-
scope = scope_class(scope_klass)
|
109
|
-
should_clusterize_scope?(user,organization,cluster_filter,force_cluster_clause) do |should,cluster_ids|
|
110
|
-
if should
|
111
|
-
scope = scope.eager_load(:organization,cluster_entities: :cluster).where( cluster_entities: { cluster_id: cluster_ids } )
|
112
|
-
end
|
113
|
-
end
|
114
|
-
scope.where(organization_id: organization)
|
115
|
-
end
|
116
|
-
|
117
|
-
#
|
118
|
-
# Filter non-clustered entity through a clusterized one
|
119
|
-
#
|
120
|
-
def cluster_scope_through_of!(relation, cluster_entity_klass, scope_klass, user, organization, cluster_filter=nil, force_cluster_clause=false)
|
121
|
-
unclusterized_scope = scope_class(scope_klass)
|
122
|
-
|
123
|
-
if organization.is_in_cluster_mode? && ( force_cluster_clause || user.cannot_skip_cluster_clause? )
|
124
|
-
unclusterized_scope = unclusterized_scope.joins(relation).joins(Klastera::ClusterEntity.left_join_sources_of(cluster_entity_klass))
|
125
|
-
end
|
126
|
-
|
127
|
-
if scope_klass.respond_to?(:organization)
|
128
|
-
unclusterized_scope = unclusterized_scope.where(organization_id: organization)
|
129
|
-
end
|
130
|
-
|
131
|
-
unclusterized_scope.where("#{relation}_id" => cluster_scope!(cluster_entity_klass, user, organization, cluster_filter, force_cluster_clause))
|
132
|
-
end
|
133
|
-
|
134
|
-
#
|
135
|
-
# Returns an array with a clusterized scoped result and its grouped version
|
136
|
-
#
|
137
|
-
def group_by_cluster_scope!(scope_klass, user, organization, cluster_filter=[], scope_scopes=[])
|
138
|
-
cluster_ids = cluster_filter.is_a?(Array) ? cluster_filter : [cluster_filter]
|
139
|
-
kluster_scope = cluster_scope!(scope_klass, user, organization, cluster_ids.compact, organization.is_in_cluster_mode? )
|
140
|
-
|
141
|
-
scope_scopes.each do |tuple_scope|
|
142
|
-
scope_name, scope_arg = tuple_scope
|
143
|
-
kluster_scope = scope_arg.present? ? kluster_scope.send(scope_name,scope_arg) : kluster_scope.send(scope_name)
|
144
|
-
end
|
145
|
-
|
146
|
-
group_by_block = ->(o) {
|
147
|
-
if organization.is_in_cluster_mode?
|
148
|
-
o.cluster.present? ? o.cluster.name : UNCLUSTERED_POSITION
|
149
|
-
else
|
150
|
-
I18n.t("klastera.group_by_cluster_scope.#{scope_klass.model_name.plural}")
|
151
|
-
end
|
152
|
-
}
|
153
|
-
|
154
|
-
grouped_cluster_scope = kluster_scope.group_by(&group_by_block).sort_by{|k,v|k.to_s}
|
155
|
-
|
156
|
-
grouped_cluster_scope.dup.each do |group|
|
157
|
-
if group.first == UNCLUSTERED_POSITION
|
158
|
-
grouped_cluster_scope.delete(group)
|
159
|
-
group[0] = I18n.t("klastera.#{UNCLUSTERED_ENTITY}")
|
160
|
-
grouped_cluster_scope.append(group)
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
[ kluster_scope, grouped_cluster_scope ]
|
165
|
-
end
|
166
|
-
|
167
|
-
#
|
168
|
-
# A helper that returns a CLUSTER SCOPE to build queries that need explicit LEFT OUTER JOIN clause,
|
169
|
-
# instead of the default INNER JOIN provide by ActiveRecord's joins method
|
170
|
-
#
|
171
|
-
def cluster_scope_left_join!(scope_klass,organization)
|
172
|
-
cluster_entities_arel_table = Klastera::ClusterEntity.arel_table
|
173
|
-
cluster_arel_table = ::Cluster.arel_table
|
174
|
-
cluster_entities_cluster = cluster_entities_arel_table.join(cluster_arel_table, Arel::Nodes::OuterJoin).on(
|
175
|
-
cluster_entities_arel_table[:cluster_id].eq(cluster_arel_table[:id]),
|
176
|
-
).join_sources
|
177
|
-
|
178
|
-
scope_class(scope_klass).where(organization_id: organization).joins(Klastera::ClusterEntity.left_join_sources_of(scope_klass)).joins(cluster_entities_cluster)
|
179
|
-
end
|
180
|
-
end
|
181
|
-
|
182
|
-
##################################################################################################################################################
|
183
|
-
|
184
|
-
def cluster_user
|
185
|
-
current_user
|
186
|
-
end
|
187
|
-
|
188
|
-
def cluster_organization
|
189
|
-
current_organization
|
190
|
-
end
|
191
|
-
|
192
|
-
def set_cluster_filter
|
193
|
-
cluster_filter_params = params.require(:cluster_filter) rescue {}
|
194
|
-
@cluster_filter = ::ClusterFilter.new(
|
195
|
-
cluster_filter_params.present? ? cluster_filter_params.permit(
|
196
|
-
[ :cluster_id ].concat( ::ClusterFilter.attributes )
|
197
|
-
) : {}
|
198
|
-
)
|
199
|
-
end
|
200
|
-
|
201
|
-
def cluster_list(include_unclustered=true)
|
202
|
-
Klastera.cluster_list!(cluster_organization, cluster_user, include_unclustered)
|
203
|
-
end
|
204
|
-
|
205
|
-
def cluster_scope(scope_klass, cluster_filter=nil, force_cluster_clause=false)
|
206
|
-
Klastera.cluster_scope!(scope_klass, cluster_user, cluster_organization, cluster_filter, force_cluster_clause)
|
207
|
-
end
|
208
|
-
|
209
|
-
def cluster_scope_through_of(relation, cluster_entity_klass, scope_klass, cluster_filter=nil, force_cluster_clause=false)
|
210
|
-
Klastera.cluster_scope_through_of!(relation, cluster_entity_klass, scope_klass, cluster_user, cluster_organization, cluster_filter, force_cluster_clause)
|
211
|
-
end
|
212
|
-
|
213
|
-
def group_by_cluster_scope(scope_klass, cluster_filter=[], scope_scopes=[])
|
214
|
-
Klastera.group_by_cluster_scope!(scope_klass, cluster_user, cluster_organization, cluster_filter, scope_scopes)
|
215
|
-
end
|
216
|
-
|
217
|
-
def user_clusters_string_list(object_entity, separator, attribute=:name)
|
218
|
-
Klastera.user_clusters_string_list!(cluster_user, cluster_organization, object_entity.try(:cluster_entities), separator, attribute)
|
219
|
-
end
|
220
|
-
|
221
|
-
def cluster_scope_left_join(scope_klass)
|
222
|
-
Klastera.cluster_scope_left_join!(scope_klas,cluster_organization)
|
223
|
-
end
|
224
|
-
|
225
|
-
included do
|
226
|
-
Klastera::KLSTR_HELPERS.each do |action|
|
227
|
-
if respond_to?(:helper_method)
|
228
|
-
helper_method(action)
|
229
|
-
end
|
230
|
-
if respond_to?(:hide_action)
|
231
|
-
hide_action(helper)
|
232
|
-
hide_action("#{helper}=")
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
# desc "Explaining what the task does"
|
2
|
-
# task :klastera do
|
3
|
-
# # Task goes here
|
4
|
-
# end
|
5
|
-
|
6
|
-
|
7
|
-
namespace :klastera do
|
8
|
-
namespace :seed do
|
9
|
-
|
10
|
-
desc "Move cluster_id to cluster_entities"
|
11
|
-
task :cluster_entities, [:entity] => :environment do |task,args|
|
12
|
-
begin
|
13
|
-
klass = args.entity.constantize
|
14
|
-
ActiveRecord::Base.transaction do
|
15
|
-
klass.where.not(cluster_id: nil).each do |entity|
|
16
|
-
if entity.cluster.blank?
|
17
|
-
puts "Cluster ID #{entity.cluster_id} was not found!"
|
18
|
-
puts "skip..."
|
19
|
-
next
|
20
|
-
end
|
21
|
-
Klastera::ClusterEntity.create(entity: entity, cluster: entity.cluster)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
rescue NameError => ne
|
25
|
-
puts "NameError Exception: #{ne}"
|
26
|
-
rescue ActiveRecord::StatementInvalid => asi
|
27
|
-
puts "ActiveRecord::StatementInvalid Exception #{asi}"
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
module Klastera
|
4
|
-
class ClustersControllerTest < ActionController::TestCase
|
5
|
-
setup do
|
6
|
-
@cluster = klastera_clusters(:one)
|
7
|
-
@routes = Engine.routes
|
8
|
-
end
|
9
|
-
|
10
|
-
test "should get index" do
|
11
|
-
get :index
|
12
|
-
assert_response :success
|
13
|
-
assert_not_nil assigns(:clusters)
|
14
|
-
end
|
15
|
-
|
16
|
-
test "should get new" do
|
17
|
-
get :new
|
18
|
-
assert_response :success
|
19
|
-
end
|
20
|
-
|
21
|
-
test "should create cluster" do
|
22
|
-
assert_difference('Cluster.count') do
|
23
|
-
post :create, cluster: { color: @cluster.color, name: @cluster.name, nid: @cluster.nid }
|
24
|
-
end
|
25
|
-
|
26
|
-
assert_redirected_to cluster_path(assigns(:cluster))
|
27
|
-
end
|
28
|
-
|
29
|
-
test "should show cluster" do
|
30
|
-
get :show, id: @cluster
|
31
|
-
assert_response :success
|
32
|
-
end
|
33
|
-
|
34
|
-
test "should get edit" do
|
35
|
-
get :edit, id: @cluster
|
36
|
-
assert_response :success
|
37
|
-
end
|
38
|
-
|
39
|
-
test "should update cluster" do
|
40
|
-
patch :update, id: @cluster, cluster: { color: @cluster.color, name: @cluster.name, nid: @cluster.nid }
|
41
|
-
assert_redirected_to cluster_path(assigns(:cluster))
|
42
|
-
end
|
43
|
-
|
44
|
-
test "should destroy cluster" do
|
45
|
-
assert_difference('Cluster.count', -1) do
|
46
|
-
delete :destroy, id: @cluster
|
47
|
-
end
|
48
|
-
|
49
|
-
assert_redirected_to clusters_path
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
data/test/klastera_test.rb
DELETED
data/test/test_helper.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
# Configure Rails Environment
|
2
|
-
ENV["RAILS_ENV"] = "test"
|
3
|
-
|
4
|
-
require File.expand_path("../../test/dummy/config/environment.rb", __FILE__)
|
5
|
-
ActiveRecord::Migrator.migrations_paths = [File.expand_path("../../test/dummy/db/migrate", __FILE__)]
|
6
|
-
ActiveRecord::Migrator.migrations_paths << File.expand_path('../../db/migrate', __FILE__)
|
7
|
-
require "rails/test_help"
|
8
|
-
|
9
|
-
# Filter out Minitest backtrace while allowing backtrace from other libraries
|
10
|
-
# to be shown.
|
11
|
-
Minitest.backtrace_filter = Minitest::BacktraceFilter.new
|
12
|
-
|
13
|
-
# Load support files
|
14
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
15
|
-
|
16
|
-
# Load fixtures from the engine
|
17
|
-
if ActiveSupport::TestCase.respond_to?(:fixture_path=)
|
18
|
-
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
19
|
-
ActionDispatch::IntegrationTest.fixture_path = ActiveSupport::TestCase.fixture_path
|
20
|
-
ActiveSupport::TestCase.fixtures :all
|
21
|
-
end
|