trusty-cms 4.1.2 → 4.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +104 -104
  4. data/README.md +1 -1
  5. data/Rakefile +7 -7
  6. data/app/assets/javascripts/admin/assets.js +1 -1
  7. data/app/assets/javascripts/rad_social/rad_ajax_form.js +3 -0
  8. data/app/assets/javascripts/rad_social/rad_email.js +0 -1
  9. data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
  10. data/app/assets/stylesheets/admin/partials/_content.scss +1 -2
  11. data/app/assets/stylesheets/rad_social/rad_screen.scss +0 -4
  12. data/app/controllers/admin/assets_controller.rb +22 -21
  13. data/app/controllers/admin/configuration_controller.rb +9 -11
  14. data/app/controllers/admin/extensions_controller.rb +3 -3
  15. data/app/controllers/admin/layouts_controller.rb +3 -4
  16. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  17. data/app/controllers/admin/page_fields_controller.rb +3 -4
  18. data/app/controllers/admin/page_parts_controller.rb +4 -5
  19. data/app/controllers/admin/pages_controller.rb +55 -56
  20. data/app/controllers/admin/references_controller.rb +1 -1
  21. data/app/controllers/admin/resource_controller.rb +132 -130
  22. data/app/controllers/admin/sites_controller.rb +4 -4
  23. data/app/controllers/admin/snippets_controller.rb +3 -4
  24. data/app/controllers/admin/users_controller.rb +16 -16
  25. data/app/controllers/application_controller.rb +47 -48
  26. data/app/controllers/site_controller.rb +51 -48
  27. data/app/controllers/social_mailer_controller.rb +12 -22
  28. data/app/helpers/admin/configuration_helper.rb +19 -20
  29. data/app/helpers/admin/layouts_helper.rb +0 -1
  30. data/app/helpers/admin/node_helper.rb +27 -24
  31. data/app/helpers/admin/pages_helper.rb +2 -2
  32. data/app/helpers/admin/preferences_helper.rb +0 -1
  33. data/app/helpers/admin/references_helper.rb +9 -10
  34. data/app/helpers/admin/regions_helper.rb +3 -3
  35. data/app/helpers/application_helper.rb +32 -33
  36. data/app/helpers/rad_social_helper.rb +8 -11
  37. data/app/helpers/scoped_helper.rb +1 -3
  38. data/app/helpers/sites_helper.rb +4 -4
  39. data/app/mailers/devise_mailer.rb +3 -4
  40. data/app/mailers/rad_social_mailer.rb +8 -8
  41. data/app/models/asset.rb +62 -63
  42. data/app/models/asset_type.rb +38 -39
  43. data/app/models/deprecated_tags.rb +3 -4
  44. data/app/models/file_not_found_page.rb +1 -3
  45. data/app/models/haml_filter.rb +1 -1
  46. data/app/models/layout.rb +4 -5
  47. data/app/models/legacy_user.rb +2 -2
  48. data/app/models/menu_renderer.rb +16 -18
  49. data/app/models/page.rb +96 -93
  50. data/app/models/page_attachment.rb +1 -2
  51. data/app/models/page_context.rb +11 -12
  52. data/app/models/page_part.rb +3 -4
  53. data/app/models/rails_page.rb +10 -12
  54. data/app/models/site.rb +22 -21
  55. data/app/models/snippet.rb +6 -8
  56. data/app/models/snippet_finder.rb +3 -3
  57. data/app/models/snippet_tags.rb +4 -4
  58. data/app/models/standard_tags.rb +258 -252
  59. data/app/models/status.rb +8 -8
  60. data/app/models/trusty_cms/config.rb +25 -25
  61. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  62. data/app/models/user.rb +15 -14
  63. data/app/models/user_action_observer.rb +3 -3
  64. data/app/views/admin/assets/edit.html.haml +3 -0
  65. data/app/views/rad_social_mailer/social_mail_form.html.haml +1 -3
  66. data/app/views/widget/_email_form.html.haml +0 -5
  67. data/bin/rails +4 -4
  68. data/bin/trusty_cms +3 -5
  69. data/config.ru +1 -1
  70. data/config/application.rb +14 -15
  71. data/config/boot.rb +1 -2
  72. data/config/environment.rb +1 -1
  73. data/config/environments/production.rb +0 -1
  74. data/config/environments/test.rb +1 -2
  75. data/config/initializers/devise.rb +1 -1
  76. data/config/initializers/kraken.rb +2 -2
  77. data/config/initializers/tmp.rb +1 -1
  78. data/config/initializers/trusty_cms_config.rb +48 -48
  79. data/config/locales/en.yml +1 -0
  80. data/config/routes.rb +6 -6
  81. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  82. data/lib/annotatable.rb +3 -5
  83. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  84. data/lib/inheritable_class_attributes.rb +13 -9
  85. data/lib/login_system.rb +73 -73
  86. data/lib/method_observer.rb +13 -12
  87. data/lib/ostruct.rb +7 -10
  88. data/lib/simpleton.rb +0 -4
  89. data/lib/string_extensions/string_extensions.rb +3 -3
  90. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  91. data/lib/tasks/database.rake +28 -28
  92. data/lib/tasks/extensions.rake +18 -18
  93. data/lib/tasks/framework.rake +68 -68
  94. data/lib/tasks/radiant_config.rake +4 -4
  95. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  96. data/lib/tasks/translate.rake +14 -14
  97. data/lib/tasks/upgrade_to_devise.rake +1 -1
  98. data/lib/translation_support.rb +22 -22
  99. data/lib/trusty_cms.rb +2 -2
  100. data/lib/trusty_cms/admin_ui.rb +19 -16
  101. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  102. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  103. data/lib/trusty_cms/available_locales.rb +2 -4
  104. data/lib/trusty_cms/config/definition.rb +11 -8
  105. data/lib/trusty_cms/engine.rb +13 -14
  106. data/lib/trusty_cms/extension.rb +14 -16
  107. data/lib/trusty_cms/extension_loader.rb +6 -6
  108. data/lib/trusty_cms/extension_migrator.rb +42 -41
  109. data/lib/trusty_cms/extension_path.rb +20 -19
  110. data/lib/trusty_cms/initializer.rb +5 -8
  111. data/lib/trusty_cms/pagination/controller.rb +7 -10
  112. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  113. data/lib/trusty_cms/resource_responses.rb +3 -3
  114. data/lib/trusty_cms/setup.rb +130 -132
  115. data/lib/trusty_cms/taggable.rb +19 -22
  116. data/lib/trusty_cms/task_support.rb +9 -6
  117. data/public/dispatch.fcgi +1 -1
  118. data/public/dispatch.rb +2 -2
  119. data/script/extension +1 -1
  120. data/script/rails +2 -2
  121. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/core.js +126 -0
  122. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/index.js +4 -0
  123. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/map.js +56 -0
  124. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/seq.js +43 -0
  125. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/string.js +28 -0
  126. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/index.js +36 -0
  127. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/json.js +76 -0
  128. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/options.js +23 -0
  129. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/binary.js +87 -0
  130. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/index.js +157 -0
  131. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/omap.js +142 -0
  132. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/pairs.js +81 -0
  133. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/set.js +114 -0
  134. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/timestamp.js +97 -0
  135. data/spec/spec/dummy/node_modules/yaml/dist/tags/core.js +114 -0
  136. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/index.js +17 -0
  137. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/map.js +37 -0
  138. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/seq.js +34 -0
  139. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/string.js +40 -0
  140. data/spec/spec/dummy/node_modules/yaml/dist/tags/index.js +62 -0
  141. data/spec/spec/dummy/node_modules/yaml/dist/tags/json.js +60 -0
  142. data/spec/spec/dummy/node_modules/yaml/dist/tags/options.js +35 -0
  143. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/binary.js +97 -0
  144. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/index.js +131 -0
  145. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/omap.js +105 -0
  146. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/pairs.js +80 -0
  147. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/set.js +91 -0
  148. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/timestamp.js +93 -0
  149. data/trusty_cms.gemspec +24 -24
  150. data/yarn.lock +3 -3
  151. metadata +7602 -103
  152. data/app/assets/javascripts/rad_social/captcha.js +0 -42
