lato_core 1.1

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.
Files changed (89) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +38 -0
  3. data/app/controllers/lato_core/api/v1/api_controller.rb +9 -0
  4. data/app/controllers/lato_core/application_controller.rb +6 -0
  5. data/app/controllers/lato_core/back/authentication_controller.rb +114 -0
  6. data/app/controllers/lato_core/back/back_controller.rb +28 -0
  7. data/app/controllers/lato_core/back/superusers_controller.rb +172 -0
  8. data/app/mailers/lato_core/application_mailer.rb +10 -0
  9. data/app/mailers/lato_core/superusers_mailer.rb +29 -0
  10. data/app/models/lato_core/superuser.rb +43 -0
  11. data/app/views/lato_core/back/authentication/login.html.erb +42 -0
  12. data/app/views/lato_core/back/authentication/password_edit.html.erb +50 -0
  13. data/app/views/lato_core/back/authentication/password_forget.html.erb +37 -0
  14. data/app/views/lato_core/back/back/home.html.erb +20 -0
  15. data/app/views/lato_core/back/superusers/edit.html.erb +12 -0
  16. data/app/views/lato_core/back/superusers/index.html.erb +25 -0
  17. data/app/views/lato_core/back/superusers/new.html.erb +12 -0
  18. data/app/views/lato_core/back/superusers/shared/_form.html.erb +71 -0
  19. data/app/views/lato_core/back/superusers/show.html.erb +1 -0
  20. data/app/views/lato_core/mailers/layouts/mailer.html.erb +9 -0
  21. data/app/views/lato_core/mailers/layouts/mailer.text.erb +1 -0
  22. data/app/views/lato_core/mailers/superusers/notify.html.erb +2 -0
  23. data/app/views/lato_core/mailers/superusers/recover_password.html.erb +4 -0
  24. data/config/config.yml +8 -0
  25. data/config/example.yml +66 -0
  26. data/config/initializers/init.rb +16 -0
  27. data/config/initializers/ram.rb +50 -0
  28. data/config/routes.rb +20 -0
  29. data/db/migrate/20160224181217_create_lato_core_superusers.rb +15 -0
  30. data/lib/lato_core.rb +11 -0
  31. data/lib/lato_core/engine.rb +26 -0
  32. data/lib/lato_core/interface.rb +29 -0
  33. data/lib/lato_core/interface/authentication.rb +34 -0
  34. data/lib/lato_core/interface/cache.rb +29 -0
  35. data/lib/lato_core/interface/communication.rb +104 -0
  36. data/lib/lato_core/interface/languages.rb +60 -0
  37. data/lib/lato_core/interface/navigation.rb +109 -0
  38. data/lib/lato_core/interface/session.rb +71 -0
  39. data/lib/lato_core/interface/superusers.rb +143 -0
  40. data/lib/tasks/lato_core_tasks.rake +11 -0
  41. data/test/controllers/lato_core/api/v1/api_controller_test.rb +9 -0
  42. data/test/controllers/lato_core/application_controller_test.rb +9 -0
  43. data/test/controllers/lato_core/back/authentication_controller_test.rb +13 -0
  44. data/test/controllers/lato_core/back/back_controller_test.rb +9 -0
  45. data/test/controllers/lato_core/back/session_controller_test.rb +13 -0
  46. data/test/controllers/lato_core/back/superusers_controller_test.rb +13 -0
  47. data/test/dummy/README.rdoc +28 -0
  48. data/test/dummy/Rakefile +6 -0
  49. data/test/dummy/app/assets/javascripts/application.js +13 -0
  50. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  51. data/test/dummy/app/controllers/application_controller.rb +5 -0
  52. data/test/dummy/app/helpers/application_helper.rb +2 -0
  53. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  54. data/test/dummy/bin/bundle +3 -0
  55. data/test/dummy/bin/rails +4 -0
  56. data/test/dummy/bin/rake +4 -0
  57. data/test/dummy/bin/setup +29 -0
  58. data/test/dummy/config.ru +4 -0
  59. data/test/dummy/config/application.rb +25 -0
  60. data/test/dummy/config/boot.rb +5 -0
  61. data/test/dummy/config/database.yml +25 -0
  62. data/test/dummy/config/environment.rb +5 -0
  63. data/test/dummy/config/environments/development.rb +41 -0
  64. data/test/dummy/config/environments/production.rb +79 -0
  65. data/test/dummy/config/environments/test.rb +42 -0
  66. data/test/dummy/config/initializers/assets.rb +11 -0
  67. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  68. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  69. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  70. data/test/dummy/config/initializers/inflections.rb +16 -0
  71. data/test/dummy/config/initializers/mime_types.rb +4 -0
  72. data/test/dummy/config/initializers/session_store.rb +3 -0
  73. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  74. data/test/dummy/config/locales/en.yml +23 -0
  75. data/test/dummy/config/routes.rb +4 -0
  76. data/test/dummy/config/secrets.yml +22 -0
  77. data/test/dummy/log/test.log +0 -0
  78. data/test/dummy/public/404.html +67 -0
  79. data/test/dummy/public/422.html +67 -0
  80. data/test/dummy/public/500.html +66 -0
  81. data/test/dummy/public/favicon.ico +0 -0
  82. data/test/fixtures/lato_core/superusers.yml +11 -0
  83. data/test/integration/navigation_test.rb +8 -0
  84. data/test/lato_core_test.rb +7 -0
  85. data/test/mailers/lato_core/lato_core_mailer_test.rb +9 -0
  86. data/test/mailers/previews/lato_core/lato_core_mailer_preview.rb +6 -0
  87. data/test/models/lato_core/superuser_test.rb +9 -0
  88. data/test/test_helper.rb +21 -0
  89. metadata +207 -0
