forcast 0.0.110
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 +7 -0
- data/.gitignore +1 -0
- data/COPYRIGHTS +11 -0
- data/Gemfile +22 -0
- data/Gemfile.lock +166 -0
- data/PENDIENTES +39 -0
- data/README.md +35 -0
- data/Rakefile +7 -0
- data/VERSION +1 -0
- data/bin/console +14 -0
- data/bin/rake +28 -0
- data/bin/setup +8 -0
- data/forcast.gemspec +73 -0
- data/lib/forcast.rb +5 -0
- data/lib/forcast/controllers/all.rb +2 -0
- data/lib/forcast/controllers/application/all.rb +12 -0
- data/lib/forcast/controllers/application/crud.rb +91 -0
- data/lib/forcast/controllers/application/database.rb +34 -0
- data/lib/forcast/controllers/application/error.rb +18 -0
- data/lib/forcast/controllers/application/exception_handler.rb +25 -0
- data/lib/forcast/controllers/application/json.rb +83 -0
- data/lib/forcast/controllers/application/locale.rb +30 -0
- data/lib/forcast/controllers/application/log.rb +22 -0
- data/lib/forcast/controllers/application/login.rb +41 -0
- data/lib/forcast/controllers/application/meta.rb +61 -0
- data/lib/forcast/controllers/application/model.rb +17 -0
- data/lib/forcast/controllers/application/permitirtodo.rb +27 -0
- data/lib/forcast/controllers/application/utils.rb +28 -0
- data/lib/forcast/controllers/controller/all.rb +8 -0
- data/lib/forcast/controllers/controller/asociar.rb +121 -0
- data/lib/forcast/controllers/controller/busqueda.rb +151 -0
- data/lib/forcast/controllers/controller/definitor/definitor.rb +322 -0
- data/lib/forcast/controllers/controller/definitor/definitor_page.rb +40 -0
- data/lib/forcast/controllers/controller/definitor_all.rb +2 -0
- data/lib/forcast/controllers/controller/filtro.rb +48 -0
- data/lib/forcast/controllers/controller/login/controllers/base_controller.rb +135 -0
- data/lib/forcast/controllers/controller/login/controllers/login_controller.rb +38 -0
- data/lib/forcast/controllers/controller/login/login.rb +71 -0
- data/lib/forcast/controllers/controller/login_all.rb +1 -0
- data/lib/forcast/controllers/controller/paper_trail/paper_trail.rb +21 -0
- data/lib/forcast/controllers/controller/paper_trail_all.rb +1 -0
- data/lib/forcast/controllers/controller/relacion.rb +157 -0
- data/lib/forcast/controllers/controller/rule_engine/action_engine.rb +92 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/action_logs_controller.rb +12 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/actions_controller.rb +10 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/pollings_controller.rb +13 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/rule_logs_controller.rb +12 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/rules_controller.rb +19 -0
- data/lib/forcast/controllers/controller/rule_engine/controllers/webhooks_controller.rb +27 -0
- data/lib/forcast/controllers/controller/rule_engine/polling_engine.rb +76 -0
- data/lib/forcast/controllers/controller/rule_engine/rule_controller.rb +27 -0
- data/lib/forcast/controllers/controller/rule_engine/rule_engine.rb +88 -0
- data/lib/forcast/controllers/controller/rule_engine/webhook_engine.rb +38 -0
- data/lib/forcast/controllers/controller/rule_engine_all.rb +5 -0
- data/lib/forcast/jobs/all.rb +2 -0
- data/lib/forcast/jobs/jobs_assets.rb +25 -0
- data/lib/forcast/jobs/jobs_wrapper.rb +25 -0
- data/lib/forcast/jobs/rule_engine/jobs_actions.rb +73 -0
- data/lib/forcast/jobs/rule_engine/jobs_pollings.rb +77 -0
- data/lib/forcast/jobs/rule_engine/jobs_webhooks.rb +54 -0
- data/lib/forcast/migrations/0_migracion_general.rb +44 -0
- data/lib/forcast/migrations/paper_trail/versions.rb +61 -0
- data/lib/forcast/migrations/rule_engine/action_logs.rb +15 -0
- data/lib/forcast/migrations/rule_engine/actions.rb +15 -0
- data/lib/forcast/migrations/rule_engine/pollings.rb +26 -0
- data/lib/forcast/migrations/rule_engine/rule_logs.rb +22 -0
- data/lib/forcast/migrations/rule_engine/rules.rb +27 -0
- data/lib/forcast/migrations/rule_engine/webhooks.rb +25 -0
- data/lib/forcast/models/all.rb +8 -0
- data/lib/forcast/models/asociar.rb +74 -0
- data/lib/forcast/models/busqueda.rb +17 -0
- data/lib/forcast/models/login/authorization.rb +37 -0
- data/lib/forcast/models/login/json_web_token.rb +15 -0
- data/lib/forcast/models/login/login.rb +26 -0
- data/lib/forcast/models/login_all.rb +2 -0
- data/lib/forcast/models/meta.rb +19 -0
- data/lib/forcast/models/modelo.rb +125 -0
- data/lib/forcast/models/models/meta.rb +6 -0
- data/lib/forcast/models/paper_trail/paper_trail.rb +13 -0
- data/lib/forcast/models/paper_trail_all.rb +1 -0
- data/lib/forcast/models/permitirtodo.rb +57 -0
- data/lib/forcast/models/rule_engine/action_engine.rb +19 -0
- data/lib/forcast/models/rule_engine/models/action.rb +41 -0
- data/lib/forcast/models/rule_engine/models/action_log.rb +40 -0
- data/lib/forcast/models/rule_engine/models/polling.rb +43 -0
- data/lib/forcast/models/rule_engine/models/rule.rb +44 -0
- data/lib/forcast/models/rule_engine/models/rule_log.rb +39 -0
- data/lib/forcast/models/rule_engine/models/webhook.rb +43 -0
- data/lib/forcast/models/rule_engine/polling_engine.rb +113 -0
- data/lib/forcast/models/rule_engine/rule.rb +62 -0
- data/lib/forcast/models/rule_engine/rule_engine.rb +137 -0
- data/lib/forcast/models/rule_engine/rule_scope.rb +35 -0
- data/lib/forcast/models/rule_engine/webhook_engine.rb +55 -0
- data/lib/forcast/models/rule_engine_all.rb +6 -0
- data/lib/forcast/routes/concerns/asociar.rb +15 -0
- data/lib/forcast/routes/concerns/buscar.rb +6 -0
- data/lib/forcast/routes/concerns/definitor.rb +3 -0
- data/lib/forcast/routes/concerns/modelo.rb +6 -0
- data/lib/forcast/routes/database.rb +4 -0
- data/lib/forcast/routes/login.rb +4 -0
- data/lib/forcast/routes/paper_trail/paper_trail.rb +3 -0
- data/lib/forcast/routes/rule_engine/rule.rb +5 -0
- data/lib/forcast/tasks/.giosaveZr0hbs +21 -0
- data/lib/forcast/tasks/.keep +0 -0
- data/lib/forcast/tasks/all.rb +16 -0
- data/lib/forcast/tasks/diagramas.rake +32 -0
- data/lib/forcast/tasks/documentation/documentation.rb +100 -0
- data/lib/forcast/tasks/env.rake +10 -0
- data/lib/forcast/tasks/git.rake +22 -0
- data/lib/forcast/tasks/indy/indy.rb +28 -0
- data/lib/forcast/tasks/logs.rake +13 -0
- data/lib/forcast/tasks/process.rake +18 -0
- data/lib/forcast/tasks/schema.rake +17 -0
- data/lib/forcast/tasks/schema/recips/action.rb +18 -0
- data/lib/forcast/tasks/schema/recips/controller.rb +29 -0
- data/lib/forcast/tasks/schema/recips/definitor.rb +38 -0
- data/lib/forcast/tasks/schema/recips/model.rb +43 -0
- data/lib/forcast/tasks/schema/recips/project.rb +19 -0
- data/lib/forcast/tasks/schema/recips/route.rb +9 -0
- data/lib/forcast/tasks/schema/recips/tmp/controller.rb +0 -0
- data/lib/forcast/tasks/schema/recips/tmp/model.rb +0 -0
- data/lib/forcast/tasks/schema/recips/tmp/model/.keep +0 -0
- data/lib/forcast/tasks/schema/rule_engine/rule_engine.rb +98 -0
- data/lib/forcast/tasks/schema/schema.rb +346 -0
- data/lib/forcast/tasks/test.rake +129 -0
- data/lib/forcast/tasks/utils.rake +68 -0
- data/lib/forcast/tasks/yard.rake +18 -0
- data/lib/forcast/utils/all.rb +4 -0
- data/lib/forcast/utils/email.rb +49 -0
- data/lib/forcast/utils/email/forcast/utils/email/layout/default.html.erb +3 -0
- data/lib/forcast/utils/email/forcast/utils/email/layout/default.text.erb +5 -0
- data/lib/forcast/utils/firebase.rb +60 -0
- data/lib/forcast/utils/firebase_database.rb +117 -0
- data/lib/forcast/utils/measure.rb +44 -0
- data/lib/forcast/utils/qvo.rb +141 -0
- data/lib/forcast/utils/server.rb +296 -0
- data/lib/forcast/utils/telegram.rb +82 -0
- data/lib/forcast/utils/thing.rb +180 -0
- data/lib/forcast/version.rb +15 -0
- data/lib/lib/backup.rb +42 -0
- data/lib/lib/deploy.sh +40 -0
- data/lib/lib/forcast_servidor_rails.sh +11 -0
- data/lib/lib/pg_generator.sh +10 -0
- data/lib/lib/production.rb +66 -0
- data/lib/lib/production/production.rb +30 -0
- data/lib/lib/systemctl_maker.rb +88 -0
- data/lib/lib/update.rb +100 -0
- data/production.rb +31 -0
- metadata +301 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
module Forcast
|
|
3
|
+
module Application
|
|
4
|
+
module Crud
|
|
5
|
+
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
#before_action :require_login!
|
|
10
|
+
#before_action :require_admin!, only: [:create, :update, :destroy]
|
|
11
|
+
before_action :model, :limit_query
|
|
12
|
+
before_action :jsonparser,:params_to_global, except:[:index, :show]
|
|
13
|
+
before_action :set_model_id, only: [:show, :update, :destroy]
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
#model = Metodo que devuelve el objecto ActiveRecord por Nombre del controlador
|
|
17
|
+
#@model_id = Objecto instanciado por el param ID
|
|
18
|
+
|
|
19
|
+
def index
|
|
20
|
+
# buscar_por_nombre if params_present?('nombre')
|
|
21
|
+
# buscar_por_parametro_exacto if params_present?('buscar_por') && params_present?('dato')
|
|
22
|
+
# buscar_por_parametro_contiene if params_present?('buscar_por') && params_present?('contiene')
|
|
23
|
+
|
|
24
|
+
#Arreglar HARDCODEO
|
|
25
|
+
#@response = @model.last(@limit) if controller_name == 'alarmas'
|
|
26
|
+
meta = Meta::MetaRelation.new(@model)
|
|
27
|
+
@model = meta.egear_load(@model)
|
|
28
|
+
@response ||= @model.all.limit(@limit).order('id desc').select(*params_permitidos_enviar).map {|e| e.as_json.merge("meta" => meta.has_relation(e)) }
|
|
29
|
+
json_response(@response,t("ok"),200)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def show
|
|
33
|
+
meta = Meta::MetaRelation.new(@model)
|
|
34
|
+
@model = meta.egear_load(@model)
|
|
35
|
+
@response ||= @model_id.attributes.slice(*params_permitidos_enviar)
|
|
36
|
+
@response[:meta] = meta.has_relation(@model_id)
|
|
37
|
+
json_response(@response,t("ok"))
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def create
|
|
41
|
+
@create_model = @model.new
|
|
42
|
+
raise Error::General.new(t("bad_params")) if @model.parametros_estan_create?(@params)
|
|
43
|
+
#raise Error::General.new(t("bad_name")) if @model.nombre_existe?(@nombre)
|
|
44
|
+
#raise Error::General.new(t("#{c}.#{a}.bad_custom", param: 'nombre')) if @model.parametro_existe?('nombre',@nombre)
|
|
45
|
+
## Metodo General para comprobar parametros de creación
|
|
46
|
+
comprobar = @model.parametros_existen_create?(params)
|
|
47
|
+
raise Error::General.new(t("bad_custom", param: comprobar[1])) if comprobar[0]
|
|
48
|
+
comprobar = @model.parametros_a_validar_create(@datos)
|
|
49
|
+
raise Error::General.new(t("bad_params_not_allow_custom", param: t(comprobar[1].to_s))) if comprobar[0]
|
|
50
|
+
@response ||= @create_model
|
|
51
|
+
@create_model.create(params) ? json_response(@response,t("ok")) : (raise Error::General.new(@create_model.errores))
|
|
52
|
+
return @create_model
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def update
|
|
56
|
+
unless @variable == "all"
|
|
57
|
+
raise Error::General.new(t("bad_param")) unless params_permitidos_update.include?(@variable)
|
|
58
|
+
raise Error::General.new(t("bad_param_exists_custom", param: @variable)) if @model.parametro_existe?(@variable,@dato) && @model.parametros_a_comprobar_si_existen_update.include?(@variable)
|
|
59
|
+
comprobar = @model.validaciones_update(@variable,@dato)
|
|
60
|
+
raise Error::General.new(t("bad_param_not_allow_custom", param: t(comprobar[0].to_s))) if comprobar[1]
|
|
61
|
+
@dato = true if @dato == 'true'
|
|
62
|
+
@dato = false if @dato == 'false'
|
|
63
|
+
@model_id.update(Hash[@variable, @dato])
|
|
64
|
+
#@model_id.update_columns(Hash[@variable, @dato])
|
|
65
|
+
else
|
|
66
|
+
@datos_mod = @datos.without("variable")
|
|
67
|
+
@datos_mod.keys.each do |key|
|
|
68
|
+
@variable = key
|
|
69
|
+
@dato = @datos_mod[key]
|
|
70
|
+
raise Error::General.new(t("bad_param")) unless params_permitidos_update.include?(@variable)
|
|
71
|
+
raise Error::General.new(t("bad_param_exists_custom", param: @variable)) if @model.parametro_existe?(@variable,@dato) && @model.parametros_a_comprobar_si_existen_update.include?(@variable)
|
|
72
|
+
comprobar = @model.validaciones_update(@variable,@dato)
|
|
73
|
+
raise Error::General.new(t("bad_param_not_allow_custom", param: t(comprobar[0].to_s))) if comprobar[1]
|
|
74
|
+
@dato = true if @dato == 'true'
|
|
75
|
+
@dato = false if @dato == 'false'
|
|
76
|
+
end
|
|
77
|
+
@model_id.update(@datos_mod)
|
|
78
|
+
#@model_id.update_columns(@datos_mod)
|
|
79
|
+
end
|
|
80
|
+
@response ||= @model_id.attributes.slice(*params_permitidos_enviar)
|
|
81
|
+
json_response(@response,t("ok"))
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def destroy
|
|
86
|
+
@model_id.destroy ? json_response(t("ok")) : (raise Error::General.new(@model_id.errores))
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Forcast
|
|
2
|
+
module Application
|
|
3
|
+
module Database
|
|
4
|
+
def insert_multiples_object_db_sqlite3(model,array)
|
|
5
|
+
params = array[0].keys.collect { |x| "'"+x.to_s+"'" }.join(', ').to_s+",'created_at','updated_at'"
|
|
6
|
+
values = []
|
|
7
|
+
array.each do |arr|
|
|
8
|
+
next if arr.nil?
|
|
9
|
+
str = contructor_insert_multiples_object_db_sqlite3(arr.values)
|
|
10
|
+
values.push(str)
|
|
11
|
+
end
|
|
12
|
+
values = values.join(",")
|
|
13
|
+
begin
|
|
14
|
+
ActiveRecord::Base.connection.execute("INSERT INTO #{model} (#{params}) VALUES #{values}")
|
|
15
|
+
rescue
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
ActiveRecord::Base.connection.close
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def contructor_insert_multiples_object_db_sqlite3(array)
|
|
22
|
+
str = '('
|
|
23
|
+
array.each do |arr|
|
|
24
|
+
str += "'"+arr.to_s+"'"+','
|
|
25
|
+
end
|
|
26
|
+
str += "'"+Time.now.to_s+"'"+','
|
|
27
|
+
str += "'"+Time.now.to_s+"'"+','
|
|
28
|
+
str = str[0...-1]
|
|
29
|
+
str += ')'
|
|
30
|
+
return str
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module Forcast
|
|
2
|
+
module Application
|
|
3
|
+
module Error
|
|
4
|
+
class General < StandardError
|
|
5
|
+
|
|
6
|
+
attr_reader :status, :error, :message
|
|
7
|
+
|
|
8
|
+
def initialize(_message=nil)
|
|
9
|
+
@message = _message || 'Error General'
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def fetch_json
|
|
13
|
+
Helpers::Render.json(error, message, status)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# app/controllers/concerns/exception_handler.rb
|
|
2
|
+
require 'active_support'
|
|
3
|
+
module Forcast
|
|
4
|
+
module Application
|
|
5
|
+
module ExceptionHandler
|
|
6
|
+
# provides the more graceful `included` method
|
|
7
|
+
extend ActiveSupport::Concern
|
|
8
|
+
|
|
9
|
+
included do
|
|
10
|
+
rescue_from ActiveRecord::RecordNotFound do |e|
|
|
11
|
+
json_response({ message: e.message }, :not_found, 404)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
rescue_from ActiveRecord::RecordInvalid do |e|
|
|
15
|
+
json_response({ message: e.message }, :unprocessable_entity)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
rescue_from Error::General do |e|
|
|
19
|
+
jsonerror_response(e.message)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
module Forcast
|
|
2
|
+
module Application
|
|
3
|
+
module Json
|
|
4
|
+
|
|
5
|
+
def json_response(object = '', message = '', status = 200, meta = {})
|
|
6
|
+
|
|
7
|
+
object.is_a?(Hash) ? object = [object] : object
|
|
8
|
+
|
|
9
|
+
render json: {
|
|
10
|
+
object: object,
|
|
11
|
+
message: message,
|
|
12
|
+
status: status,
|
|
13
|
+
meta: meta
|
|
14
|
+
}, status: status
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def jsonerror_response(message = '')
|
|
18
|
+
|
|
19
|
+
render json: {
|
|
20
|
+
message: message,
|
|
21
|
+
status: 400
|
|
22
|
+
}, status: 400
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def json_requestall(object)
|
|
28
|
+
|
|
29
|
+
@datos = []
|
|
30
|
+
@datos = JSON.parse(object) if valid_json?(object)
|
|
31
|
+
@params = []
|
|
32
|
+
@params_data = []
|
|
33
|
+
@datos.each do |datos|
|
|
34
|
+
|
|
35
|
+
unless datos[0].nil? || datos [1].nil?
|
|
36
|
+
symbol = datos[0]
|
|
37
|
+
####
|
|
38
|
+
@params.push(symbol)
|
|
39
|
+
@params_data.push(datos [1])
|
|
40
|
+
next if symbol.include?('?')
|
|
41
|
+
instance_variable_set("@#{symbol}", datos[1])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#convierto los parametros en variable globales @
|
|
50
|
+
def params_to_global
|
|
51
|
+
@params = []
|
|
52
|
+
@params_data = []
|
|
53
|
+
params.each do |key, value|
|
|
54
|
+
@params.push(key)
|
|
55
|
+
@params_data.push(value)
|
|
56
|
+
next if key.include?('?')
|
|
57
|
+
instance_variable_set("@#{key}", value)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def jsonparser
|
|
64
|
+
|
|
65
|
+
data = request.body.read
|
|
66
|
+
json_requestall(data)
|
|
67
|
+
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def valid_json?(json)
|
|
72
|
+
JSON.parse(json)
|
|
73
|
+
return true
|
|
74
|
+
rescue JSON::ParserError => e
|
|
75
|
+
return false
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
module Forcast
|
|
3
|
+
module Application
|
|
4
|
+
module Locale
|
|
5
|
+
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
before_action :set_locale
|
|
10
|
+
end
|
|
11
|
+
def set_locale
|
|
12
|
+
I18n.locale = I18n.default_locale
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def t (s,custom='')
|
|
16
|
+
str = c + '.' + a + '.'+s
|
|
17
|
+
return I18n.t(str,custom)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def c
|
|
21
|
+
return controller_name
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def a
|
|
25
|
+
return action_name
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
module Forcast
|
|
3
|
+
module Application
|
|
4
|
+
module Log
|
|
5
|
+
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
included do
|
|
8
|
+
around_action :global_request_logging
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def global_request_logging
|
|
12
|
+
#logger.info "USERAGENT: #{request.headers['HTTP_USER_AGENT']}"
|
|
13
|
+
begin
|
|
14
|
+
yield
|
|
15
|
+
ensure
|
|
16
|
+
#logger.info "response_status: #{response.status}"
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
module Forcast
|
|
2
|
+
module Application
|
|
3
|
+
module Login
|
|
4
|
+
|
|
5
|
+
def require_login!
|
|
6
|
+
authenticate_token
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def require_admin!
|
|
10
|
+
raise Application::Error::General.new(t("required_admin")) unless current_user.class.name == ENV('login_admin')
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def current_user
|
|
14
|
+
@current_user
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def authenticate_token
|
|
20
|
+
headers_require
|
|
21
|
+
authenticate_with_http_token do |token, options|
|
|
22
|
+
models = ENV('login_models').split(":")
|
|
23
|
+
models.each do |model|
|
|
24
|
+
next if @current_user
|
|
25
|
+
@current_user = model.classify.constantize.where(auth_token: token).first
|
|
26
|
+
end
|
|
27
|
+
raise Application::Error::General.new(t("error_with_auth")) unless @current_user
|
|
28
|
+
raise Application::Error::General.new(t("token_expire")) if @current_user[:token_created_at] < ENV('login_expire_session').to_i.send(ENV('login_time_expire_session')).ago
|
|
29
|
+
@current_user.update_columns(Hash["last_connection", DateTime.now]) if @current_user
|
|
30
|
+
return @current_user
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def headers_require
|
|
35
|
+
auth = request.headers["Authorization"]
|
|
36
|
+
raise Application::Error::General.new(t("error_with_headers")) if auth.nil?
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
require 'active_support'
|
|
2
|
+
module Forcast
|
|
3
|
+
module Application
|
|
4
|
+
module Meta
|
|
5
|
+
|
|
6
|
+
extend ActiveSupport::Concern
|
|
7
|
+
|
|
8
|
+
included do
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
class MetaRelation
|
|
14
|
+
attr_accessor :class_name
|
|
15
|
+
attr_accessor :belongs_to
|
|
16
|
+
attr_accessor :has_many
|
|
17
|
+
|
|
18
|
+
def initialize(e)
|
|
19
|
+
self.class_name = e.to_s
|
|
20
|
+
self.belongs_to = e.reflect_on_all_associations(:belongs_to).map { |e| e.name.to_s }
|
|
21
|
+
self.has_many = e.reflect_on_all_associations(:has_many).map { |e| e.name.to_s }
|
|
22
|
+
#e.includes(self.belongs_to + self.has_many)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def has_relation(model)
|
|
26
|
+
rel = Hash.new
|
|
27
|
+
rel[:has_relation] = {}
|
|
28
|
+
rel[:has_relation][:belongs_to] = []
|
|
29
|
+
rel[:has_relation][:has_many] = []
|
|
30
|
+
self.belongs_to.each do |relation|
|
|
31
|
+
object = model.send(relation)
|
|
32
|
+
unless object.blank?
|
|
33
|
+
sender = [object].map {|e| e}
|
|
34
|
+
#object.is_a?(Array) ? sender = object.map {|e| e.as_json["id"]} : sender = [object].map {|e| e.as_json["id"]}
|
|
35
|
+
rel[:has_relation][:belongs_to].push({related_to: relation.to_s.pluralize, label: relation.to_s.pluralize.capitalize, ids: sender})
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
self.has_many.each do |relation|
|
|
39
|
+
object = model.send(relation)
|
|
40
|
+
##Return 'Array' Coleection Proxy
|
|
41
|
+
unless object.blank?
|
|
42
|
+
sender = object.map {|e| e}
|
|
43
|
+
#object.is_a?(Array) ? sender = object.map {|e| e.as_json["id"]} : sender = [object].map {|e| e.as_json["id"]}
|
|
44
|
+
rel[:has_relation][:has_many].push({related_to: relation.to_s.pluralize, label: relation.to_s.pluralize.capitalize, ids: sender})
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
return rel
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def egear_load(model)
|
|
51
|
+
model.includes(self.belongs_to + self.has_many)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# def meta_child(model)
|
|
55
|
+
# {hasChild: [{ relatedTo: "plants", childResource: "edificio"}]}
|
|
56
|
+
# end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Forcast
|
|
2
|
+
module Application
|
|
3
|
+
module Model
|
|
4
|
+
|
|
5
|
+
def model
|
|
6
|
+
@model ||= controller_name.classify.constantize
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def set_model_id
|
|
10
|
+
#instance_variable_set("@#{c.chomp('s')}", model.find(params[:id]))
|
|
11
|
+
return if params[:id_mongo] #This is for mongo db or another database
|
|
12
|
+
@model_id ||= model.find(params[:id])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Forcast
|
|
2
|
+
module Application
|
|
3
|
+
module Permitirtodo
|
|
4
|
+
|
|
5
|
+
def params_permitidos_enviar
|
|
6
|
+
return params_permitidos_enviar = controller_name.classify.constantize.column_names + assoc
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def params_permitidos_update
|
|
10
|
+
return params_permitidos_update = controller_name.classify.constantize.column_names + assoc
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def params_permitidos_buscar
|
|
14
|
+
return params_permitidos_buscar = controller_name.classify.constantize.column_names + assoc
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def assoc
|
|
18
|
+
nn = []
|
|
19
|
+
controller_name.classify.constantize.reflect_on_all_associations(:belongs_to).each do |x|
|
|
20
|
+
nn = nn.push(x.name.to_s + '_id')
|
|
21
|
+
end
|
|
22
|
+
return nn
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|