@@ -1,8 +1,7 @@
1
1
  # Don't change this file!
2
2
  # Configure your app in config/environment.rb and config/environments/*.rb
3
3
 
4
-
5
4
  # Set up gems listed in the Gemfile.
6
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
5
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
7
6
 
8
7
  require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
@@ -1,5 +1,5 @@
1
1
  # Load the rails application
2
- require File.expand_path('../application', __FILE__)
2
+ require File.expand_path('application', __dir__)
3
3
 
4
4
  # Initialize the rails application
5
5
  TrustyCms::Application.initialize!
@@ -40,5 +40,4 @@ TrustyCms::Application.configure do
40
40
  # config.after_initialize do
41
41
  # SiteController.cache_timeout = 12.hours
42
42
  # end
43
-
44
43
  end
@@ -18,13 +18,12 @@ TrustyCms::Application.configure do
18
18
  # end
19
19
 
20
20
  # Log error messages when you accidentally call methods on nil.
21
- config.whiny_nils = true
21
+ config.whiny_nils = true
22
22
 
23
23
  # Show full error reports and disable caching
24
24
  config.consider_all_requests_local = true
25
25
  config.action_controller.perform_caching = false
26
26
 
27
-
28
27
  # Raise an ActiveModel::MassAssignmentSecurity::Error any time
