thecore 1.3.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +37 -0
  4. data/app/controllers/application_controller.rb +2 -0
  5. data/app/controllers/pages_controller.rb +37 -0
  6. data/app/jobs/application_job.rb +2 -0
  7. data/app/models/ability.rb +48 -0
  8. data/app/models/user.rb +158 -0
  9. data/app/uploaders/attachment_uploader.rb +27 -0
  10. data/app/uploaders/image_uploader.rb +27 -0
  11. data/config/initializers/rails_admin.rb +42 -0
  12. data/config/initializers/rails_application_config.rb +28 -0
  13. data/config/initializers/thecore_concern.rb +113 -0
  14. data/config/locales/en.activerecord.yml +6 -0
  15. data/config/locales/en.contact_mailer.custom.yml +5 -0
  16. data/config/locales/en.devise.custom.yml +15 -0
  17. data/config/locales/en.rails_admin.yml +34 -0
  18. data/config/locales/en.rollincode.yml +5 -0
  19. data/config/locales/en.simple_form.yml +31 -0
  20. data/config/locales/en.yml +31 -0
  21. data/config/locales/it.activerecord.yml +20 -0
  22. data/config/locales/it.contact_mailer.custom.yml +5 -0
  23. data/config/locales/it.devise.custom.yml +15 -0
  24. data/config/locales/it.rails_admin.yml +34 -0
  25. data/config/locales/it.rollincode.yml +5 -0
  26. data/config/locales/it.simple_form.yml +31 -0
  27. data/config/locales/it.yml +38 -0
  28. data/config/routes.rb +14 -0
  29. data/db/migrate/20131103142222_create_friendly_id_slugs.rb +15 -0
  30. data/db/migrate/20141010133701_devise_create_users.rb +54 -0
  31. data/db/migrate/20150806091039_add_authentication_token_to_users.rb +6 -0
  32. data/db/migrate/20150825101810_add_roles_mask_to_users.rb +5 -0
  33. data/db/migrate/20151201145832_add_external_to_user.rb +5 -0
  34. data/db/migrate/20160331101901_add_code_to_user.rb +6 -0
  35. data/db/migrate/20160331101902_add_admin_user.rb +162 -0
  36. data/db/migrate/20161029154134_remove_friendly_id_slugs.rb +5 -0
  37. data/db/seeds.rb +1 -0
  38. data/lib/abilities.rb +20 -0
  39. data/lib/active_record_extension.rb +145 -0
  40. data/lib/activerecord_paperclip_extension.rb +21 -0
  41. data/lib/application_configs.rb +26 -0
  42. data/lib/application_record_loader.rb +3 -0
  43. data/lib/backtrace_silencers.rb +7 -0
  44. data/lib/constants.rb +0 -0
  45. data/lib/date_format.rb +27 -0
  46. data/lib/devise_initializer.rb +275 -0
  47. data/lib/generators/thecore/add_git/USAGE +8 -0
  48. data/lib/generators/thecore/add_git/add_git_generator.rb +269 -0
  49. data/lib/generators/thecore/thecorize_app/USAGE +8 -0
  50. data/lib/generators/thecore/thecorize_app/thecorize_app_generator.rb +37 -0
  51. data/lib/generators/thecore/thecorize_models/USAGE +9 -0
  52. data/lib/generators/thecore/thecorize_models/thecorize_models_generator.rb +255 -0
  53. data/lib/generators/thecore/thecorize_plugin/USAGE +9 -0
  54. data/lib/generators/thecore/thecorize_plugin/thecorize_plugin_generator.rb +166 -0
  55. data/lib/inflections.rb +16 -0
  56. data/lib/integer_extensions.rb +26 -0
  57. data/lib/kaminari_config.rb +12 -0
  58. data/lib/mime_types.rb +5 -0
  59. data/lib/postgresql_drop_replacement.rb +11 -0
  60. data/lib/string_extensions.rb +14 -0
  61. data/lib/tasks/thecore_tasks.rake +4 -0
  62. data/lib/thecore/engine.rb +35 -0
  63. data/lib/thecore/version.rb +3 -0
  64. data/lib/thecore.rb +63 -0
  65. data/lib/thecore_actions.rb +2 -0
  66. data/lib/thecore_base_roles.rb +2 -0
  67. data/lib/thecore_rails_admin_bulk_delete_concern.rb +19 -0
  68. data/lib/thecore_rails_admin_export_concern.rb +19 -0
  69. data/lib/thecore_rails_admin_main_controller_concern.rb +11 -0
  70. data/test/dummy/README.rdoc +28 -0
  71. data/test/dummy/Rakefile +6 -0
  72. data/test/dummy/app/assets/javascripts/application.js +13 -0
  73. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  74. data/test/dummy/app/controllers/application_controller.rb +5 -0
  75. data/test/dummy/app/helpers/application_helper.rb +2 -0
  76. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  77. data/test/dummy/bin/bundle +3 -0
  78. data/test/dummy/bin/rails +4 -0
  79. data/test/dummy/bin/rake +4 -0
  80. data/test/dummy/bin/setup +29 -0
  81. data/test/dummy/config/application.rb +25 -0
  82. data/test/dummy/config/boot.rb +5 -0
  83. data/test/dummy/config/database.yml +25 -0
  84. data/test/dummy/config/environment.rb +5 -0
  85. data/test/dummy/config/environments/development.rb +41 -0
  86. data/test/dummy/config/environments/production.rb +79 -0
  87. data/test/dummy/config/environments/test.rb +42 -0
  88. data/test/dummy/config/initializers/assets.rb +11 -0
  89. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  90. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  91. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  92. data/test/dummy/config/initializers/inflections.rb +16 -0
  93. data/test/dummy/config/initializers/mime_types.rb +4 -0
  94. data/test/dummy/config/initializers/session_store.rb +3 -0
  95. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  96. data/test/dummy/config/locales/en.yml +23 -0
  97. data/test/dummy/config/routes.rb +56 -0
  98. data/test/dummy/config/secrets.yml +22 -0
  99. data/test/dummy/config.ru +4 -0
  100. data/test/dummy/db/development.sqlite3 +0 -0
  101. data/test/dummy/log/development.log +6 -0
  102. data/test/dummy/public/404.html +67 -0
  103. data/test/dummy/public/422.html +67 -0
  104. data/test/dummy/public/500.html +66 -0
  105. data/test/dummy/public/favicon.ico +0 -0
  106. data/test/fixtures/users.yml +11 -0
  107. data/test/integration/navigation_test.rb +8 -0
  108. data/test/lib/generators/make_associations_complete_generator_test.rb +14 -0
  109. data/test/lib/generators/thecoreize_rails_plugin_generator_test.rb +14 -0
  110. data/test/lib/generators/thecorize_app_generator_test.rb +14 -0
  111. data/test/models/user_test.rb +7 -0
  112. data/test/test_helper.rb +20 -0
  113. data/test/thecore_test.rb +7 -0
  114. metadata +494 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2cd52dac896d7a464ed6311a27c66f298dac2fac
