effective_regions 1.8.6 → 1.9.0

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: 2ba94f8c8d5b5d1f44e5c6becb9e8243a5f01b30c1926b5e8eff93caeec1863e
4
+ data.tar.gz: 4c76c3056698a2152a5bf1ebeeaa6de93a9ed2dd81e8918e92361a0c7a01ded2
5
5
  SHA512:
6
- metadata.gz: a23081daf17be7266805f782a74be3025f3b1836be1a85f68d9c3f266e484a469bf1d8289ec3c2d6bbcc4f65501e9b5b61ab0573f765b57bbc35fa61d7ddded9
7
- data.tar.gz: a942e28d6fe8dfbc86c2cb4b178e6fb0b988b3a36e30f9efb5a248de1e48f21fee1f7de0df5238a0ecdb4826ddc379b1980fed20c2de27b3b2ab35fa94e48f09
6
+ metadata.gz: cf35cbc0a65e91dda1851adb09c08689fa904025ef99aa4a50ff1633dc7fca1b19b9a3b359ce9bbeaab07333c8b26f5a63d22599a3585e54ab37fa8c127ffe39
7
+ data.tar.gz: 3b6db2cde4926b5563b23ed7e96a7b2e6e91236d5d46ee6fee21fd575b3caae193011c90a0008e9d3a3c9999cae48a261ca9e191788218a88558b035a6629825
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
-
@@ -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?
@@ -63,7 +63,7 @@ module EffectiveRegionsHelper
63
63
  region = obj.regions.find { |region| region.title == title }
64
64
 
65
65
  if effectively_editing?
66
- can_edit = (EffectiveRegions.authorized?(controller, :update, obj) rescue false)
66
+ can_edit = EffectiveResources.authorized?(controller, :update, obj)
67
67
  opts[:id] = [model_name_from_record_or_class(obj).param_key(), obj.id, title].join('_')
68
68
  end
69
69
  else # This is a global region
@@ -71,7 +71,7 @@ module EffectiveRegionsHelper
71
71
  region = regions.find { |region| region.title == title } || Effective::Region.new(:title => title)
72
72
 
73
73
  if effectively_editing?
74
- can_edit = (EffectiveRegions.authorized?(controller, :update, region) rescue false)
74
+ can_edit = EffectiveResources.authorized?(controller, :update, region)
75
75
  opts[:id] = title.to_s.parameterize
76
76
  end
77
77
  end
@@ -112,6 +112,4 @@ module EffectiveRegionsHelper
112
112
  end.html_safe
113
113
  end
114
114
 
115
-
116
-
117
115
  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
-
@@ -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.
@@ -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
@@ -1,3 +1,3 @@
1
1
  module EffectiveRegions
2
- VERSION = '1.8.6'.freeze
2
+ VERSION = '1.9.0'.freeze
3
3
  end
@@ -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.9.0
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: 2021-02-18 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
@@ -61,7 +75,6 @@ files:
61
75
  - app/helpers/effective_regions_controller_helper.rb
62
76
  - app/helpers/effective_regions_helper.rb
63
77
  - app/models/concerns/acts_as_regionable.rb
64
- - app/models/effective/access_denied.rb
65
78
  - app/models/effective/ck_asset.rb
66
79
  - app/models/effective/region.rb
67
80
  - app/models/effective/snippets/current_date_time.rb
@@ -93,7 +106,7 @@ homepage: https://github.com/code-and-effect/effective_regions
93
106
  licenses:
94
107
  - MIT
95
108
  metadata: {}
96
- post_install_message:
109
+ post_install_message:
97
110
  rdoc_options: []
98
111
  require_paths:
99
112
  - lib
@@ -108,8 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
121
  - !ruby/object:Gem::Version
109
122
  version: '0'
110
123
  requirements: []
111
- rubygems_version: 3.0.3
112
- signing_key:
124
+ rubygems_version: 3.1.2
125
+ signing_key:
113
126
  specification_version: 4
114
127
  summary: Create editable content regions within your existing, ordinary ActionView::Base
115
128
  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