29
28
  # something is mass-assigned that shouldn't be for ease in debugging.
30
29
  # config.active_record.mass_assignment_sanitizer = :strict
@@ -20,7 +20,7 @@ Devise.setup do |config|
20
20
 
21
21
  # ==> Controller configuration
22
22
  # Configure the parent class to the devise controllers.
23
- #config.parent_controller = 'ApplicationController'
23
+ # config.parent_controller = 'ApplicationController'
24
24
 
25
25
  # ==> Mailer Configuration
26
26
  # Configure the e-mail address which will be shown in Devise::Mailer,
@@ -2,6 +2,6 @@ require 'rubygems'
2
2
  require 'kraken-io'
3
3
 
4
4
  $kraken = Kraken::API.new(
5
- :api_key => ENV['KRAKEN_KEY'],
6
- :api_secret => ENV['KRAKEN_SECRET']
5
+ api_key: ENV['KRAKEN_KEY'],
6
+ api_secret: ENV['KRAKEN_SECRET'],
7
7
  )
@@ -1,2 +1,2 @@
1
1
  require 'fileutils'
2
- FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
2
+ FileUtils.mkdir_p(Rails.root.join('tmp', 'stylesheets'))
@@ -2,47 +2,47 @@ require 'multi_site/engine'
2
2
  require 'clipped/engine'
3
3
 
4
4
  TrustyCms.config do |config|
5
- config.define 'admin.title', :default => "TrustyCms CMS"
5
+ config.define 'admin.title', default: 'TrustyCms CMS'
6
6
  config.define 'dev.host'
7
- config.define 'local.timezone', :allow_change => true, :select_from => lambda { ActiveSupport::TimeZone::MAPPING.keys.sort }
8
- config.define 'defaults.locale', :select_from => lambda { TrustyCms::AvailableLocales.locales }, :allow_blank => true
9
- config.define 'defaults.page.parts', :default => "Body,Extended"
10
- config.define 'defaults.page.status', :select_from => lambda { Status.selectable_values }, :allow_blank => false, :default => "Draft"
11
- config.define 'defaults.page.filter', :select_from => lambda { TextFilter.descendants.map { |s| s.filter_name }.sort }, :allow_blank => true
7
+ config.define 'local.timezone', allow_change: true, select_from: lambda { ActiveSupport::TimeZone::MAPPING.keys.sort }
8
+ config.define 'defaults.locale', select_from: lambda { TrustyCms::AvailableLocales.locales }, allow_blank: true
9
+ config.define 'defaults.page.parts', default: 'Body,Extended'
10
+ config.define 'defaults.page.status', select_from: lambda { Status.selectable_values }, allow_blank: false, default: 'Draft'
11
+ config.define 'defaults.page.filter', select_from: lambda { TextFilter.descendants.map { |s| s.filter_name }.sort }, allow_blank: true
12
12
  config.define 'defaults.page.fields'
