rails_admin_cms 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 47d6104a8249cfb64b0579732b7abdf5e9600c57
4
- data.tar.gz: 12c545d7bdaa8a096d50e28c31a3a928ca274f8a
3
+ metadata.gz: 9f8bb36dc3f8fda329fa6f6f7963ff41e2707db3
4
+ data.tar.gz: 5507980dc86a5fb2c302adb9a48a6ff0bc21d79c
5
5
  SHA512:
6
- metadata.gz: c790c31c68a1cff583a72f57f983a0c1666532ab6d6ab6f7788f7e75e7c51aeab057f19eac6436b33d4f0aca6024ca97b68f6820c90eddc4abb077249729d2c9
7
- data.tar.gz: ad2cf322ad079e6fd0c6c8769aad3e268d5b9b1bed108ff91c5b7169da1464d785cda76a2adadb7bfe1c069b730176c4521cc749e83f8585297be1ae7c30aa9e
6
+ metadata.gz: 5321a7dd235768491894cc59e0b6ee1fd3c1990ae0aae6239715f66b682f2547e5a644c6a23fc68c76cd284ce6de264c71282391a96fac781ff0bc8f9cb0640c
7
+ data.tar.gz: 634038e2d6aec4c5061785574cf2148bd32cf6371233c9788e41b0be2cd6c213c52d170b4734f67aade35a45b2c80ea2cb82c999c49daddbeb1a11d587125cf0
@@ -0,0 +1,16 @@
1
+ module CMS
2
+ module Logger
3
+ extend ActiveSupport
4
+
5
+ protected
6
+
7
+ def cms_logger(exception, log_name = nil)
8
+ current_logger = log_name ? ::Logger.new("#{Rails.root}/log/#{log_name}.log") : logger
9
+ current_logger.error "[ERROR][#{request.remote_ip}][#{request.method}][#{request.original_url}]"
10
+ if exception
11
+ current_logger.error exception.message
12
+ exception.backtrace.each{ |line| current_logger.error line }
13
+ end
14
+ end
15
+ end
16
+ end
@@ -33,5 +33,53 @@ module CMS
33
33
  default
34
34
  end
35
35
  end
36
+
37
+ def cms_meta_og_tags(title = nil)
38
+ tags = {}
39
+ if @product # TODO: move to Solidus connector
40
+ tags[:title] = @product.name
41
+ tags[:description] = @product.description
42
+ tags[:url] = product_url(@product, only_path: false)
43
+ image = @product.images.first.try(:attachment)
44
+ tags[:image] = image.try(:url, :product)
45
+ else
46
+ tags[:title] = title.blank? ? Setting['cms_og_tag_title'] : title
47
+ end
48
+ %{
49
+ <meta property="og:title" content="#{tags[:title]}" />
50
+ <meta property="og:type" content="website" />
51
+ <meta property="og:description" content="#{tags[:description] || Setting['cms_og_tag_description']}" />
52
+ <meta property="og:url" content="#{tags[:url] || request.original_url }" />
53
+ <meta property="og:image" content="#{image_url(tags[:image] || 'ogimage.jpg', only_path: false)}" />
54
+ }.html_safe
55
+ end
56
+
57
+ def yes_no(boolean)
58
+ boolean ? t('yes') : t('no')
59
+ end
60
+
61
+ def to_nbsp(value)
62
+ value.kind_of?(String) ? value.gsub(' ', '&nbsp;').gsub('-', '&#8209;') : (value || '')
63
+ end
64
+
65
+ def to_currency(value)
66
+ number_to_currency(value, separator: '.', delimiter: '', format: '%n $')
67
+ end
68
+
69
+ def to_int_if_whole(float)
70
+ (float % 1 == 0) ? float.to_i : float
71
+ end
72
+
73
+ def full_name(object, prefix = nil)
74
+ if prefix
75
+ "#{object.send("#{prefix}_firstname")} #{object.send("#{prefix}_lastname")}"
76
+ else
77
+ "#{object.firstname} #{object.lastname}"
78
+ end
79
+ end
80
+
81
+ def current_url_without_params
82
+ "#{request.base_url}#{request.path}"
83
+ end
36
84
  end
