thecore 1.3.20
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/MIT-LICENSE +20 -0
- data/Rakefile +37 -0
- data/app/controllers/application_controller.rb +2 -0
- data/app/controllers/pages_controller.rb +37 -0
- data/app/jobs/application_job.rb +2 -0
- data/app/models/ability.rb +48 -0
- data/app/models/user.rb +158 -0
- data/app/uploaders/attachment_uploader.rb +27 -0
- data/app/uploaders/image_uploader.rb +27 -0
- data/config/initializers/rails_admin.rb +42 -0
- data/config/initializers/rails_application_config.rb +28 -0
- data/config/initializers/thecore_concern.rb +113 -0
- data/config/locales/en.activerecord.yml +6 -0
- data/config/locales/en.contact_mailer.custom.yml +5 -0
- data/config/locales/en.devise.custom.yml +15 -0
- data/config/locales/en.rails_admin.yml +34 -0
- data/config/locales/en.rollincode.yml +5 -0
- data/config/locales/en.simple_form.yml +31 -0
- data/config/locales/en.yml +31 -0
- data/config/locales/it.activerecord.yml +20 -0
- data/config/locales/it.contact_mailer.custom.yml +5 -0
- data/config/locales/it.devise.custom.yml +15 -0
- data/config/locales/it.rails_admin.yml +34 -0
- data/config/locales/it.rollincode.yml +5 -0
- data/config/locales/it.simple_form.yml +31 -0
- data/config/locales/it.yml +38 -0
- data/config/routes.rb +14 -0
- data/db/migrate/20131103142222_create_friendly_id_slugs.rb +15 -0
- data/db/migrate/20141010133701_devise_create_users.rb +54 -0
- data/db/migrate/20150806091039_add_authentication_token_to_users.rb +6 -0
- data/db/migrate/20150825101810_add_roles_mask_to_users.rb +5 -0
- data/db/migrate/20151201145832_add_external_to_user.rb +5 -0
- data/db/migrate/20160331101901_add_code_to_user.rb +6 -0
- data/db/migrate/20160331101902_add_admin_user.rb +162 -0
- data/db/migrate/20161029154134_remove_friendly_id_slugs.rb +5 -0
- data/db/seeds.rb +1 -0
- data/lib/abilities.rb +20 -0
- data/lib/active_record_extension.rb +145 -0
- data/lib/activerecord_paperclip_extension.rb +21 -0
- data/lib/application_configs.rb +26 -0
- data/lib/application_record_loader.rb +3 -0
- data/lib/backtrace_silencers.rb +7 -0
- data/lib/constants.rb +0 -0
- data/lib/date_format.rb +27 -0
- data/lib/devise_initializer.rb +275 -0
- data/lib/generators/thecore/add_git/USAGE +8 -0
- data/lib/generators/thecore/add_git/add_git_generator.rb +269 -0
- data/lib/generators/thecore/thecorize_app/USAGE +8 -0
- data/lib/generators/thecore/thecorize_app/thecorize_app_generator.rb +37 -0
- data/lib/generators/thecore/thecorize_models/USAGE +9 -0
- data/lib/generators/thecore/thecorize_models/thecorize_models_generator.rb +255 -0
- data/lib/generators/thecore/thecorize_plugin/USAGE +9 -0
- data/lib/generators/thecore/thecorize_plugin/thecorize_plugin_generator.rb +166 -0
- data/lib/inflections.rb +16 -0
- data/lib/integer_extensions.rb +26 -0
- data/lib/kaminari_config.rb +12 -0
- data/lib/mime_types.rb +5 -0
- data/lib/postgresql_drop_replacement.rb +11 -0
- data/lib/string_extensions.rb +14 -0
- data/lib/tasks/thecore_tasks.rake +4 -0
- data/lib/thecore/engine.rb +35 -0
- data/lib/thecore/version.rb +3 -0
- data/lib/thecore.rb +63 -0
- data/lib/thecore_actions.rb +2 -0
- data/lib/thecore_base_roles.rb +2 -0
- data/lib/thecore_rails_admin_bulk_delete_concern.rb +19 -0
- data/lib/thecore_rails_admin_export_concern.rb +19 -0
- data/lib/thecore_rails_admin_main_controller_concern.rb +11 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/config/application.rb +25 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +56 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +6 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/fixtures/users.yml +11 -0
- data/test/integration/navigation_test.rb +8 -0
- data/test/lib/generators/make_associations_complete_generator_test.rb +14 -0
- data/test/lib/generators/thecoreize_rails_plugin_generator_test.rb +14 -0
- data/test/lib/generators/thecorize_app_generator_test.rb +14 -0
- data/test/models/user_test.rb +7 -0
- data/test/test_helper.rb +20 -0
- data/test/thecore_test.rb +7 -0
- metadata +494 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
# Files in the config/locales directory are used for internationalization
|
2
|
+
# and are automatically loaded by Rails. If you want to use locales other
|
3
|
+
# than English, add the necessary files in this directory.
|
4
|
+
#
|
5
|
+
# To use the locales, use `I18n.t`:
|
6
|
+
#
|
7
|
+
# I18n.t 'hello'
|
8
|
+
#
|
9
|
+
# In views, this is aliased to just `t`:
|
10
|
+
#
|
11
|
+
# <%= t('hello') %>
|
12
|
+
#
|
13
|
+
# To use a different locale, set it with `I18n.locale`:
|
14
|
+
#
|
15
|
+
# I18n.locale = :es
|
16
|
+
#
|
17
|
+
# This would use the information in config/locales/es.yml.
|
18
|
+
#
|
19
|
+
# To learn more, please read the Rails Internationalization guide
|
20
|
+
# available at http://guides.rubyonrails.org/i18n.html.
|
21
|
+
|
22
|
+
en:
|
23
|
+
current_user: Current user
|
24
|
+
hello: "Hello world"
|
25
|
+
dashboard: "Dashboard"
|
26
|
+
contact: "Contact"
|
27
|
+
manage: "Manage"
|
28
|
+
sign_out: "Sign Out"
|
29
|
+
admin:
|
30
|
+
links:
|
31
|
+
label: Links
|
@@ -0,0 +1,20 @@
|
|
1
|
+
it:
|
2
|
+
activerecord:
|
3
|
+
models:
|
4
|
+
user:
|
5
|
+
one: Utente
|
6
|
+
other: Anagrafica Utenti
|
7
|
+
attributes:
|
8
|
+
user:
|
9
|
+
email: E-Mail
|
10
|
+
username: Nome Utente
|
11
|
+
code: Codice
|
12
|
+
roles: Ruoli
|
13
|
+
admin: Amministratore?
|
14
|
+
created_at: Data di Creazione
|
15
|
+
locked: Bloccato?
|
16
|
+
third_party: Ente Terzo?
|
17
|
+
password: Password
|
18
|
+
password_confirmation: Conferma Password
|
19
|
+
descriptions:
|
20
|
+
user: In questa sezione dell'applicazione potete cercare nella lista degli utenti in diversi modi usando i filtri o ordinare la lista secondo diversi campi.
|
@@ -0,0 +1,15 @@
|
|
1
|
+
it:
|
2
|
+
devise:
|
3
|
+
mailer:
|
4
|
+
password_changed_instructions:
|
5
|
+
greeting: Benvenuto %{recipient}!
|
6
|
+
instruction: Le abbiamo inviato questa email per notificarle il fatto che la sua password è stata cambiata.
|
7
|
+
instruction_2: Se non è stato lei a richiedere la modifica della password, la preghiamo di contattare il servizio clienti.
|
8
|
+
shared:
|
9
|
+
links:
|
10
|
+
sign_out: Esci
|
11
|
+
descriptions:
|
12
|
+
current_password_needed: (è necessario inserire la password corrente per autorizzare la modifica)
|
13
|
+
leave_blank: (lasciare vuota se non la si vuole modificare)
|
14
|
+
validations:
|
15
|
+
minimum_length: la lunghezza minima è di %{length} caratteri
|
@@ -0,0 +1,34 @@
|
|
1
|
+
it:
|
2
|
+
admin:
|
3
|
+
misc:
|
4
|
+
scopes: Filtri Veloci
|
5
|
+
scopes:
|
6
|
+
all: Tutti
|
7
|
+
order_by_name: Ordine Alfabetico
|
8
|
+
order_by_insert_date: Ordina per Data
|
9
|
+
starts_with_a: Inizia per A
|
10
|
+
starts_with_b: Inizia per B
|
11
|
+
starts_with_c: Inizia per C
|
12
|
+
starts_with_d: Inizia per D
|
13
|
+
starts_with_e: Inizia per E
|
14
|
+
starts_with_f: Inizia per F
|
15
|
+
starts_with_g: Inizia per G
|
16
|
+
starts_with_h: Inizia per H
|
17
|
+
starts_with_i: Inizia per I
|
18
|
+
starts_with_j: Inizia per J
|
19
|
+
starts_with_k: Inizia per K
|
20
|
+
starts_with_l: Inizia per L
|
21
|
+
starts_with_m: Inizia per M
|
22
|
+
starts_with_n: Inizia per N
|
23
|
+
starts_with_o: Inizia per O
|
24
|
+
starts_with_p: Inizia per P
|
25
|
+
starts_with_q: Inizia per Q
|
26
|
+
starts_with_r: Inizia per R
|
27
|
+
starts_with_s: Inizia per S
|
28
|
+
starts_with_t: Inizia per T
|
29
|
+
starts_with_u: Inizia per U
|
30
|
+
starts_with_v: Inizia per V
|
31
|
+
starts_with_w: Inizia per W
|
32
|
+
starts_with_x: Inizia per X
|
33
|
+
starts_with_y: Inizia per Y
|
34
|
+
starts_with_z: Inizia per Z
|
@@ -0,0 +1,31 @@
|
|
1
|
+
it:
|
2
|
+
simple_form:
|
3
|
+
yes: Si
|
4
|
+
no: No
|
5
|
+
required:
|
6
|
+
# text: 'required'
|
7
|
+
# mark: '*'
|
8
|
+
# You can uncomment the line below if you need to overwrite the whole required html.
|
9
|
+
# When using html, text and mark won't be used.
|
10
|
+
html: '*'
|
11
|
+
error_notification:
|
12
|
+
default_message: 'Per piacere, controlli gli errori riportati:'
|
13
|
+
# Examples
|
14
|
+
# labels:
|
15
|
+
# defaults:
|
16
|
+
# password: 'Password'
|
17
|
+
# user:
|
18
|
+
# new:
|
19
|
+
# email: 'E-mail to sign in.'
|
20
|
+
# edit:
|
21
|
+
# email: 'E-mail.'
|
22
|
+
# hints:
|
23
|
+
# defaults:
|
24
|
+
# username: 'User name to sign in.'
|
25
|
+
# password: 'No special characters, please.'
|
26
|
+
# include_blanks:
|
27
|
+
# defaults:
|
28
|
+
# age: 'Rather not say'
|
29
|
+
# prompts:
|
30
|
+
# defaults:
|
31
|
+
# age: 'Select your age'
|
@@ -0,0 +1,38 @@
|
|
1
|
+
it:
|
2
|
+
current_user: Utente corrente
|
3
|
+
hello: "Ciao Mondo"
|
4
|
+
dashboard: "Pannello di controllo"
|
5
|
+
contact: "Aiutaci a Migliorare"
|
6
|
+
manage: "Gestione"
|
7
|
+
sign_out: "Uscita"
|
8
|
+
advanced: Impostazioni
|
9
|
+
main_records: Anagrafiche
|
10
|
+
tiered_times:
|
11
|
+
dd:
|
12
|
+
zero: "0 Giorni"
|
13
|
+
one: "%{count} Giorno"
|
14
|
+
other: "%{count} Giorni"
|
15
|
+
hh:
|
16
|
+
zero: "0 Ore"
|
17
|
+
one: "%{count} Ora"
|
18
|
+
other: "%{count} Ore"
|
19
|
+
mm:
|
20
|
+
zero: "0 Minuti"
|
21
|
+
one: "%{count} Minuto"
|
22
|
+
other: "%{count} Minuti"
|
23
|
+
ss:
|
24
|
+
zero: "0 Secondi"
|
25
|
+
one: "%{count} Secondo"
|
26
|
+
other: "%{count} Secondi"
|
27
|
+
admin:
|
28
|
+
links:
|
29
|
+
label: Collegamenti
|
30
|
+
tools:
|
31
|
+
label: "Strumenti"
|
32
|
+
settings:
|
33
|
+
label: "Impostazioni"
|
34
|
+
actions:
|
35
|
+
charts:
|
36
|
+
menu: Analisi
|
37
|
+
title: Grafici
|
38
|
+
breadcrumb: Grafici
|
data/config/routes.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
# mount RailsAdminSelectize::Engine => '/rails-admin-selectize', as: 'rails_admin_selectize'
|
3
|
+
mount RailsAdmin::Engine => '/app', as: 'rails_admin'
|
4
|
+
|
5
|
+
get "home", to: "pages#home", as: "home"
|
6
|
+
get "inside", to: "pages#inside", as: "inside"
|
7
|
+
get "/contact", to: "pages#contact", as: "contact"
|
8
|
+
post "/emailconfirmation", to: "pages#email", as: "email_confirmation"
|
9
|
+
|
10
|
+
devise_for :users
|
11
|
+
devise_scope :user do
|
12
|
+
root to: "devise/sessions#new"
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateFriendlyIdSlugs < ActiveRecord::Migration[4.2]
|
2
|
+
def change
|
3
|
+
create_table :friendly_id_slugs do |t|
|
4
|
+
t.string :slug, :null => false
|
5
|
+
t.integer :sluggable_id, :null => false
|
6
|
+
t.string :sluggable_type, :limit => 50
|
7
|
+
t.string :scope
|
8
|
+
t.datetime :created_at
|
9
|
+
end
|
10
|
+
add_index :friendly_id_slugs, :sluggable_id
|
11
|
+
add_index :friendly_id_slugs, [:slug, :sluggable_type]
|
12
|
+
add_index :friendly_id_slugs, [:slug, :sluggable_type, :scope], :unique => true
|
13
|
+
add_index :friendly_id_slugs, :sluggable_type
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class DeviseCreateUsers < ActiveRecord::Migration[4.2]
|
2
|
+
def change
|
3
|
+
create_table(:users) do |t|
|
4
|
+
## Database authenticatable
|
5
|
+
t.string :username, :null => false, :default => ""
|
6
|
+
t.string :email, :null => false, :default => ""
|
7
|
+
t.string :encrypted_password, :null => false, :default => ""
|
8
|
+
|
9
|
+
## Admin
|
10
|
+
t.boolean :admin, :null => false, :default => false
|
11
|
+
|
12
|
+
## Lock
|
13
|
+
t.boolean :locked, :null => false, :default => false
|
14
|
+
|
15
|
+
## Friendly_id
|
16
|
+
t.string :slug
|
17
|
+
|
18
|
+
## Recoverable
|
19
|
+
t.string :reset_password_token
|
20
|
+
t.datetime :reset_password_sent_at
|
21
|
+
|
22
|
+
## Rememberable
|
23
|
+
t.datetime :remember_created_at
|
24
|
+
|
25
|
+
## Trackable
|
26
|
+
t.integer :sign_in_count, :default => 0, :null => false
|
27
|
+
t.datetime :current_sign_in_at
|
28
|
+
t.datetime :last_sign_in_at
|
29
|
+
t.string :current_sign_in_ip
|
30
|
+
t.string :last_sign_in_ip
|
31
|
+
|
32
|
+
## Confirmable
|
33
|
+
# t.string :confirmation_token
|
34
|
+
# t.datetime :confirmed_at
|
35
|
+
# t.datetime :confirmation_sent_at
|
36
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
37
|
+
|
38
|
+
## Lockable
|
39
|
+
# t.integer :failed_attempts, :default => 0, :null => false # Only if lock strategy is :failed_attempts
|
40
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
41
|
+
# t.datetime :locked_at
|
42
|
+
|
43
|
+
|
44
|
+
t.timestamps
|
45
|
+
end
|
46
|
+
|
47
|
+
add_index :users, :username, :unique => true
|
48
|
+
add_index :users, :email, :unique => true
|
49
|
+
add_index :users, :reset_password_token, :unique => true
|
50
|
+
#add_index :users, :confirmation_token, :unique => true
|
51
|
+
add_index :users, :slug, :unique => true
|
52
|
+
# add_index :users, :unlock_token, :unique => true
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,162 @@
|
|
1
|
+
class AddAdminUser < ActiveRecord::Migration[4.2]
|
2
|
+
# Model actual as of today
|
3
|
+
class User < ActiveRecord::Base
|
4
|
+
# Include default devise modules. Others available are:
|
5
|
+
# :confirmable, :lockable, :timeoutable and :omniauthable
|
6
|
+
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable #, :confirmable
|
7
|
+
|
8
|
+
before_create :generate_authentication_token
|
9
|
+
|
10
|
+
paginates_per 50
|
11
|
+
|
12
|
+
# Validations
|
13
|
+
# :username
|
14
|
+
validates :username, uniqueness: { case_sensitive: false }
|
15
|
+
validates_format_of :username, with: /\A[a-zA-Z0-9]*\z/, on: :create, message: "can only contain letters and digits"
|
16
|
+
validates :username, length: { in: 4..15 }
|
17
|
+
# :email
|
18
|
+
validates :email, uniqueness: { case_sensitive: false }
|
19
|
+
validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
|
20
|
+
|
21
|
+
validates :username, presence: true
|
22
|
+
validates :email, presence: true
|
23
|
+
|
24
|
+
validates :password, presence: true, on: :create
|
25
|
+
validates :password_confirmation, presence: true, on: :create
|
26
|
+
|
27
|
+
def self.paged(page_number)
|
28
|
+
order(admin: :desc, username: :asc).page page_number
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.search_and_order(search, page_number)
|
32
|
+
if search
|
33
|
+
where("username LIKE ?", "%#{search.downcase}%").order(
|
34
|
+
admin: :desc, username: :asc
|
35
|
+
).page page_number
|
36
|
+
else
|
37
|
+
order(admin: :desc, username: :asc).page page_number
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.last_signups(count)
|
42
|
+
order(created_at: :desc).limit(count).select("id","username","slug","created_at")
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.last_signins(count)
|
46
|
+
order(last_sign_in_at:
|
47
|
+
:desc).limit(count).select("id","username","slug","last_sign_in_at")
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.users_count
|
51
|
+
where("admin = ? AND locked = ?",false,false).count
|
52
|
+
end
|
53
|
+
|
54
|
+
serialize :roles, Array
|
55
|
+
def roles_enum
|
56
|
+
# Do not EDIT below this line
|
57
|
+
ROLES.each_with_index.map {|a,i| [I18n.t("roles.#{a.to_sym}"), (i+1).to_s]}
|
58
|
+
end
|
59
|
+
def has_role? role
|
60
|
+
# example called from cancan's app/models/ability.rb
|
61
|
+
# if user.has_role? :admin
|
62
|
+
|
63
|
+
# for roles array stored in db... take each value, see if it matches the second column in the roles_enum array, if so, retu the 1st col of the enum as a uprcase,space_to_underscore,symbol .
|
64
|
+
chosen_roles = self.roles.map { |r| r.blank? ? nil : ROLES[r.to_i - 1] }
|
65
|
+
chosen_roles.compact.include? role
|
66
|
+
end
|
67
|
+
|
68
|
+
def title
|
69
|
+
username
|
70
|
+
end
|
71
|
+
|
72
|
+
rails_admin do
|
73
|
+
navigation_label I18n.t("admin.settings.label")
|
74
|
+
weight 10
|
75
|
+
# Field present Everywhere
|
76
|
+
field :email do
|
77
|
+
required true
|
78
|
+
end
|
79
|
+
field :username do
|
80
|
+
required true
|
81
|
+
end
|
82
|
+
field :code
|
83
|
+
field :roles, :enum do
|
84
|
+
pretty_value do # used in list view columns and show views, defaults to formatted_value for non-association fields
|
85
|
+
value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", "
|
86
|
+
end
|
87
|
+
export_value do
|
88
|
+
value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", " # used in exports, where no html/data is allowed
|
89
|
+
end
|
90
|
+
queryable false
|
91
|
+
end
|
92
|
+
field :admin do
|
93
|
+
visible do
|
94
|
+
bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
|
95
|
+
end
|
96
|
+
end
|
97
|
+
field :locked do
|
98
|
+
visible do
|
99
|
+
bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
|
100
|
+
end
|
101
|
+
end
|
102
|
+
field :third_party do
|
103
|
+
visible do
|
104
|
+
bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
# Fields only in lists and forms
|
109
|
+
list do
|
110
|
+
field :created_at
|
111
|
+
configure :email do
|
112
|
+
visible false
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
create do
|
117
|
+
field :password do
|
118
|
+
required true
|
119
|
+
end
|
120
|
+
field :password_confirmation do
|
121
|
+
required true
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
edit do
|
126
|
+
field :password do
|
127
|
+
required false
|
128
|
+
end
|
129
|
+
field :password_confirmation do
|
130
|
+
required false
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
#has_paper_trail
|
136
|
+
|
137
|
+
private
|
138
|
+
|
139
|
+
def generate_authentication_token
|
140
|
+
loop do
|
141
|
+
self.authentication_token = SecureRandom.base64(64)
|
142
|
+
break unless User.find_by(authentication_token: authentication_token)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
def up
|
149
|
+
puts "Generating admin user"
|
150
|
+
User.reset_column_information
|
151
|
+
u=User.find_or_initialize_by(username: "admin")
|
152
|
+
puts "Utente Admin: #{u.inspect}"
|
153
|
+
u.email = "admin@example.com"
|
154
|
+
psswd = SecureRandom.hex(5)
|
155
|
+
puts "\tThecore admin password is:\n\n\t\t#{psswd}\n\n\tplease save it somewhere, securely."
|
156
|
+
u.password = psswd
|
157
|
+
u.password_confirmation = psswd
|
158
|
+
u.admin = true
|
159
|
+
# u.skip_confirmation!
|
160
|
+
u.save!
|
161
|
+
end
|
162
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
data/lib/abilities.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module TheCoreAbilities
|
2
|
+
def core_abilities user
|
3
|
+
# So the static link navigation can be set runtime (yes it's an hack)
|
4
|
+
RailsAdmin.config do |config|
|
5
|
+
config.navigation_static_label = I18n.t("admin.links.label")
|
6
|
+
end
|
7
|
+
# Normal core abilities file
|
8
|
+
if user
|
9
|
+
can :access, :rails_admin # grant access to rails_admin
|
10
|
+
can :dashboard, :all # allow access to dashboard
|
11
|
+
if user.admin?
|
12
|
+
can :manage, :all # only allow admin users to access Rails Admin
|
13
|
+
cannot :destroy, User do |u|
|
14
|
+
# prevents killing himself
|
15
|
+
u.id == user.id
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,145 @@
|
|
1
|
+
module ActiveRecordExtension
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
# add your instance methods here
|
5
|
+
# def foo
|
6
|
+
# "foo"
|
7
|
+
# end
|
8
|
+
# def taris_deep_clone_method
|
9
|
+
# Rails.logger.debug "FEBWUFBEUWFJEWNKJNFJDKSBFKJREHJBFKJE: Deep Cloning"
|
10
|
+
# copy = self.amoeba_dup
|
11
|
+
# copy.save
|
12
|
+
# end
|
13
|
+
|
14
|
+
# add your static(class) methods here
|
15
|
+
module ClassMethods
|
16
|
+
#E.g: Order.top_ten
|
17
|
+
def top_ten
|
18
|
+
limit(10)
|
19
|
+
end
|
20
|
+
|
21
|
+
def name_or_title_or_code_or_barcode_starts_with letter
|
22
|
+
# Se ha name o code o barcode, uso uno di questi:
|
23
|
+
column = if self.column_names.include? "name"
|
24
|
+
:name
|
25
|
+
elsif self.column_names.include? "title"
|
26
|
+
:title
|
27
|
+
elsif self.column_names.include? "code"
|
28
|
+
:code
|
29
|
+
elsif self.column_names.include? "barcode"
|
30
|
+
:barcode
|
31
|
+
end
|
32
|
+
# Ecco la ricerca dedicata a Postgres, la facciamo multiplatform? Fatto
|
33
|
+
query = "#{letter}%"
|
34
|
+
match = arel_table[column].matches(query)
|
35
|
+
where(match)
|
36
|
+
end
|
37
|
+
|
38
|
+
def starts_with_a
|
39
|
+
name_or_title_or_code_or_barcode_starts_with :a
|
40
|
+
end
|
41
|
+
|
42
|
+
def starts_with_b
|
43
|
+
name_or_title_or_code_or_barcode_starts_with :b
|
44
|
+
end
|
45
|
+
|
46
|
+
def starts_with_c
|
47
|
+
name_or_title_or_code_or_barcode_starts_with :c
|
48
|
+
end
|
49
|
+
|
50
|
+
def starts_with_d
|
51
|
+
name_or_title_or_code_or_barcode_starts_with :d
|
52
|
+
end
|
53
|
+
|
54
|
+
def starts_with_e
|
55
|
+
name_or_title_or_code_or_barcode_starts_with :e
|
56
|
+
end
|
57
|
+
|
58
|
+
def starts_with_f
|
59
|
+
name_or_title_or_code_or_barcode_starts_with :f
|
60
|
+
end
|
61
|
+
|
62
|
+
def starts_with_g
|
63
|
+
name_or_title_or_code_or_barcode_starts_with :g
|
64
|
+
end
|
65
|
+
|
66
|
+
def starts_with_h
|
67
|
+
name_or_title_or_code_or_barcode_starts_with :h
|
68
|
+
end
|
69
|
+
|
70
|
+
def starts_with_i
|
71
|
+
name_or_title_or_code_or_barcode_starts_with :i
|
72
|
+
end
|
73
|
+
|
74
|
+
def starts_with_j
|
75
|
+
name_or_title_or_code_or_barcode_starts_with :j
|
76
|
+
end
|
77
|
+
|
78
|
+
def starts_with_k
|
79
|
+
name_or_title_or_code_or_barcode_starts_with :k
|
80
|
+
end
|
81
|
+
|
82
|
+
def starts_with_l
|
83
|
+
name_or_title_or_code_or_barcode_starts_with :l
|
84
|
+
end
|
85
|
+
|
86
|
+
def starts_with_m
|
87
|
+
name_or_title_or_code_or_barcode_starts_with :m
|
88
|
+
end
|
89
|
+
|
90
|
+
def starts_with_n
|
91
|
+
name_or_title_or_code_or_barcode_starts_with :n
|
92
|
+
end
|
93
|
+
|
94
|
+
def starts_with_o
|
95
|
+
name_or_title_or_code_or_barcode_starts_with :o
|
96
|
+
end
|
97
|
+
|
98
|
+
def starts_with_p
|
99
|
+
name_or_title_or_code_or_barcode_starts_with :p
|
100
|
+
end
|
101
|
+
|
102
|
+
def starts_with_q
|
103
|
+
name_or_title_or_code_or_barcode_starts_with :q
|
104
|
+
end
|
105
|
+
|
106
|
+
def starts_with_r
|
107
|
+
name_or_title_or_code_or_barcode_starts_with :r
|
108
|
+
end
|
109
|
+
|
110
|
+
def starts_with_s
|
111
|
+
name_or_title_or_code_or_barcode_starts_with :s
|
112
|
+
end
|
113
|
+
|
114
|
+
def starts_with_t
|
115
|
+
name_or_title_or_code_or_barcode_starts_with :t
|
116
|
+
end
|
117
|
+
|
118
|
+
def starts_with_u
|
119
|
+
name_or_title_or_code_or_barcode_starts_with :u
|
120
|
+
end
|
121
|
+
|
122
|
+
def starts_with_v
|
123
|
+
name_or_title_or_code_or_barcode_starts_with :v
|
124
|
+
end
|
125
|
+
|
126
|
+
def starts_with_w
|
127
|
+
name_or_title_or_code_or_barcode_starts_with :w
|
128
|
+
end
|
129
|
+
|
130
|
+
def starts_with_x
|
131
|
+
name_or_title_or_code_or_barcode_starts_with :x
|
132
|
+
end
|
133
|
+
|
134
|
+
def starts_with_y
|
135
|
+
name_or_title_or_code_or_barcode_starts_with :y
|
136
|
+
end
|
137
|
+
|
138
|
+
def starts_with_z
|
139
|
+
name_or_title_or_code_or_barcode_starts_with :z
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# include the extension
|
145
|
+
ActiveRecord::Base.send(:include, ActiveRecordExtension)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module ActiveRecordPaperclipConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
has_attached_file :asset, styles: {
|
8
|
+
thumb: "100x100#",
|
9
|
+
small: "150x150>",
|
10
|
+
medium: "200x200>",
|
11
|
+
large: "600x600>"
|
12
|
+
}
|
13
|
+
validates_attachment_content_type :asset, content_type: /\Aimage\/.*\Z/
|
14
|
+
# add a delete_<asset_name> method:
|
15
|
+
attr_accessor :delete_asset
|
16
|
+
before_validation { self.asset.clear if self.delete_asset == '1' }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Do not auto include the asset, not all the models have it
|
21
|
+
# ActiveRecord::Base.send(:include, ActiveRecordPaperclipConcern)
|