4
+ data.tar.gz: 749149993625e1370d43c359469b4dfbfad1ab68
5
+ SHA512:
6
+ metadata.gz: 8ba5ab09e8614d9f6d075e60bdf8d72ecadadb06e70b44819a8a515967ca1eb5131abe38b518645d1e13193e9b7488255425715848cd2cdea155f7782f3ca5d0
7
+ data.tar.gz: d678cca087627de83e0ac9792b49e69995be31fce2be23663ef109ac51f4184a9fa4b55afbc15b7f66be6d22bfb90588e5c244cbd6697ec3ba6762982d4f80de
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Gabriele Tassoni
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/Rakefile ADDED
@@ -0,0 +1,37 @@
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 = 'Thecore'
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
@@ -0,0 +1,2 @@
1
+ class ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,37 @@
1
+ class PagesController < ApplicationController
2
+ before_action :authenticate_user!, only: [
3
+ :inside, :contact
4
+ ]
5
+ #authorize_resource :class => false
6
+
7
+ def home
8
+ end
9
+
10
+ def inside
11
+ end
12
+
13
+
14
+ def email
15
+ @name = params[:name]
16
+ @email = params[:email]
17
+ @message = params[:message]
18
+
19
+ if @name.blank?
20
+ flash[:alert] = "Please enter your name before sending your message. Thank you."
21
+ render :contact
22
+ elsif @email.blank? || @email.scan(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i).size < 1
23
+ flash[:alert] = "You must provide a valid email address before sending your message. Thank you."
24
+ render :contact
25
+ elsif @message.blank? || @message.length < 10
26
+ flash[:alert] = "Your message is empty. Requires at least 10 characters. Nothing to send."
27
+ render :contact
28
+ elsif @message.scan(/<a href=/).size > 0 || @message.scan(/\[url=/).size > 0 || @message.scan(/\[link=/).size > 0 || @message.scan(/http:\/\//).size > 0
29
+ flash[:alert] = "You can't send links. Thank you for your understanding."
30
+ render :contact
31
+ else
32
+ ContactMailer.contact_message(@name,@email,@message).deliver_now
33
+ redirect_to root_path, notice: "Your message was sent. Thank you."
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,2 @@
1
+ class ApplicationJob < ActiveJob::Base
2
+ end
@@ -0,0 +1,48 @@
1
+ class Ability
2
+ include CanCan::Ability
3
+
4
+ include TheCoreAbilities
5
+
6
+ def initialize(user)
7
+ # Define abilities for the passed in user here. For example:
8
+ #
9
+ # user ||= User.new # guest user (not logged in)
10
+ # if user.admin?
11
+ # can :manage, :all
12
+ # else
13
+ # can :read, :all
14
+ # end
15
+ #
16
+ # The first argument to `can` is the action you are giving the user
17
+ # permission to do.
18
+ # If you pass :manage it will apply to every action. Other common actions
19
+ # here are :read, :create, :update and :destroy.
20
+ #
21
+ # The second argument is the resource the user can perform the action on.
22
+ # If you pass :all it will apply to every resource. Otherwise pass a Ruby
23
+ # class of the resource.
24
+ #
25
+ # The third argument is an optional hash of conditions to further filter the
26
+ # objects.
27
+ # For example, here the user can only update published articles.
28
+ #
29
+ # can :update, Article, :published => true
30
+ #
31
+ # See the wiki for details:
32
+ # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities
33
+
34
+ # TODO: Spiegare meglio Taris
35
+ # Modo per poter caricare diversi file ability presenti in diversi engine
36
+ # bisogna creare nella cartella config/initializers dell'engine un file che
37
+ # faccia il module_eval di TheCore::Abilities, aggiungendo un metodo
38
+ # che accetta user come parametro e con dentro la definizione delle ability
39
+ # include TheCore::Abilities
40
+ TheCoreAbilities.instance_methods(false).each do |a|
41
+ # method(a).call(user)
42
+ # eval("#{a} #{user}")
43
+ Rails.logger.debug "LOADING ABILITIES FROM: #{a}"
44
+ send(a, user)
45
+ end
46
+ # core_abilities user
47
+ end
48
+ end
@@ -0,0 +1,158 @@
1
+ class User < ApplicationRecord
2
+ include RailsAdmin
3
+ # # include default devise modules. Others available are:
4
+ # :confirmable, :lockable, :timeoutable and :omniauthable
5
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable #, :confirmable
6
+
7
+ before_create :generate_authentication_token
8
+
9
+ paginates_per 50
10
+
11
+ # Validations
12
+ # :username
13
+ validates :username, uniqueness: { case_sensitive: false }
14
+ validates_format_of :username, with: /\A[a-zA-Z0-9]*\z/, on: :create, message: "can only contain letters and digits"
15
+ validates :username, length: { in: 4..15 }
16
+ # :email
17
+ validates :email, uniqueness: { case_sensitive: false }
18
+ validates_format_of :email, with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i
19
+
20
+ validates :username, presence: true
21
+ validates :email, presence: true
22
+
23
+ validates :password, presence: true, on: :create
24
+ validates :password_confirmation, presence: true, on: :create
25
+
26
+ def self.paged(page_number)
27
+ order(admin: :desc, username: :asc).page page_number
28
+ end
29
+
30
+ def self.search_and_order(search, page_number)
31
+ if search
32
+ where("username LIKE ?", "%#{search.downcase}%").order(
33
+ admin: :desc, username: :asc
34
+ ).page page_number
35
+ else
36
+ order(admin: :desc, username: :asc).page page_number
37
+ end
38
+ end
39
+
40
+ def self.last_signups(count)
41
+ order(created_at: :desc).limit(count).select("id","username","slug","created_at")
42
+ end
43
+
44
+ def self.last_signins(count)
45
+ order(last_sign_in_at:
46
+ :desc).limit(count).select("id","username","slug","last_sign_in_at")
47
+ end
48
+
49
+ def self.users_count
50
+ where("admin = ? AND locked = ?",false,false).count
51
+ end
52
+
53
+ def title
54
+ username
55
+ end
56
+
57
+ serialize :roles, Array
58
+ def roles_enum
59
+ # Do not EDIT below this line
60
+ ROLES.each_with_index.map {|a,i| [I18n.t("roles.#{a.to_sym}"), (i+1).to_s]}
61
+ end
62
+ def has_role? role
63
+ # example called from cancan's app/models/ability.rb
64
+ # if user.has_role? :admin
65
+
66
+ # 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 .
67
+ chosen_roles = self.roles.map { |r| r.blank? ? nil : ROLES[r.to_i - 1] }
68
+ chosen_roles.compact.include? role
69
+ end
70
+
71
+ RailsAdmin.config do |config|
72
+ config.model self.name.underscore.capitalize.constantize do
73
+ # rails_admin do
74
+ navigation_label I18n.t("admin.settings.label")
75
+ navigation_icon 'fa fa-user-circle-o'
76
+ desc I18n.t("activerecord.descriptions.user")
77
+
78
+ weight 1000
79
+ # Field present Everywhere
80
+ field :email do
81
+ required true
82
+ end
83
+ field :username do
84
+ required true
85
+ end
86
+ field :code
87
+ field :admin do
88
+ visible do
89
+ bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
90
+ end
91
+ end
92
+ field :locked do
93
+ visible do
94
+ bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
95
+ end
96
+ end
97
+ field :third_party do
98
+ visible do
99
+ bindings[:view].current_user.admin? && bindings[:view].current_user.id != bindings[:object].id
100
+ end
101
+ end
102
+ field :roles, :enum do
103
+ visible !ROLES.blank?
104
+ pretty_value do # used in list view columns and show views, defaults to formatted_value for non-association fields
105
+ value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", "
106
+ end
107
+ export_value do
108
+ value.map { |v| bindings[:object].roles_enum.rassoc(v)[0] rescue nil }.compact.join ", " # used in exports, where no html/data is allowed
109
+ end
110
+ queryable false
111
+ end
112
+ # include UserRailsAdminConcern
113
+
114
+ # Fields only in lists and forms
115
+ list do
116
+ field :created_at
117
+ configure :email do
118
+ visible false
119
+ end
120
+
121
+ # include UserRailsAdminListConcern
122
+ end
123
+
124
+ create do
125
+ field :password do
126
+ required true
127
+ end
128
+ field :password_confirmation do
129
+ required true
130
+ end
131
+
132
+ # include UserRailsAdminCreateConcern
133
+ end
134
+
135
+ edit do
136
+ field :password do
137
+ required false
138
+ end
139
+ field :password_confirmation do
140
+ required false
141
+ end
142
+
143
+ # include UserRailsAdminEditConcern
144
+ end
145
+ end
146
+ end
147
+
148
+ #has_paper_trail
149
+
150
+ private
151
+
152
+ def generate_authentication_token
153
+ loop do
154
+ self.authentication_token = SecureRandom.base64(64)
155
+ break unless User.find_by(authentication_token: authentication_token)
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,27 @@
1
+ # class ImageUploader < CarrierWave::Uploader::Base
2
+ # include CarrierWave::MiniMagick
3
+ #
4
+ # storage :file
5
+ #
6
+ # def store_dir
7
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
8
+ # end
9
+ #
10
+ # #version :example, if: :is_example? do
11
+ # #process :resize_to_fill => [200, 150]
12
+ # #end
13
+ #
14
+ # def extension_white_list
15
+ # %w(jpg jpeg gif png)
16
+ # end
17
+ #
18
+ # def content_type_whitelist
19
+ # /image\//
20
+ # end
21
+ #
22
+ # protected
23
+ # #def is_example?(picture)
24
+ # # model.kind_of?(ExampleModel)
25
+ # #end
26
+ # end
27
+
@@ -0,0 +1,27 @@
1
+ # class ImageUploader < CarrierWave::Uploader::Base
2
+ # include CarrierWave::MiniMagick
3
+ #
4
+ # storage :file
5
+ #
6
+ # def store_dir
7
+ # "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
8
+ # end
9
+ #
10
+ # #version :example, if: :is_example? do
11
+ # #process :resize_to_fill => [200, 150]
12
+ # #end
13
+ #
14
+ # def extension_white_list
15
+ # %w(jpg jpeg gif png)
16
+ # end
17
+ #
18
+ # def content_type_whitelist
19
+ # /image\//
20
+ # end
21
+ #
22
+ # protected
23
+ # #def is_example?(picture)
24
+ # # model.kind_of?(ExampleModel)
25
+ # #end
26
+ # end
27
+
@@ -0,0 +1,42 @@
1
+ require 'rails_admin'
2
+
3
+ require "thecore_actions"
4
+
5
+ include TheCoreActions
6
+
7
+ RailsAdmin.config do |config|
8
+ # config.main_app_name = Proc.new { |controller|
9
+ # [(Settings.app_name rescue (ENV["APP_NAME"] || "TheCore App")), "#{controller.params[:action].try(:titleize)} (#{Time.zone.now.to_s(:time)})"]
10
+ # }
11
+ ### Popular gems integration
12
+
13
+ ## == Devise ==
14
+ config.authenticate_with do
15
+ warden.authenticate! scope: :user
16
+ end
17
+ config.current_user_method(&:current_user)
18
+
19
+ ## == Cancan ==
20
+ config.authorize_with :cancan
21
+
22
+ ## == PaperTrail ==
23
+ # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
24
+
25
+ ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
26
+ config.label_methods.unshift(:display_name)
27
+
28
+ config.actions do
29
+ # show_in_app
30
+ dashboard # mandatory
31
+ index # mandatory
32
+ new
33
+ export
34
+ bulk_delete
35
+ show
36
+ edit
37
+ delete
38
+ toggle
39
+ end
40
+ end
41
+
42
+ # require "thecore_rails_admin_main_controller_concern"
@@ -0,0 +1,28 @@
1
+ Rails.application.configure do
2
+ config.assets.precompile += %w( favicon.ico )
3
+ config.assets.precompile += %w( apple-touch-icon.png )
4
+ config.assets.precompile += %w( favicon-32x32.png )
5
+ config.assets.precompile += %w( favicon-16x16.png )
6
+ config.assets.precompile += %w( safari-pinned-tab.svg )
7
+ config.assets.precompile += %w( mstile-150x150.svg )
8
+ config.assets.precompile += %w( android-chrome-192x192.png )
9
+ config.assets.precompile += %w( android-chrome-512x512.png )
10
+ config.assets.precompile += %w( logo.png )
11
+ config.assets.precompile += %w( up-arrow.png )
12
+ # mstile-150x150
13
+ config.assets.precompile += %w( thecore.js )
14
+ config.assets.precompile += %w( thecore.css )
15
+ # config.assets.precompile += %w( app_logo.png )
16
+ # config.assets.precompile += %w( main_app_logo.png )
17
+ config.assets.precompile += %w( ie.js )
18
+ config.assets.precompile += %w( manifest.json )
19
+ config.assets.precompile += %w( browserconfig.xml )
20
+
21
+ config.filter_parameters += [:password]
22
+
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+
25
+ config.serviceworker.routes.draw do
26
+ match "/manifest.json"
27
+ end
28
+ end
@@ -0,0 +1,113 @@
1
+ require 'active_support/concern'
2
+
3
+ module ThecoreConcern
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ # Prevent CSRF attacks by raising an exception.
8
+ # For APIs, you may want to use :null_session instead.
9
+ layout 'thecore'
10
+ protect_from_forgery with: :exception, prepend: true
11
+ rescue_from CanCan::AccessDenied do |exception|
12
+ redirect_to main_app.root_url, :alert => exception.message
13
+ end
14
+ include HttpAcceptLanguage::AutoLocale
15
+ Rails.logger.debug "Selected Locale: #{I18n.locale}"
16
+ before_action :configure_permitted_parameters, if: :devise_controller?
17
+ before_action :reject_locked!, if: :devise_controller?
18
+
19
+ helper_method :reject_locked!
20
+ helper_method :require_admin!
21
+ helper_method :line_break
22
+ helper_method :title
23
+ helper_method :bootstrap_class_for
24
+
25
+ # Redirects on successful sign in
26
+ def after_sign_in_path_for resource
27
+ Rails.logger.debug("SUCCESFULL SIGNIN, USER IS ADMIN? #{current_user.admin?}")
28
+ #if current_user.admin?
29
+ # GETTING JUST THE ROOT ACTIONS I (CURRENT_USER) CAN MANAGE
30
+ root_actions = RailsAdmin::Config::Actions.all(:root).select {|action| can? action.action_name, :all }
31
+ # Rails.logger.debug "ROOT ACTIONS: #{root_actions.inspect}"
32
+ # GETTING THE FIRST ACTION I CAN MANAGE
33
+ action = root_actions.collect(&:action_name).first
34
+ # Rails.logger.debug "FIRST ACTION: #{action}"
35
+ # REDIRECT TO THAT ACTION
36
+ rails_admin.send("#{action}_path").sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
37
+ #rails_admin.dashboard_path.sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
38
+ #elsif current_user.has_role? :workers
39
+ # rails_admin.new_path('timetable').sub("#{ENV['RAILS_RELATIVE_URL_ROOT']}#{ENV['RAILS_RELATIVE_URL_ROOT']}", "#{ENV['RAILS_RELATIVE_URL_ROOT']}")
40
+ #else
41
+ # inside_path
42
+ #end
43
+ end
44
+ end
45
+
46
+ def title value = "Thecore"
47
+ @title = value
48
+ end
49
+
50
+ def bootstrap_class_for flash_type
51
+ case flash_type
52
+ when 'success'
53
+ 'alert-success'
54
+ when 'error'
55
+ 'alert-danger'
56
+ when 'alert'
57
+ 'alert-warning'
58
+ when 'notice'
59
+ 'alert-info'
60
+ else
61
+ flash_type.to_s
62
+ end
63
+ end
64
+
65
+ def line_break s
66
+ s.gsub("\n", "<br/>")
67
+ end
68
+ # Devise permitted params
69
+ def configure_permitted_parameters
70
+ devise_parameter_sanitizer.permit(:sign_in) { |u| u.permit(
71
+ :username,
72
+ :password,
73
+ :password_confirmation,
74
+ :remember_me)
75
+ }
76
+ devise_parameter_sanitizer.permit(:sign_up) { |u| u.permit(
77
+ :username,
78
+ :password,
79
+ :password_confirmation)
80
+ }
81
+ devise_parameter_sanitizer.permit(:account_update) { |u| u.permit(
82
+ :username,
83
+ :password,
84
+ :password_confirmation,
85
+ :current_password
86
+ )
87
+ }
88
+ end
89
+
90
+ # Auto-sign out locked users
91
+ def reject_locked!
92
+ if current_user && current_user.locked?
93
+ sign_out current_user
94
+ user_session = nil
95
+ current_user = nil
96
+ flash[:alert] = "Your account is locked."
97
+ flash[:notice] = nil
98
+ redirect_to root_url
99
+ end
100
+ end
101
+
102
+ # Only permits admin users
103
+ def require_admin!
104
+ authenticate_user!
105
+
106
+ if current_user && !current_user.admin?
107
+ redirect_to inside_path
108
+ end
109
+ end
110
+ end
111
+
112
+ # include the extension
113
+ ActionController::Base.send(:include, ThecoreConcern)
@@ -0,0 +1,6 @@
1
+ en:
2
+ activerecord:
3
+ models:
4
+ user:
5
+ one: User
6
+ other: Users Database
@@ -0,0 +1,5 @@
1
+ it:
2
+ contact_mailer:
3
+ message:
4
+ domain: "Domain: %{domain}"
5
+ from: "From: %{name} - %{email}"
@@ -0,0 +1,15 @@
1
+ en:
2
+ devise:
3
+ mailer:
4
+ password_changed_instructions:
5
+ greeting: Welcome %{recipient}!
6
+ instruction: We sent you this email to inform about password change.
7
+ instruction_2: If you didn't changed password, we ask you to contact our customer service, please.
8
+ shared:
9
+ links:
10
+ sign_out: Log out
11
+ descriptions:
12
+ current_password_needed: (we need your current password to confirm your changes)
13
+ leave_blank: (leave blank if you don't want to change it)
14
+ validations:
15
+ minimum_length: "%{length} characters minimum"
@@ -0,0 +1,34 @@
1
+ en:
2
+ admin:
3
+ misc:
4
+ scopes: Fast Filters
5
+ scopes:
6
+ all: All
7
+ order_by_name: Order By Name
8
+ order_by_insert_date: Order By Date
9
+ starts_with_a: Starts with A
10
+ starts_with_b: Starts with B
11
+ starts_with_c: Starts with C
12
+ starts_with_d: Starts with D
13
+ starts_with_e: Starts with E
14
+ starts_with_f: Starts with F
15
+ starts_with_g: Starts with G
16
+ starts_with_h: Starts with H
17
+ starts_with_i: Starts with I
18
+ starts_with_j: Starts with J
19
+ starts_with_k: Starts with K
20
+ starts_with_l: Starts with L
21
+ starts_with_m: Starts with M
22
+ starts_with_n: Starts with N
23
+ starts_with_o: Starts with O
24
+ starts_with_p: Starts with P
25
+ starts_with_q: Starts with Q
26
+ starts_with_r: Starts with R
27
+ starts_with_s: Starts with S
28
+ starts_with_t: Starts with T
29
+ starts_with_u: Starts with U
30
+ starts_with_v: Starts with V
31
+ starts_with_w: Starts with W
32
+ starts_with_x: Starts with X
33
+ starts_with_y: Starts with Y
34
+ starts_with_z: Starts with Z
@@ -0,0 +1,5 @@
1
+ en:
2
+ admin:
3
+ rollincode:
4
+ number: "Number"
5
+ show: "Show"
@@ -0,0 +1,31 @@
1
+ en:
2
+ simple_form:
3
+ "yes": 'Yes'
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: "Please review the problems below:"
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'