13
- config.define 'pagination.param_name', :default => 'page'
14
- config.define 'pagination.per_page_param_name', :default => 'per_page'
15
- config.define 'admin.pagination.per_page', :type => :integer, :default => 50
16
- config.define 'site.title', :default => "Your site title", :allow_blank => false
17
- config.define 'site.host', :default => "www.example.com", :allow_blank => false
18
- config.define 'user.allow_password_reset?', :default => true
19
- config.define 'session_timeout', :default => 2.weeks
13
+ config.define 'pagination.param_name', default: 'page'
14
+ config.define 'pagination.per_page_param_name', default: 'per_page'
15
+ config.define 'admin.pagination.per_page', type: :integer, default: 50
16
+ config.define 'site.title', default: 'Your site title', allow_blank: false
17
+ config.define 'site.host', default: 'www.example.com', allow_blank: false
18
+ config.define 'user.allow_password_reset?', default: true
19
+ config.define 'session_timeout', default: 2.weeks
20
20
  require 'multi_site/scoped_validation'
21
21
  end
22
22
 
23
23
  TrustyCms.config do |config|
24
24
  config.namespace 'paperclip' do |pc|
25
- pc.define 'url', :default => '/system/:attachment/:id/:style/:basename:no_original_style.:extension', :allow_change => true
26
- pc.define 'path', :default => ':rails_root/public/system/:attachment/:id/:style/:basename:no_original_style.:extension', :allow_change => true
27
- pc.define 'skip_filetype_validation', :default => true, :type => :boolean
28
- pc.define 'storage', :default => 'filesystem',
29
- :select_from => {
30
- 'File System' => 'filesystem',
31
- 'Amazon S3' => 'fog',
32
- 'Google Storage' => 'fog',
33
- 'Rackspace Cloud Files' => 'fog'
25
+ pc.define 'url', default: '/system/:attachment/:id/:style/:basename:no_original_style.:extension', allow_change: true
26
+ pc.define 'path', default: ':rails_root/public/system/:attachment/:id/:style/:basename:no_original_style.:extension', allow_change: true
27
+ pc.define 'skip_filetype_validation', default: true, type: :boolean
28
+ pc.define 'storage', default: 'filesystem',
29
+ select_from: {
30
+ 'File System' => 'filesystem',
31
+ 'Amazon S3' => 'fog',
32
+ 'Google Storage' => 'fog',
33
+ 'Rackspace Cloud Files' => 'fog',
34
34
  },
35
- :allow_blank => false,
36
- :allow_display => false
35
+ allow_blank: false,
36
+ allow_display: false
37
37
 
38
38
  pc.namespace 'fog' do |fog|
39
- fog.define 'provider', :select_from => {
40
- 'Amazon S3' => 'AWS',
41
- 'Google Storage' => 'Google',
42
- 'Rackspace Cloud Files' => 'Rackspace'
43
- }
39
+ fog.define 'provider', select_from: {
40
+ 'Amazon S3' => 'AWS',
41
+ 'Google Storage' => 'Google',
42
+ 'Rackspace Cloud Files' => 'Rackspace',
43
+ }
44
44
  fog.define 'directory'
45
- fog.define 'public?', :default => true
45
+ fog.define 'public?', default: true
46
46
  fog.define 'host'
47
47
  end
48
48
 
@@ -59,35 +59,35 @@ TrustyCms.config do |config|
59
59
  pc.namespace 's3' do |s3|
60
60
  s3.define 'key'
61
61
  s3.define 'secret'
62
- s3.define 'region', :select_from => {
63
- 'Asia North East' => 'ap-northeast-1',
64
- 'Asia South East' => 'ap-southeast-1',
65
- 'EU West' => 'eu-west-1',
66
- 'US East' => 'us-east-1',
67
- 'US West' => 'us-west-1'
68
- }
62
+ s3.define 'region', select_from: {
63
+ 'Asia North East' => 'ap-northeast-1',
64
+ 'Asia South East' => 'ap-southeast-1',
65
+ 'EU West' => 'eu-west-1',
66
+ 'US East' => 'us-east-1',
67
+ 'US West' => 'us-west-1',
68
+ }
69
69
  end
70
70
  end
71
71
 
72
- config.namespace 'assets', :allow_display => false do |assets|
73
- assets.define 'create_image_thumbnails?', :default => 'true'
74
- assets.define 'create_video_thumbnails?', :default => 'true'
75
- assets.define 'create_pdf_thumbnails?', :default => 'true'
72
+ config.namespace 'assets', allow_display: false do |assets|
73
+ assets.define 'create_image_thumbnails?', default: 'true'
74
+ assets.define 'create_video_thumbnails?', default: 'true'
75
+ assets.define 'create_pdf_thumbnails?', default: 'true'
76
76
 
77
77
  assets.namespace 'thumbnails' do |thumbs| # NB :icon and :thumbnail are already defined as fixed formats for use in the admin interface and can't be changed
78
- thumbs.define 'image', :default => 'normal:size=640x640>|small:size=320x320>'
79
- thumbs.define 'video', :default => 'normal:size=640x640>,format=jpg|small:size=320x320>,format=jpg'
80
- thumbs.define 'pdf', :default => 'normal:size=640x640>,format=jpg|small:size=320x320>,format=jpg'
78
+ thumbs.define 'image', default: 'normal:size=640x640>|small:size=320x320>'
79
+ thumbs.define 'video', default: 'normal:size=640x640>,format=jpg|small:size=320x320>,format=jpg'
80
+ thumbs.define 'pdf', default: 'normal:size=640x640>,format=jpg|small:size=320x320>,format=jpg'
81
81
  end
82
82
 
83
- assets.define 'max_asset_size', :default => 5, :type => :integer, :units => 'MB'
84
- assets.define 'display_size', :default => 'normal', :allow_blank => true
85
- assets.define 'insertion_size', :default => 'normal', :allow_blank => true
83
+ assets.define 'max_asset_size', default: 5, type: :integer, units: 'MB'
84
+ assets.define 'display_size', default: 'normal', allow_blank: true
85
+ assets.define 'insertion_size', default: 'normal', allow_blank: true
86
86
  end
87
87
  end
88
88
 
89
89
  if TrustyCms.config_definitions['defaults.snippet.filter'].nil?
90
- TrustyCms.config.define 'defaults.snippet.filter', :select_from => lambda { TextFilter.descendants.map { |s| s.filter_name }.sort }, :allow_blank => true
90
+ TrustyCms.config.define 'defaults.snippet.filter', select_from: lambda { TextFilter.descendants.map { |s| s.filter_name }.sort }, allow_blank: true
91
91
  end
92
92
 
93
93
  Admin::LayoutsController.send :helper, MultiSite::SiteChooserHelper
@@ -65,6 +65,7 @@ en:
65
65
  asset_errors: 'Sorry. {{errors}}'
66
66
  asset_page_attachment_note: 'Attached assets. These can be inserted with drag and drop or shown with the <code>&lt;r:assets:each /&gt;</code> tag.'
67
67
  asset_note: 'Attached assets. '
68
+ asset_url: 'Asset URL'
68
69
  assets: 'Assets'
69
70
  assets_explanation: 'Assets and images can be uploaded and then attached or inserted into pages, snippets and layouts. Click on an asset name above to edit it or click <code>Remove</code> to delete it.'
70
71
  assets_title: 'Assets'
@@ -1,16 +1,16 @@
1
1
  TrustyCms::Application.routes.draw do
2
2
  root to: 'site#show_page'
3
- devise_for :users, module: :devise, :skip => :registration
3
+ devise_for :users, module: :devise, skip: :registration
4
4
  as :user do
5
5
  post 'authenticate', to: 'devise/sessions#create', as: :authenticate
6
6
  end
7
7
  get '/rad_social/mail' => 'social_mailer#social_mail_form', as: :rad_social_mail_form
8
8
  post '/rad_social/mail' => 'social_mailer#create_social_mail', as: :rad_create_social_mail
9
- TrustyCms::Application.config.enabled_extensions.each { |ext|
10
- }
9
+ TrustyCms::Application.config.enabled_extensions.each do |ext|
10
+ end
11
11
  namespace :admin do
12
12
  resources :pages do
13
- resources :children, :controller => 'pages'
13
+ resources :children, controller: 'pages'
14
14
  get 'remove', on: :member
15
15
  end
16
16
  resources :layouts do
@@ -22,7 +22,7 @@ TrustyCms::Application.routes.draw do
22
22
  resources :snippets do
23
23
  get :remove, on: :member
24
24
  end
25
- post 'save-table-position' => "pages#save_table_position", as: "save_tables_position"
25
+ post 'save-table-position' => 'pages#save_table_position', as: 'save_tables_position'
26
26
 
27
27
  resources :assets do
28
28
  get :remove, on: :member
@@ -38,7 +38,7 @@ TrustyCms::Application.routes.draw do
38
38
  end
39
39
  end
40
40
 
41
- match 'admin/preview' => 'admin/pages#preview', :as => :preview, :via => [:post, :put]
41
+ match 'admin/preview' => 'admin/pages#preview', :as => :preview, :via => %i[post put]
42
42
  get 'admin' => 'admin/pages#index'
43
43
 
44
44
  namespace :admin do
@@ -1,12 +1,11 @@
1
1
  require 'active_record'
2
2
 
3
3
  class ActiveRecord::Base
4
-
5
4
  def self.validates_path(*args)
6
5
  configuration = args.extract_options!
7
6
  validates_each(args, configuration) do |record, attr_name, value|
8
7
  page = Page.find_by_path(value)
9
- record.errors.add(attr_name, :page_not_found, :default => configuration[:message]) if page.nil? || page.is_a?(FileNotFoundPage)
8
+ record.errors.add(attr_name, :page_not_found, default: configuration[:message]) if page.nil? || page.is_a?(FileNotFoundPage)
10
9
  end
11
10
  end
12
11
 
@@ -1,5 +1,4 @@
1
1
  module Annotatable
2
-
3
2
  def self.included(base)
4
3
  base.extend ClassMethods
5
4
  end
@@ -14,7 +13,7 @@ module Annotatable
14
13
 
15
14
  def annotate(*attrs)
16
15
  options = {}
17
- options = attrs.pop if attrs.last.kind_of?(Hash)
16
+ options = attrs.pop if attrs.last.is_a?(Hash)
18
17
  options.symbolize_keys!
19
18
  inherit = options[:inherit]
20
19
  if inherit
@@ -42,13 +41,12 @@ module Annotatable
42
41
 
43
42
  def inherited_with_annotatable(subclass)
44
43
  inherited_without_annotatable(subclass)
45
- (["inherited_annotations"] + (@inherited_annotations || [])).each do |t|
44
+ (['inherited_annotations'] + (@inherited_annotations || [])).each do |t|
46
45
  ivar = "@#{t}"
47
46
  subclass.instance_variable_set(ivar, instance_variable_get(ivar))
48
47
  end
49
48
  end
50
49
  end
51
-
52
50
  end
53
51
 
54
52
  # We don't necessarily have ActiveSupport loaded yet!
@@ -63,6 +61,6 @@ class Hash
63
61
 
64
62
  # Destructively convert all keys to symbols.
65
63
  def symbolize_keys!
66
- self.replace(self.symbolize_keys)
64
+ replace(symbolize_keys)
67
65
  end
68
66
  end
@@ -317,4 +317,4 @@ class GemBoot < Boot
317
317
  def load_error_message
318
318
  "Have you run `bundle install`?'."
319
319
  end
320
- end
320
+ end
@@ -20,26 +20,26 @@ module InheritableClassAttributes
20
20
 
21
21
  def cattr_inheritable_reader(*symbols)
22
22
  symbols.each do |symbol|
23
- self.inheritable_cattr_readers << symbol
24
- self.module_eval %{
23
+ inheritable_cattr_readers << symbol
24
+ module_eval %{
25
25
  def self.#{symbol}
26
26
  @#{symbol}
27
27
  end
28
28
  }
29
29
  end
30
- self.inheritable_cattr_readers.uniq!
30
+ inheritable_cattr_readers.uniq!
31
31
  end
32
32
 
33
33
  def cattr_inheritable_writer(*symbols)
34
34
  symbols.each do |symbol|
35
- self.inheritable_cattr_writers << symbol
36
- self.module_eval %{
35
+ inheritable_cattr_writers << symbol
36
+ module_eval %{
37
37
  def self.#{symbol}=(value)
38
38
  @#{symbol} = value
39
39
  end
40
40
  }
41
41
  end
42
- self.inheritable_cattr_writers.uniq!
42
+ inheritable_cattr_writers.uniq!
43
43
  end
44
44
 
45
45
  def cattr_inheritable_accessor(*symbols)
@@ -52,12 +52,16 @@ module InheritableClassAttributes
52
52
 
53
53
  readers = inheritable_cattr_readers.dup
54
54
  writers = inheritable_cattr_writers.dup
55
- inheritables = [:inheritable_cattr_readers, :inheritable_cattr_writers]
55
+ inheritables = %i[inheritable_cattr_readers inheritable_cattr_writers]
56
56
 
57
57
  (readers + writers + inheritables).uniq.each do |attr|
58
58
  var = "@#{attr}"
59
- old_value = self.module_eval(var)
60
- new_value = (old_value.dup rescue old_value)
59
+ old_value = module_eval(var)
60
+ new_value = (begin
61
+ old_value.dup
62
+ rescue StandardError
63
+ old_value
64
+ end)
61
65
  klass.module_eval("#{var} = new_value")
62
66
  end
63
67
  end
@@ -2,93 +2,94 @@ module LoginSystem
2
2
  def self.included(base)
3
3
  base.extend ClassMethods
4
4
  base.class_eval do
5
- #prepend_before_action :authenticate
6
- #prepend_before_action :authorize
7
- #helper_method :current_user
5
+ # prepend_before_action :authenticate
6
+ # prepend_before_action :authorize
7
+ # helper_method :current_user
8
8
  end
9
9
  end
10
10
 
11
11
  protected
12
12
 
13
- # def current_user
13
+ # def current_user
14
+ # end
15
+
16
+ # def current_user=(value=nil)
17
+ # if value && value.is_a?(User)
18
+ # @current_user = value
19
+ # session['user_id'] = value.id
20
+ # else
21
+ # @current_user = nil
22
+ # session['user_id'] = nil
23
+ # end
24
+ # @current_user
25
+ # end
26
+
27
+ def authenticate
28
+ # puts _process_action_callbacks.map(&:filter)
29
+ # if current_user
30
+ # session['user_id'] = current_user.id
31
+ # true
32
+ # else
33
+ # session[:return_to] = request.original_url
34
+ # respond_to do |format|
35
+ # format.html { redirect_to login_url }
36
+ # format.any(:xml,:json) { request_http_basic_authentication }
37
+ # end
38
+ # false
14
39
  # end
40
+ true
41
+ end
15
42
 
16
- # def current_user=(value=nil)
17
- # if value && value.is_a?(User)
18
- # @current_user = value
19
- # session['user_id'] = value.id
20
- # else
21
- # @current_user = nil
22
- # session['user_id'] = nil
43
+ def authorize
44
+ # puts _process_action_callbacks.map(&:filter)
45
+ # action = action_name.to_s.intern
46
+ # if user_has_access_to_action?(action)
47
+ # true
48
+ # else
49
+ # permissions = self.class.controller_permissions[action]
50
+ # flash[:error] = permissions[:denied_message] || 'Access denied.'
51
+ # respond_to do |format|
52
+ # format.html { redirect_to(permissions[:denied_url] || { :action => :index }) }
53
+ # format.any(:xml, :json) { head :forbidden }
23
54
  # end
24
- # @current_user
55
+ # false
25
56
  # end
57
+ true
58
+ end
26
59
 
27
- def authenticate
28
- #puts _process_action_callbacks.map(&:filter)
29
- # if current_user
30
- # session['user_id'] = current_user.id
31
- # true
32
- # else
33
- # session[:return_to] = request.original_url
34
- # respond_to do |format|
35
- # format.html { redirect_to login_url }
36
- # format.any(:xml,:json) { request_http_basic_authentication }
37
- # end
38
- # false
39
- # end
40
- true
41
- end
42
-
43
- def authorize
44
- #puts _process_action_callbacks.map(&:filter)
45
- # action = action_name.to_s.intern
46
- # if user_has_access_to_action?(action)
47
- # true
48
- # else
49
- # permissions = self.class.controller_permissions[action]
50
- # flash[:error] = permissions[:denied_message] || 'Access denied.'
51
- # respond_to do |format|
52
- # format.html { redirect_to(permissions[:denied_url] || { :action => :index }) }
53
- # format.any(:xml, :json) { head :forbidden }
54
- # end
55
- # false
56
- # end
57
- true
58
- end
59
-
60
- def user_has_access_to_action?(action)
61
- self.class.user_has_access_to_action?(current_user, action, self)
62
- end
60
+ def user_has_access_to_action?(action)
61
+ self.class.user_has_access_to_action?(current_user, action, self)
62
+ end
63
63
 
64
- def login_from_session
65
- User.unscoped.find(session['user_id']) rescue nil
66
- end
64
+ def login_from_session
65
+ User.unscoped.find(session['user_id'])
66
+ rescue StandardError
67
+ nil
68
+ end
67
69
 
68
- def login_from_cookie
69
- if !cookies[:session_token].blank? && user = User.find_by_session_token(cookies[:session_token]) # don't find by empty value
70
- user.remember_me
71
- set_session_cookie(user)
72
- user
73
- end
70
+ def login_from_cookie
71
+ if !cookies[:session_token].blank? && user = User.find_by_session_token(cookies[:session_token]) # don't find by empty value
72
+ user.remember_me
73
+ set_session_cookie(user)
74
+ user
74
75
  end
76
+ end
75
77
 
76
- def login_from_http
77
- if [Mime[:xml], Mime[:json]].include?(request.format)
78
- authenticate_with_http_basic do |user_name, password|
79
- User.authenticate(user_name, password)
80
- end
78
+ def login_from_http
79
+ if [Mime[:xml], Mime[:json]].include?(request.format)
80
+ authenticate_with_http_basic do |user_name, password|
81
+ User.authenticate(user_name, password)
81
82
  end
82
83
  end
84
+ end
83
85
 
84
- def set_session_cookie(user = current_user)
85
- cookies[:session_token] = { :value => user.session_token , :expires => (Time.now + ((TrustyCms::Config['session_timeout'].to_i)/86400).days).utc }
86
- end
86
+ def set_session_cookie(user = current_user)
87
+ cookies[:session_token] = { value: user.session_token, expires: (Time.now + (TrustyCms::Config['session_timeout'].to_i / 86400).days).utc }
88
+ end
87
89
 
88
90
  module ClassMethods
89
-
90
91
  def login_required?
91
- filter_chain.any? {|f| f.method == :authenticate || f.method == :authorize }
92
+ filter_chain.any? { |f| f.method == :authenticate || f.method == :authorize }
92
93
  end
93
94
 
94
95
  def login_required
@@ -99,7 +100,7 @@ module LoginSystem
99
100
 
100
101
  def only_allow_access_to(*args)
101
102
  options = {}
102
- options = args.pop.dup if args.last.kind_of?(Hash)
103
+ options = args.pop.dup if args.last.is_a?(Hash)
103
104
  options.symbolize_keys!
104
105
  actions = args.map { |a| a.to_s.intern }
105
106
  actions.each do |action|
@@ -108,16 +109,15 @@ module LoginSystem
108
109
  end
109
110
 
110
111
  def controller_permissions
111
- @controller_permissions ||= Hash.new { |h,k| h[k.to_s.intern] = Hash.new }
112
+ @controller_permissions ||= Hash.new { |h, k| h[k.to_s.intern] = Hash.new }
112
113
  end
113
114
 
114
- def user_has_access_to_action?(user, action, instance=new)
115
+ def user_has_access_to_action?(user, action, instance = new)
115
116
  permissions = controller_permissions[action.to_s.intern]
116
- case
117
- when allowed_roles = permissions[:when]
117
+ if allowed_roles = permissions[:when]
118
118
  allowed_roles = [allowed_roles].flatten
119
119
  user.present? ? allowed_roles.any? { |role| user.has_role?(role) } : false
120
- when condition_method = permissions[:if]
120
+ elsif condition_method = permissions[:if]
121
121
  instance.send(condition_method)
122
122
  else
123
123
  true