effective_regions 1.8.6 → 1.10.1

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
  SHA256:
3
- metadata.gz: 9bd907c7a4a74b6fdcc71cc652ed99229b03dadf66e6cb2001dea5b486155f22
4
- data.tar.gz: b4f340a6d6a92c31350be45b047fe97126f8df4dc3542c3377ba8f5c5d975e02
3
+ metadata.gz: 52769c5ca1c6e16d0564381fd6c4049bf2adf1b38baf0a082bbf62b7d589cce0
4
+ data.tar.gz: a2ef266ab5a1af1f976ce2a70ee8c19fb2f2f5e6fc13329dfa81cc7c2dcccdf9
5
5
  SHA512:
6
- metadata.gz: a23081daf17be7266805f782a74be3025f3b1836be1a85f68d9c3f266e484a469bf1d8289ec3c2d6bbcc4f65501e9b5b61ab0573f765b57bbc35fa61d7ddded9
7
- data.tar.gz: a942e28d6fe8dfbc86c2cb4b178e6fb0b988b3a36e30f9efb5a248de1e48f21fee1f7de0df5238a0ecdb4826ddc379b1980fed20c2de27b3b2ab35fa94e48f09
6
+ metadata.gz: 265070e6d1431bf65eadfe85a11d67e4f254d77d65d63aa9c7705aa36db112cb74aa964f621294a0025cef053ffc8025b70b1105ea7dd9ffe7fa3aa4589fd19b
7
+ data.tar.gz: 15268d17dbcb2b84a02f09a89008cc0e36e9040d8dfc33e7e8ab39f2e77aa72c638f75b8324dc118840c81b6879f07322e2883bc1910b836e8222246bbe82fb4
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2014 Code and Effect Inc.
1
+ Copyright 2021 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -252,36 +252,14 @@ You can overide the default behaviour by passing an Exit URL as a parameter:
252
252
  = link_to 'Edit Post Content', effective_regions.edit_path(post_path(@post), :exit => edit_admin_post_path(@post))