37
85
  end
@@ -1,7 +1,7 @@
1
1
  class Setting < ActiveRecord::Base
2
2
  include Admin::Setting
3
3
 
4
- has_paper_trail if RailsAdminCMS::Config.with_paper_trail?
4
+ has_paper_trail
5
5
 
6
6
  cattr_accessor :cache
7
7
  self.cache = Rails.cache
@@ -1,7 +1,7 @@
1
1
  class UniqueKey < ActiveRecord::Base
2
2
  include Admin::UniqueKey
3
3
 
4
- has_paper_trail if RailsAdminCMS::Config.with_paper_trail?
4
+ has_paper_trail
5
5
 
6
6
  belongs_to :viewable, polymorphic: true
7
7
 
@@ -4,7 +4,7 @@ module Viewable
4
4
  included do
5
5
  self.table_name_prefix = 'viewable_'
6
6
 
7
- has_paper_trail if RailsAdminCMS::Config.with_paper_trail?
7
+ has_paper_trail
8
8
 
9
9
  has_one :unique_key, as: :viewable, dependent: :destroy
10
10
 
@@ -0,0 +1,20 @@
1
+ class CreateVersions < ActiveRecord::Migration
2
+
3
+ # The largest text column available in all supported RDBMS is
4
+ # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size
5
+ # so that MySQL will use `longtext` instead of `text`. Otherwise,
6
+ # when serializing very large objects, `text` might not be big enough.
7
+ TEXT_BYTES = 1_073_741_823
8
+
9
+ def change
10
+ create_table :versions do |t|
11
+ t.string :item_type, :null => false
12
+ t.integer :item_id, :null => false
13
+ t.string :event, :null => false
14
+ t.string :whodunnit
15
+ t.text :object, :limit => TEXT_BYTES
16
+ t.datetime :created_at
17
+ end
18
+ add_index :versions, [:item_type, :item_id]
19
+ end
20
+ end
@@ -0,0 +1,10 @@
1
+ class AddObjectChangesToVersions < ActiveRecord::Migration
2
+
3
+ # The largest text column available in all supported RDBMS.
4
+ # See `create_versions.rb` for details.
5
+ TEXT_BYTES = 1_073_741_823
6
+
7
+ def change
8
+ add_column :versions, :object_changes, :text, limit: TEXT_BYTES
9
+ end
10
+ end
@@ -0,0 +1,17 @@
1
+ class CreateVersionAssociations < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :version_associations do |t|
4
+ t.integer :version_id
5
+ t.string :foreign_key_name, :null => false
6
+ t.integer :foreign_key_id
7
+ end
8
+ add_index :version_associations, [:version_id]
9
+ add_index :version_associations, [:foreign_key_name, :foreign_key_id], :name => 'index_version_associations_on_foreign_key'
10
+ end
11
+
12
+ def self.down
13
+ remove_index :version_associations, [:version_id]
14
+ remove_index :version_associations, :name => 'index_version_associations_on_foreign_key'
15
+ drop_table :version_associations
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ class AddTransactionIdColumnToVersions < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :versions, :transaction_id, :integer
4
+ add_index :versions, [:transaction_id]
5
+ end
6
+
7
+ def self.down
8
+ remove_index :versions, [:transaction_id]
9
+ remove_column :versions, :transaction_id
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ class AddCMSOgTagsSettings < ActiveRecord::Migration
2
+ def change
3
+ def up
4
+ Setting.apply_all(
5
+ cms_og_tag_title: Rails.application.class.parent_name,
6
+ cms_og_tag_description: Rails.application.class.parent_name,
7
+ )
8
+ end
9
+ def down
10
+ Setting.remove_all(
11
+ :cms_og_tag_title,
12
+ :cms_og_tag_description,
13
+ )
14
+ end
15
+ end
16
+ end
@@ -6,4 +6,9 @@ class ApplicationController < ActionController::Base
6
6
  include CMS::Localize
7
7
  include CMS::Editing
8
8
  include CMS::Authenticate
9
+ include CMS::Logger
10
+
11
+ def paper_trail_enabled_for_controller
12
+ false
13
+ end
9
14
  end
@@ -1,12 +1,21 @@
1
1
  RailsAdmin.config do |config|