@@ -0,0 +1,71 @@
1
+ module LatoCore
2
+ module Interface
3
+ # Insieme di funzioni che permettono alla applicazione di gestire
4
+ # le sessioni di utenze per l'accesso al backoffice.
5
+ module Session
6
+
7
+ # Funzione che crea una nuova sessione per permettere di accedere
8
+ # alle funzionalita' del backoffice.
9
+ # * *Args* :
10
+ # - +username+ -> username dell'utente
11
+ # - +password+ -> password dell'utente
12
+ # * *Returns* :
13
+ # - true se l'utente se la sessione e' stata creata correttamente
14
+ # - false se i dati ricevuti come parametro non sono corretti
15
+ def core_createSession(username, password)
16
+ user = LatoCore::Superuser.find_by(username: username)
17
+ if user && user.authenticate(password)
18
+ # genero un session_code
19
+ code = SecureRandom.urlsafe_base64
20
+ # memorizzo il session_code sul db
21
+ user.update_attribute('session_code', code)
22
+ # genero le sessioni
23
+ session[:user] = user.id
24
+ session[:session_code] = code
25
+ # ritorno true
26
+ return true
27
+ else
28
+ # ritorno false
29
+ return false
30
+ end
31
+ end
32
+
33
+ # Funzione che elimina una sessione di accesso al backoffice se presente
34
+ # * *Returns* :
35
+ # - true se la sessione e' stata eliminata
36
+ # - false se la sessione e' ancora attiva
37
+ def core_destroySession
38
+ if session[:user] && session[:session_code]
39
+ # determino l'utente della sessione
40
+ user = LatoCore::Superuser.find(session[:user])
41
+ # se l'utente esiste elimino il suo session_code dal db
42
+ user.update_attribute('session_code', nil) if user
43
+ # elimino le sessioni
44
+ session[:user] = nil
45
+ session[:session_code] = nil
46
+ # ritorno true
47
+ return true
48
+ else
49
+ # ritorno false
50
+ return false
51
+ end
52
+ end
53
+
54
+ # Funzione che controlla se l'utente ha una sessione valida.
55
+ # * *Returns* :
56
+ # - true se la sessione dell'utente risulta valida
57
+ # - false se la sessione non esiste o non e' valida
58
+ def core_controlSession
59
+ user = LatoCore::Superuser.find(session[:user]) if session[:user]
60
+
61
+ if user && session[:session_code] &&
62
+ user.session_code === session[:session_code] &&
63
+ !user.session_code.nil?
64
+ return true
65
+ else
66
+ return false
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,143 @@
1
+ module LatoCore
2
+ module Interface
3
+ # Insieme di funzioni che gestiscono varie impostazioni sulla gestione
4
+ # e visualizzazione dei superusers
5
+ module Superusers
6
+
7
+ # Funzione che richiede come parametri un utente, un titolo e un messaggio
8
+ # e invia tale contenuto come notifica email all'utente
9
+ def core_notifyUser(user, title, message)
10
+ # richiamo mailer corretto
11
+ LatoCore::SuperusersMailer.notify(user, title, message).deliver
12
+ end
13
+
14
+ # Funzione che ritorna una lista dei possibili permessi per gli utenti
15
+ # utilizzando la seguente struttura: [[1, 'Nome'], [2, 'Nome']].
16
+ # Il risultato della funzione e' compatibile con la componente input select
17
+ # di lato_view
18
+ def core_getUsersPermissions
19
+ # definisco permessi iniziali
20
+ initial_permissions = (1...11).to_a
21
+
22
+ unpermitted = core_getHideUsersPermissionsSettings
23
+ return initial_permissions if !unpermitted
24
+ permitted_permissions = initial_permissions - unpermitted
25
+
26
+ permissions = []
27
+ names = core_getUsersPermissionsNamesSettings
28
+ return permitted_permissions if !names
29
+
30
+ permitted_permissions.each do |permission|
31
+ names.each do |name|
32
+ permissions.push([permission, name.last]) if permission === name.first.to_i
33
+ end
34
+ end
35
+
36
+ return permissions
37
+ end
38
+
39
+ # Funzione che legge il file di cache e, se e' stato impostato per nascondere
40
+ # determinati utenti ad altri utenti, ritorna tali informazione attraverso
41
+ # un array con la seguente struttura: [[1,4], [1,3]]
42
+ def core_getHideUsersSettings
43
+ return CORE_SUPERUSERSHIDESETTINGS if defined? CORE_SUPERUSERSHIDESETTINGS
44
+ # accedo al config.yml
45
+ directory = core_getCacheDirectory
46
+ config = YAML.load(
47
+ File.read(File.expand_path("#{directory}/config.yml", __FILE__))
48
+ )
49
+ # controllo che il file di configurazione esista e abbia i dati necessari
50
+ return false if !config['hide_users'] || config['hide_users'].nil?
51
+ # estraggo lista impostazioni utenti da nascondere
52
+ settings = config['hide_users'].split(',')
53
+ # definisco output
54
+ output = []
55
+ # riempio file di output
56
+ settings.each do |setting|
57
+ setting.slice! ' '
58
+ if setting
59
+ values = setting.split('to')
60
+ raise 'Permission value not correct on hide_users config' unless (1..11).to_a.include? values.first.to_i
61
+ raise 'Permission value not correct on hide_users config' unless (1..11).to_a.include? values.last.to_i
62
+ output.push([values.first, values.last])
63
+ end
64
+ end
65
+ # ritorno l'output
66
+ return output
67
+ end
68
+
69
+ # Funzione che legge il file di configurazione e, se e' stato impostato di
70
+ # nascondere determinati permessi di utenze dall'interfaccia, ritorna i
71
+ # valori da nascondere in un array
72
+ def core_getHideUsersPermissionsSettings
73
+ return CORE_SUPERUSERSPERMISSIONSHIDESETTINGS if defined? CORE_SUPERUSERSPERMISSIONSHIDESETTINGS
74
+ # accedo al config.yml
75
+ directory = core_getCacheDirectory
76
+ config = YAML.load(
77
+ File.read(File.expand_path("#{directory}/config.yml", __FILE__))
78
+ )
79
+ # controllo che il file di configurazione esista e abbia i dati necessari
80
+ return false if !config['hide_users_permissions'] || config['hide_users_permissions'].nil?
81
+ # estraggo lista impostazioni utenti da nascondere
82
+ settings = config['hide_users_permissions'].to_s.split(',')
83
+ # definisco output
84
+ output = []
85
+ # riempio file di output
86
+ settings.each do |setting|
87
+ setting.slice! ' '
88
+ if setting
89
+ raise 'Permission value not correct on hide_users_permissions config' unless (1..11).to_a.include? setting.to_i
90
+ output.push(setting.to_i)
91
+ end
92
+ end
93
+ # ritorno l'output
94
+ return output
95
+ end
96
+
97
+ # Funzione che legge il file di configurazione e, se e' stato impostato di rinominare
98
+ # dei valori di permessi degli utenti, ritorna tali valori in un array con la seguente
99
+ # struttura: [[1,'nome'], [4,'nome']]
100
+ def core_getUsersPermissionsNamesSettings
101
+ return CORE_SUPERUSERSPERMISSIONSNAMESSETTINGS if defined? CORE_SUPERUSERSPERMISSIONSNAMESSETTINGS
102
+ # accedo al config.yml
103
+ directory = core_getCacheDirectory
104
+ config = YAML.load(
105
+ File.read(File.expand_path("#{directory}/config.yml", __FILE__))
106
+ )
107
+ # controllo che il file di configurazione esista e abbia i dati necessari
108
+ return false if !config['rename_users_permissions'] || config['rename_users_permissions'].nil?
109
+ # estraggo lista impostazioni utenti da nascondere
110
+ settings = config['rename_users_permissions'].split(',')
111
+ # definisco output
112
+ output = []
113
+ # riempio file di output
114
+ settings.each do |setting|
115
+ setting.slice! ' '
116
+ if setting
117
+ values = setting.split('-')
118
+ raise 'Permission value not correct on rename_users_permissions config' unless (1..11).to_a.include? values.first.to_i
119
+ output.push([values.first, values.last])
120
+ end
121
+ end
122
+ # ritorno l'output
123
+ return output
124
+ end
125
+
126
+ # Funzione che controlla se e' permesso il servizio di recupero password
127
+ # per gli utenti. Ritorna true se è permesso, false altrimenti.
128
+ def core_getRecoveryPasswordPermission
129
+ return CORE_RECOVERYPASSWORDPERMISSION if defined? CORE_RECOVERYPASSWORDPERMISSION
130
+ # accedo al config.yml
131
+ directory = core_getCacheDirectory
132
+ config = YAML.load(
133
+ File.read(File.expand_path("#{directory}/config.yml", __FILE__))
134
+ )
135
+ # controllo che il file di configurazione esista e abbia i dati necessari
136
+ return false if !config['recovery_password'] || config['recovery_password'].nil?
137
+ # ritorno valore letto
138
+ return config['recovery_password']
139
+ end
140
+
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,11 @@
1
+ include LatoCore::Interface
2
+
3
+ # Task che genera il file di configurazione di Lato nella cache
4
+ # dell'applicazione principale
5
+ desc 'Create config.yml file for Lato configuration'
6
+ task :lato_core_initialize do
7
+ # determino la directory di cache
8
+ directory = core_getCacheDirectory
9
+ FileUtils.cp "#{LatoCore::Engine.root}/config/example.yml", "#{Rails.root}/config/lato/config.yml"
10
+
11
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module LatoCore
4
+ class Api::V1::ApiControllerTest < ApplicationControllerTest
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module LatoCore
4
+ class ApplicationControllerTest < ActionController::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ module LatoCore
4
+ class Back::AuthenticationControllerTest < ActionController::TestCase
5
+ setup do
6
+ @routes = Engine.routes
7
+ end
8
+
9
+ # test "the truth" do
10
+ # assert true
11
+ # end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module LatoCore
4
+ class Back::BackControllerTest < ApplicationControllerTest
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ module LatoCore
4
+ class Back::SessionControllerTest < ActionController::TestCase
5
+ setup do
6
+ @routes = Engine.routes
7
+ end
8
+
9
+ # test "the truth" do
10
+ # assert true
11
+ # end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'test_helper'
2
+
3
+ module LatoCore
4
+ class Back::SuperusersControllerTest < ActionController::TestCase
5
+ setup do
6
+ @routes = Engine.routes
7
+ end
8
+
9
+ # test "the truth" do
10
+ # assert true
11
+ # end
12
+ end
13
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
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 .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end