253
253
  ```
254
254
 
255
-
256
255
  ## Authorization
257
256
 
258
- All authorization checks are handled via the config.authorization_method found in the effective_regions.rb initializer.
259
-
260
- It is intended for flow through to CanCan, but that is not required.
261
-
262
- The authorization method can be defined as:
263
-
264
- ```ruby
265
- EffectiveRegions.setup do |config|
266
- config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
267
- end
268
- ```
257
+ All authorization checks are handled through the
258
+ [effective_resources](https://github.com/code-and-effect/effective_resources/)
259
+ gem and its `config.authorization_method` found in
260
+ the `config/initializers/effective_resources.rb` initializer.
269
261
 
270
- or as a method:
271
-
272
- ```ruby
273
- EffectiveRegions.setup do |config|
274
- config.authorization_method = :authorize_effective_regions
275
- end
276
- ```
277
-
278
- and then in your application_controller.rb:
279
-
280
- ```ruby
281
- def authorize_effective_regions(action, resource)
282
- can?(action, resource)
283
- end
284
- ```
262
+ ## Permissions
285
263
 
286
264
  There are 3 different levels of permissions to be considered:
287
265
 
@@ -297,19 +275,6 @@ can :update, Effective::Region
297
275
 
298
276
  can :update, ActsAsRegionableObject # This would be your Event, Post, or Page, or whatever.
299
277
 
300
- If the method or proc returns false (user is not authorized) an `Effective::AccessDenied` exception will be raised
301
-
302
- You can rescue from this exception by adding the following to your application_controller.rb
303
-
304
- ```ruby
305
- rescue_from Effective::AccessDenied do |exception|
306
- respond_to do |format|
307
- format.html { render 'static_pages/access_denied', :status => 403 }
308
- format.any { render :text => 'Access Denied', :status => 403 }
309
- end
310
- end
311
- ```
312
-
313
278
  ## Snippets
314
279
 
315
280
  Snippets are intelligent pieces of content that can be dropped into an effective_region through the full-screen editor's 'Insert Snippet' dropdown.
@@ -633,13 +598,6 @@ Code and Effect is the product arm of [AgileStyle](http://www.agilestyle.com/),
633
598
 
634
599
  The test suite for this gem is unfortunately not yet complete.
635
600
 
636
- Run tests by:
637
-
638
- ```ruby
639
- rake spec
640
- ```
641
-
642
-
643
601
  ## Contributing
644
602
 
645
603
  1. Fork it
@@ -648,4 +606,3 @@ rake spec
648
606
  4. Push to the branch (`git push origin my-new-feature`)
649
607
  5. Bonus points for test coverage
650
608
  6. Create new Pull Request
651
-
@@ -0,0 +1,3 @@
1
+ //= link_directory ../javascripts .js
2
+ //= link_directory ../stylesheets .css
3
+ //= link_directory ../images/effective/templates
@@ -3,24 +3,20 @@ module Effective
3
3
  respond_to :html, :json
4
4
  layout false
5
5
 
6
- if respond_to?(:before_action)
7
- skip_before_action :verify_authenticity_token, only: :update
8
- before_action :authenticate_user! if defined?(Devise)
9
- else
10
- skip_before_filter :verify_authenticity_token, only: :update
11
- before_filter :authenticate_user! if defined?(Devise)
12
- end
6
+ skip_before_action :verify_authenticity_token, only: :update
7
+ before_action(:authenticate_user!) if defined?(Devise)
13
8
 
14
- skip_log_page_views quiet: true, only: [:snippet] if defined?(EffectiveLogging)
9
+ skip_log_page_views(quiet: true, only: [:snippet]) if defined?(EffectiveLogging)
15
10
 
16
11
  def edit
17
- EffectiveRegions.authorize!(self, :edit, Effective::Region.new)
12
+ EffectiveResources.authorize!(self, :edit, Effective::Region.new)
18
13
 
19
14
  cookies['effective_regions_editting'] = {:value => params[:exit].presence || request.referrer, :path => '/'}
20
15
 
21
16
  # TODO: turn this into a cookie or something better.
22
17
  uri = URI.parse(Rack::Utils.unescape(request.url.sub('/edit', '')))
23
18
  uri.query = [uri.query, "edit=true"].compact.join('&')
19
+
24
20
  redirect_to uri.to_s
25
21
  end
26
22
 
@@ -37,15 +33,15 @@ module Effective
37
33
  regionable, title = find_regionable(key)
38
34
 
39
35
  if regionable
40
- EffectiveRegions.authorized?(self, :update, regionable) # can I update the regionable object?
36
+ EffectiveResources.authorized?(self, :update, regionable) # can I update the regionable object?
41
37
 
42
38
  region = regionable.regions.find { |region| region.title == title }
43
- region ||= regionable.regions.build(:title => title)
39
+ region ||= regionable.regions.build(title: title)
44
40
 
45
41
  to_save = regionable
46
42
  else
47
- region = Effective::Region.global.where(:title => title).first_or_initialize
48
- EffectiveRegions.authorized?(self, :update, region) # can I update the global region?
43
+ region = Effective::Region.global.where(title: title).first_or_initialize
44
+ EffectiveResources.authorized?(self, :update, region) # can I update the global region?
49
45
 
50
46
  to_save = region
51
47
  end
@@ -68,15 +64,15 @@ module Effective
68
64
 
69
65
  response[:refresh] = true if refresh_page
70
66
 
71
- render :json => response.to_json(), :status => 200
67
+ render(json: response.to_json(), status: 200)
72
68
  return
73
69
  end
74
70
 
75
- render :text => 'error', :status => :unprocessable_entity
71
+ render(text: 'error', status: :unprocessable_entity)
76
72
  end
77
73
 
78
74
  def snippet # This is a GET. CKEDITOR passes us data, we need to render the non-editable content
79
- EffectiveRegions.authorize!(self, :edit, Effective::Region.new)
75
+ EffectiveResources.authorize!(self, :edit, Effective::Region.new)
80
76
 
81
77
  klass = "Effective::Snippets::#{region_params[:name].try(:classify)}".safe_constantize
82
78
 
@@ -153,4 +149,3 @@ module Effective
153
149
 
154
150
  end
155
151
  end
156
-
@@ -2,7 +2,7 @@ module EffectiveRegionsControllerHelper
2
2
  def effectively_editing?
3
3
  @effectively_editing ||= (
4
4
  request.fullpath.include?('edit=true') &&
5
- (EffectiveRegions.authorized?(controller, :edit, Effective::Region.new()) rescue false)
5
+ EffectiveResources.authorized?(controller, :edit, Effective::Region.new)
6
6
  )
7
7
  end
8
8
  alias_method :effectively_editting?, :effectively_editing?
@@ -38,8 +38,6 @@ module EffectiveRegionsHelper
38
38
  end
39
39
  end
40
40
 
41
- private
42
-
43
41
  def ckeditor_region(args, options = {}, &block)
44
42
  obj = args.first
45
43
  title = args.last.to_s.parameterize
@@ -63,7 +61,7 @@ module EffectiveRegionsHelper
63
61
  region = obj.regions.find { |region| region.title == title }
64
62
 
65
63
  if effectively_editing?
66
- can_edit = (EffectiveRegions.authorized?(controller, :update, obj) rescue false)
64
+ can_edit = EffectiveResources.authorized?(controller, :update, obj)
67
65
  opts[:id] = [model_name_from_record_or_class(obj).param_key(), obj.id, title].join('_')
68
66
  end
69
67
  else # This is a global region
@@ -71,7 +69,7 @@ module EffectiveRegionsHelper
71
69
  region = regions.find { |region| region.title == title } || Effective::Region.new(:title => title)
72
70
 
73
71
  if effectively_editing?
74
- can_edit = (EffectiveRegions.authorized?(controller, :update, region) rescue false)
72
+ can_edit = EffectiveResources.authorized?(controller, :update, region)
75
73
  opts[:id] = title.to_s.parameterize
76
74
  end
77
75
  end
@@ -112,6 +110,4 @@ module EffectiveRegionsHelper
112
110
  end.html_safe
113
111
  end
114
112
 
115
-
116
-
117
113
  end
@@ -9,7 +9,7 @@ module ActsAsRegionable
9
9
  end
10
10
 
11
11
  included do
12
- has_many :regions, :as => :regionable, :class_name => 'Effective::Region', :dependent => :delete_all, :autosave => true
12
+ has_many :regions, as: :regionable, class_name: 'Effective::Region', dependent: :delete_all, autosave: true
13
13
  end
14
14
 
15
15
  module ClassMethods
@@ -36,4 +36,3 @@ module ActsAsRegionable
36
36
  end
37
37
 
38
38
  end
39
-
@@ -11,15 +11,12 @@ module Effective
11
11
  # The instance ones will have just one file
12
12
  has_one_attached :file
13
13
 
14
- # Attributes
15
- # global :boolean
14
+ effective_resource do
15
+ global :boolean
16
+ end
16
17
 
17
18
  def self.global
18
19
  CkAsset.where(global: true).first || CkAsset.create!(global: true)
19
20
  end
20
21
  end
21
22
  end
22
-
23
-
24
-
25
-
@@ -4,19 +4,20 @@ module Effective
4
4
 
5
5
  belongs_to :regionable, polymorphic: true, optional: true
6
6
 
7
- # structure do
8
- # title :string
9
- # content :text
10
- # snippets :text
11
- # timestamps
12
- # end
7
+ effective_resource do
8
+ title :string
9
+ content :text
10
+ snippets :text
11
+
12
+ timestamps
13
+ end
13
14
 
14
15
  serialize :snippets, HashWithIndifferentAccess
15
16
 
16
17
  scope :global, -> { where("#{EffectiveRegions.regions_table_name}.regionable_type IS NULL").where("#{EffectiveRegions.regions_table_name}.regionable_id IS NULL") }
17
18
  scope :with_snippets, -> { where("#{EffectiveRegions.regions_table_name}.snippets ILIKE ?", '%snippet_%') }
18
19
 
19
- validates_presence_of :title
20
+ validates :title, presence: true
20
21
 
21
22
  def snippets
22
23
  self[:snippets] || HashWithIndifferentAccess.new()
@@ -41,7 +42,3 @@ module Effective
41
42
 
42
43
  end
43
44
  end
44
-
45
-
46
-
47
-
@@ -0,0 +1,37 @@
1
+ if defined?(EffectiveAssets)
2
+ module Effective
3
+ module Snippets
4
+ class EffectiveAsset < Snippet
5
+ # attr_accessor :asset_id #, Integer
6
+ # attr_accessor :html_class #, String
7
+ # attr_accessor :link_title #, String
8
+ # attr_accessor :private_url # , Boolean
9
+
10
+ def snippet_attributes
11
+ super + [:asset_id, :html_class, :link_title, :private_url]
12
+ end
13
+
14
+ def asset
15
+ @asset ||= (Effective::Asset.where(:id => asset_id).first if asset_id)
16
+ end
17
+
18
+ def snippet_tag
19
+ :span
20
+ end
21
+
22
+ def private_url
23
+ super || aws_private?
24
+ end
25
+
26
+ def is_private?
27
+ [true, 'true', '1'].include?(private_url)
28
+ end
29
+
30
+ def aws_private?
31
+ (asset.try(:aws_acl) == EffectiveAssets::AWS_PRIVATE)
32
+ end
33
+
34
+ end
35
+ end
36
+ end
37
+ end
@@ -2,29 +2,6 @@ EffectiveRegions.setup do |config|
2
2
  config.regions_table_name = :regions
3
3
  config.ck_assets_table_name = :ck_assets
4
4
 
5
- # Authorization Method
6
- #
7
- # This method is called by all controller actions with the appropriate action and resource
8
- # If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
9
- #
10
- # Use via Proc (and with CanCan):
11
- # config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
12
- #
13
- # Use via custom method:
14
- # config.authorization_method = :my_authorization_method
15
- #
16
- # And then in your application_controller.rb:
17
- #
18
- # def my_authorization_method(action, resource)
19
- # current_user.is?(:admin)
20
- # end
21
- #
22
- # Or disable the check completely:
23
- # config.authorization_method = false
24
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) } # CanCanCan
25
-
26
-
27
-
28
5
  # Before Region Save Method
29
6
  #
30
7
  # This method is called when a User clicks the 'Save' button in the full screen editor.
@@ -6,15 +6,21 @@ module EffectiveRegions
6
6
 
7
7
  # Include Helpers to base application
8
8
  initializer 'effective_regions.action_controller' do |app|
9
- ActiveSupport.on_load :action_controller do
10
- ActionController::Base.send(:include, ::EffectiveRegionsControllerHelper)
9
+ app.config.to_prepare do
10
+ ActiveSupport.on_load :action_controller_base do
11
+ helper EffectiveRegionsHelper
12
+
13
+ ActionController::Base.send(:include, ::EffectiveRegionsControllerHelper)
14
+ end
11
15
  end
12
16
  end
13
17
 
14
18
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
15
19
  initializer 'effective_regions.active_record' do |app|
16
- ActiveSupport.on_load :active_record do
17
- ActiveRecord::Base.extend(ActsAsRegionable::Base)
20
+ app.config.to_prepare do
21
+ ActiveSupport.on_load :active_record do
22
+ ActiveRecord::Base.extend(ActsAsRegionable::Base)
23
+ end
18
24
  end
19
25
  end
20
26
 
@@ -24,7 +30,7 @@ module EffectiveRegions
24
30
  end
25
31
 
26
32
  initializer "effective_regions.append_precompiled_assets" do |app|
27
- Rails.application.config.assets.precompile += ['ck_assets.js', 'ck_assets.css', 'drop_cap.css']
33
+ app.config.assets.precompile += ['effective_regions_manifest.js', 'ck_assets.js', 'ck_assets.css', 'drop_cap.css']
28
34
  end
29
35
 
30
36
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveRegions
2
- VERSION = '1.8.6'.freeze
2
+ VERSION = '1.10.1'.freeze
3
3
  end
@@ -1,34 +1,15 @@
1
+ require 'effective_resources'
1
2
  require 'effective_ckeditor'
2
3
  require 'effective_regions/engine'
3
4
  require 'effective_regions/version'
4
5
 
5
6
  module EffectiveRegions
6
- mattr_accessor :regions_table_name
7
- mattr_accessor :ck_assets_table_name
8
7
 
9
- mattr_accessor :authorization_method
10
- mattr_accessor :before_save_method
11
-
12
- def self.setup
13
- yield self
8
+ def self.config_keys
9
+ [:regions_table_name, :ck_assets_table_name, :before_save_method]
14
10
  end
15
11
 
16
- def self.authorized?(controller, action, resource)
17
- @_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
18
-
19
- return !!authorization_method unless authorization_method.respond_to?(:call)
20
- controller = controller.controller if controller.respond_to?(:controller)
21
-
22
- begin
23
- !!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
24
- rescue *@_exceptions
25
- false
26
- end
27
- end
28
-
29
- def self.authorize!(controller, action, resource)
30
- raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
31
- end
12
+ include EffectiveGem
32
13
 
33
14
  # Returns a Snippet.new() for every class in the /app/effective/snippets/* directory
34
15
  def self.snippets
@@ -21,6 +21,7 @@ module EffectiveRegions
21
21
 
22
22
  def create_migration_file
23
23
  @regions_table_name = ':' + EffectiveRegions.regions_table_name.to_s
24
+ @ck_assets_table_name = : + EffectiveRegions.ck_assets_table_name.to_s
24
25
  migration_template ('../' * 3) + 'db/migrate/01_create_effective_regions.rb.erb', 'db/migrate/create_effective_regions.rb'
25
26
  end
26
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_regions
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.6
4
+ version: 1.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-17 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: effective_resources
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: effective_ckeditor
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sassc
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  description: Create editable content regions within your existing, ordinary ActionView::Base
42
70
  views, and update content with an actually-good full-screen WYSIWYG editor.
43
71
  email:
@@ -49,6 +77,7 @@ files:
49
77
  - MIT-LICENSE
50
78
  - README.md
51
79
  - Rakefile
80
+ - app/assets/config/effective_regions_manifest.js
52
81
  - app/assets/images/effective/templates/image_and_title.png
53
82
  - app/assets/javascripts/ck_assets.js.coffee
54
83
  - app/assets/javascripts/effective/snippets/current_date_time.js.coffee
@@ -61,12 +90,12 @@ files:
61
90
  - app/helpers/effective_regions_controller_helper.rb
62
91
  - app/helpers/effective_regions_helper.rb
63
92
  - app/models/concerns/acts_as_regionable.rb
64
- - app/models/effective/access_denied.rb
65
93
  - app/models/effective/ck_asset.rb
66
94
  - app/models/effective/region.rb
67
95
  - app/models/effective/snippets/current_date_time.rb
68
96
  - app/models/effective/snippets/current_user_info.rb
69
97
  - app/models/effective/snippets/drop_cap.rb
98
+ - app/models/effective/snippets/effective_asset.rb
70
99
  - app/models/effective/snippets/snippet.rb
71
100
  - app/models/effective/templates/image_and_title.rb
72
101
  - app/models/effective/templates/template.rb
@@ -93,7 +122,7 @@ homepage: https://github.com/code-and-effect/effective_regions
93
122
  licenses:
94
123
  - MIT
95
124
  metadata: {}
96
- post_install_message:
125
+ post_install_message:
97
126
  rdoc_options: []
98
127
  require_paths:
99
128
  - lib
@@ -108,8 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
137
  - !ruby/object:Gem::Version
109
138
  version: '0'
110
139
  requirements: []
111
- rubygems_version: 3.0.3
112
- signing_key:
140
+ rubygems_version: 3.1.2
141
+ signing_key:
113
142
  specification_version: 4
114
143
  summary: Create editable content regions within your existing, ordinary ActionView::Base
115
144
  views, and update content with an actually-good full-screen WYSIWYG editor.
@@ -1,17 +0,0 @@
1
- unless defined?(Effective::AccessDenied)
2
- module Effective
3
- class AccessDenied < StandardError
4
- attr_reader :action, :subject
5
-
6
- def initialize(message = nil, action = nil, subject = nil)
7
- @message = message
8
- @action = action
9
- @subject = subject
10
- end
11
-
12
- def to_s
13
- @message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
14
- end
15
- end
16
- end
17
- end