2
- ### Popular gems integration
2
+ config.main_app_name = ["Dashboard", ""]
3
+
3
4
  config.browser_validations = false
4
5
 
6
+ config.compact_show_view = false
7
+
8
+ ### Popular gems integration
9
+
5
10
  ## == Devise ==
6
11
  # config.authenticate_with do
7
12
  # warden.authenticate! scope: :user
8
13
  # end
9
- # config.current_user_method(&:current_user)
14
+ config.current_user_method(&:current_admin)
15
+
16
+ config.authorize_with do
17
+ redirect_to '/' unless current_admin?
18
+ end
10
19
 
11
20
  ## == Cancan ==
12
21
  # config.authorize_with :cancan
@@ -15,7 +24,11 @@ RailsAdmin.config do |config|
15
24
  # config.authorize_with :pundit
16
25
 
17
26
  ## == PaperTrail ==
18
- # config.audit_with :paper_trail, 'User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
27
+ if 'Spree::User'.safe_constantize # TODO: move to Solidus connector
28
+ config.audit_with :paper_trail, 'Spree::User', 'PaperTrail::Version' # PaperTrail >= 3.0.0
29
+ else
30
+ config.audit_with :paper_trail, 'BlackHole', 'PaperTrail::Version'
31
+ end
19
32
 
20
33
  ### More at https://github.com/sferik/rails_admin/wiki/Base-configuration
21
34
 
@@ -65,8 +78,8 @@ RailsAdmin.config do |config|
65
78
  show_in_app
66
79
 
67
80
  ## With an audit adapter, you can add:
68
- # history_index
69
- # history_show
81
+ history_index
82
+ history_show
70
83
  end
71
84
 
72
85
  config.model 'Rich::RichFile' do
@@ -5,9 +5,6 @@ RailsAdminCMS.config do |config|
5
5
  # Defines the base mailer inherited from
6
6
  # config.parent_mailer = ::ApplicationMailer
7
7
 
8
- # Defines if PaperTrail support is used
9
- # config.with_paper_trail = false
10
-
11
8
  # Defines the maximum number of fields a Form defined admin side has
12
9
  # * it is important to note that rake cms:adjust_max_size needs to be run if that number changes
13
10
  # config.custom_form_max_size = 20
@@ -19,6 +19,14 @@ require "invisible_captcha"
19
19
  require "jquery-form-validator-rails"
20
20
  require "bootstrap_flash_messages"
21
21
 
22
+ require "paper_trail"
23
+ require "rails_admin_history_rollback"
24
+ require "naught"
25
+
26
+ BlackHole = Naught.build do |config|
27
+ config.black_hole
28
+ end
29
+
22
30
  require "rails_admin_cms/engine"
23
31
  require "rails_admin_cms/inflections"
24
32
  require "rails_admin_cms/core_ext/boolean"
@@ -13,7 +13,6 @@ module RailsAdminCMS
13
13
  attr_writer(
14
14
  :parent_controller,
15
15
  :parent_mailer,
16
- :with_paper_trail,
17
16
  :custom_form_max_size,
18
17
  :with_email_body
19
18
  )
@@ -23,15 +22,7 @@ module RailsAdminCMS
23
22
  end
24
23
 
25
24
  def parent_mailer
26
- @parent_mailer || "::ApplicationMailer".safe_constantize || Struct.new(:mailer) {
27
- def send_email(_form)
28
- mailer
29
- end
30
- }.new(Struct.new(:deliver_now).new(nil))
31
- end
32
-
33
- def with_paper_trail?
34
- @with_paper_trail
25
+ @parent_mailer || "::ApplicationMailer".safe_constantize || BlackHole
35
26
  end
36
27
 
37
28
  def custom_form_max_size
@@ -1,3 +1,3 @@
1
1
  module RailsAdminCMS
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrice Lebel
@@ -392,6 +392,48 @@ dependencies:
392
392
  - - ">="
393
393
  - !ruby/object:Gem::Version
394
394
  version: 1.0.1
