trusty-cms 4.1.2 → 4.1.3
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 +4 -4
- data/Gemfile +2 -2
- data/Gemfile.lock +25 -25
- data/Rakefile +7 -7
- data/app/assets/stylesheets/admin/partials/_content.scss +1 -2
- data/app/controllers/admin/assets_controller.rb +22 -21
- data/app/controllers/admin/configuration_controller.rb +9 -11
- data/app/controllers/admin/extensions_controller.rb +3 -3
- data/app/controllers/admin/layouts_controller.rb +3 -4
- data/app/controllers/admin/page_attachments_controller.rb +5 -5
- data/app/controllers/admin/page_fields_controller.rb +3 -4
- data/app/controllers/admin/page_parts_controller.rb +4 -5
- data/app/controllers/admin/pages_controller.rb +55 -56
- data/app/controllers/admin/references_controller.rb +1 -1
- data/app/controllers/admin/resource_controller.rb +132 -130
- data/app/controllers/admin/sites_controller.rb +4 -4
- data/app/controllers/admin/snippets_controller.rb +3 -4
- data/app/controllers/admin/users_controller.rb +16 -16
- data/app/controllers/application_controller.rb +47 -48
- data/app/controllers/site_controller.rb +51 -48
- data/app/controllers/social_mailer_controller.rb +13 -16
- data/app/helpers/admin/configuration_helper.rb +19 -20
- data/app/helpers/admin/layouts_helper.rb +0 -1
- data/app/helpers/admin/node_helper.rb +27 -24
- data/app/helpers/admin/pages_helper.rb +2 -2
- data/app/helpers/admin/preferences_helper.rb +0 -1
- data/app/helpers/admin/references_helper.rb +9 -10
- data/app/helpers/admin/regions_helper.rb +3 -3
- data/app/helpers/application_helper.rb +32 -33
- data/app/helpers/rad_social_helper.rb +8 -11
- data/app/helpers/scoped_helper.rb +1 -3
- data/app/helpers/sites_helper.rb +4 -4
- data/app/mailers/devise_mailer.rb +3 -4
- data/app/mailers/rad_social_mailer.rb +8 -8
- data/app/models/asset.rb +62 -63
- data/app/models/asset_type.rb +38 -39
- data/app/models/deprecated_tags.rb +3 -4
- data/app/models/file_not_found_page.rb +1 -3
- data/app/models/haml_filter.rb +1 -1
- data/app/models/layout.rb +4 -5
- data/app/models/legacy_user.rb +2 -2
- data/app/models/menu_renderer.rb +16 -18
- data/app/models/page.rb +96 -93
- data/app/models/page_attachment.rb +1 -2
- data/app/models/page_context.rb +11 -12
- data/app/models/page_part.rb +3 -4
- data/app/models/rails_page.rb +10 -12
- data/app/models/site.rb +22 -21
- data/app/models/snippet.rb +6 -8
- data/app/models/snippet_finder.rb +3 -3
- data/app/models/snippet_tags.rb +4 -4
- data/app/models/standard_tags.rb +258 -252
- data/app/models/status.rb +8 -8
- data/app/models/trusty_cms/config.rb +25 -25
- data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
- data/app/models/user.rb +15 -14
- data/app/models/user_action_observer.rb +3 -3
- data/bin/rails +4 -4
- data/bin/trusty_cms +3 -5
- data/config.ru +1 -1
- data/config/application.rb +14 -15
- data/config/boot.rb +1 -2
- data/config/environment.rb +1 -1
- data/config/environments/production.rb +0 -1
- data/config/environments/test.rb +1 -2
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/kraken.rb +2 -2
- data/config/initializers/tmp.rb +1 -1
- data/config/initializers/trusty_cms_config.rb +48 -48
- data/config/routes.rb +6 -6
- data/lib/active_record_extensions/active_record_extensions.rb +1 -2
- data/lib/annotatable.rb +3 -5
- data/lib/configuration_extensions/configuration_extensions.rb +1 -1
- data/lib/inheritable_class_attributes.rb +13 -9
- data/lib/login_system.rb +73 -73
- data/lib/method_observer.rb +13 -12
- data/lib/ostruct.rb +7 -10
- data/lib/simpleton.rb +0 -4
- data/lib/string_extensions/string_extensions.rb +3 -3
- data/lib/symbol_extensions/symbol_extensions.rb +1 -1
- data/lib/tasks/database.rake +28 -28
- data/lib/tasks/extensions.rake +18 -18
- data/lib/tasks/framework.rake +68 -68
- data/lib/tasks/radiant_config.rake +4 -4
- data/lib/tasks/snippets_extension_tasks.rake +11 -11
- data/lib/tasks/translate.rake +14 -14
- data/lib/tasks/upgrade_to_devise.rake +1 -1
- data/lib/translation_support.rb +22 -22
- data/lib/trusty_cms.rb +2 -2
- data/lib/trusty_cms/admin_ui.rb +19 -16
- data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
- data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
- data/lib/trusty_cms/available_locales.rb +2 -4
- data/lib/trusty_cms/config/definition.rb +11 -8
- data/lib/trusty_cms/engine.rb +14 -14
- data/lib/trusty_cms/extension.rb +14 -16
- data/lib/trusty_cms/extension_loader.rb +6 -6
- data/lib/trusty_cms/extension_migrator.rb +42 -41
- data/lib/trusty_cms/extension_path.rb +20 -19
- data/lib/trusty_cms/initializer.rb +5 -8
- data/lib/trusty_cms/pagination/controller.rb +7 -10
- data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
- data/lib/trusty_cms/resource_responses.rb +3 -3
- data/lib/trusty_cms/setup.rb +130 -132
- data/lib/trusty_cms/taggable.rb +19 -22
- data/lib/trusty_cms/task_support.rb +9 -6
- data/public/dispatch.fcgi +1 -1
- data/public/dispatch.rb +2 -2
- data/script/extension +1 -1
- data/script/rails +2 -2
- data/trusty_cms.gemspec +23 -23
- metadata +32 -32
data/config/environment.rb
CHANGED
data/config/environments/test.rb
CHANGED
|
@@ -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
|
|
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,
|
data/config/initializers/tmp.rb
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
require 'fileutils'
|
|
2
|
-
FileUtils.mkdir_p(Rails.root.join(
|
|
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', :
|
|
5
|
+
config.define 'admin.title', default: 'TrustyCms CMS'
|
|
6
6
|
config.define 'dev.host'
|
|
7
|
-
config.define 'local.timezone', :
|
|
8
|
-
config.define 'defaults.locale', :
|
|
9
|
-
config.define 'defaults.page.parts', :
|
|
10
|
-
config.define 'defaults.page.status', :
|
|
11
|
-
config.define 'defaults.page.filter', :
|
|
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', :
|
|
14
|
-
config.define 'pagination.per_page_param_name', :
|
|
15
|
-
config.define 'admin.pagination.per_page', :
|
|
16
|
-
config.define 'site.title', :
|
|
17
|
-
config.define 'site.host', :
|
|
18
|
-
config.define 'user.allow_password_reset?', :
|
|
19
|
-
config.define 'session_timeout', :
|
|
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', :
|
|
26
|
-
pc.define 'path', :
|
|
27
|
-
pc.define 'skip_filetype_validation', :
|
|
28
|
-
pc.define 'storage', :
|
|
29
|
-
:
|
|
30
|
-
'File System'
|
|
31
|
-
'Amazon S3'
|
|
32
|
-
'Google Storage'
|
|
33
|
-
'Rackspace Cloud Files'
|
|
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
|
-
:
|
|
36
|
-
:
|
|
35
|
+
allow_blank: false,
|
|
36
|
+
allow_display: false
|
|
37
37
|
|
|
38
38
|
pc.namespace 'fog' do |fog|
|
|
39
|
-
fog.define 'provider', :
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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?', :
|
|
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', :
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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', :
|
|
73
|
-
assets.define 'create_image_thumbnails?', :
|
|
74
|
-
assets.define 'create_video_thumbnails?', :
|
|
75
|
-
assets.define 'create_pdf_thumbnails?', :
|
|
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', :
|
|
79
|
-
thumbs.define 'video', :
|
|
80
|
-
thumbs.define 'pdf', :
|
|
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', :
|
|
84
|
-
assets.define 'display_size', :
|
|
85
|
-
assets.define 'insertion_size', :
|
|
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', :
|
|
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
|
data/config/routes.rb
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
TrustyCms::Application.routes.draw do
|
|
2
2
|
root to: 'site#show_page'
|
|
3
|
-
devise_for :users, module: :devise, :
|
|
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
|
|
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, :
|
|
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' =>
|
|
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 => [
|
|
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, :
|
|
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
|
|
data/lib/annotatable.rb
CHANGED
|
@@ -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.
|
|
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
|
-
([
|
|
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
|
-
|
|
64
|
+
replace(symbolize_keys)
|
|
67
65
|
end
|
|
68
66
|
end
|
|
@@ -20,26 +20,26 @@ module InheritableClassAttributes
|
|
|
20
20
|
|
|
21
21
|
def cattr_inheritable_reader(*symbols)
|
|
22
22
|
symbols.each do |symbol|
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
30
|
+
inheritable_cattr_readers.uniq!
|
|
31
31
|
end
|
|
32
32
|
|
|
33
33
|
def cattr_inheritable_writer(*symbols)
|
|
34
34
|
symbols.each do |symbol|
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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 = [
|
|
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 =
|
|
60
|
-
new_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
|
data/lib/login_system.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
17
|
-
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
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
|
-
#
|
|
55
|
+
# false
|
|
25
56
|
# end
|
|
57
|
+
true
|
|
58
|
+
end
|
|
26
59
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
def login_from_session
|
|
65
|
+
User.unscoped.find(session['user_id'])
|
|
66
|
+
rescue StandardError
|
|
67
|
+
nil
|
|
68
|
+
end
|
|
67
69
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
120
|
+
elsif condition_method = permissions[:if]
|
|
121
121
|
instance.send(condition_method)
|
|
122
122
|
else
|
|
123
123
|
true
|