395
+ - !ruby/object:Gem::Dependency
396
+ name: paper_trail
397
+ requirement: !ruby/object:Gem::Requirement
398
+ requirements:
399
+ - - "~>"
400
+ - !ruby/object:Gem::Version
401
+ version: 4.0.0
402
+ type: :runtime
403
+ prerelease: false
404
+ version_requirements: !ruby/object:Gem::Requirement
405
+ requirements:
406
+ - - "~>"
407
+ - !ruby/object:Gem::Version
408
+ version: 4.0.0
409
+ - !ruby/object:Gem::Dependency
410
+ name: rails_admin_history_rollback
411
+ requirement: !ruby/object:Gem::Requirement
412
+ requirements:
413
+ - - "~>"
414
+ - !ruby/object:Gem::Version
415
+ version: 0.0.6
416
+ type: :runtime
417
+ prerelease: false
418
+ version_requirements: !ruby/object:Gem::Requirement
419
+ requirements:
420
+ - - "~>"
421
+ - !ruby/object:Gem::Version
422
+ version: 0.0.6
423
+ - !ruby/object:Gem::Dependency
424
+ name: naught
425
+ requirement: !ruby/object:Gem::Requirement
426
+ requirements:
427
+ - - "~>"
428
+ - !ruby/object:Gem::Version
429
+ version: 1.0.0
430
+ type: :runtime
431
+ prerelease: false
432
+ version_requirements: !ruby/object:Gem::Requirement
433
+ requirements:
434
+ - - "~>"
435
+ - !ruby/object:Gem::Version
436
+ version: 1.0.0
395
437
  - !ruby/object:Gem::Dependency
396
438
  name: sqlite3
397
439
  requirement: !ruby/object:Gem::Requirement
@@ -608,13 +650,13 @@ files:
608
650
  - app/controllers/cms/viewables_controller.rb
609
651
  - app/controllers/concerns/cms/editing.rb
610
652
  - app/controllers/concerns/cms/localize.rb
653
+ - app/controllers/concerns/cms/logger.rb
611
654
  - app/helpers/cms/cache_helper.rb
612
655
  - app/helpers/cms/form_helper.rb
613
656
  - app/helpers/cms/javascript_helper.rb
614
657
  - app/helpers/cms/locale_helper.rb
615
658
  - app/helpers/cms/view_helper.rb
616
659
  - app/helpers/cms/viewable_helper.rb
617
- - app/helpers/rails_admin/form_builder_decorator.rb
618
660
  - app/helpers/rails_admin/navigation_helper.rb
619
661
  - app/mailers/cms/forms_mailer.rb
620
662
  - app/models/admin/form/email.rb
@@ -695,6 +737,10 @@ files:
695
737
  - config/locales/routes.fr.yml
696
738
  - config/routes.rb
697
739
  - config/spring.rb
740
+ - db/migrate/20150111082038_create_versions.rb
741
+ - db/migrate/20150111082039_add_object_changes_to_versions.rb
742
+ - db/migrate/20150111082040_create_version_associations.rb
743
+ - db/migrate/20150111082041_add_transaction_id_column_to_versions.rb
698
744
  - db/migrate/20151226023652_create_unique_key.rb
699
745
  - db/migrate/20151226054335_create_viewable_link.rb
700
746
  - db/migrate/20151227064933_create_viewable_text.rb
@@ -709,6 +755,7 @@ files:
709
755
  - db/migrate/20160101141844_create_form_row.rb
710
756
  - db/migrate/20160102010317_create_form_field.rb
711
757
  - db/migrate/20160103120544_create_form_email.rb
758
+ - db/migrate/20160111072418_add_cms_og_tags_settings.rb
712
759
  - lib/active_type/virtual_attributes_decorator.rb
713
760
  - lib/generators/cms/install/USAGE
714
761
  - lib/generators/cms/install/install_generator.rb
@@ -1,11 +0,0 @@
1
- module RailsAdmin
2
- FormBuilder.class_eval do
3
-
4
- private
5
-
6
- def nested_field_association?(field, nested_in)
7
- field.inverse_of.presence && nested_in.presence && field.inverse_of == nested_in.name &&
8
- (@template.instance_variable_get(:@model_config).abstract_model == field.abstract_model || field.name == nested_in.inverse_of)
9
- end
10
- end
11
- end