effective_regions 1.8.2 → 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
- SHA1:
3
- metadata.gz: 617bff8384ef4f4788b6bc347778a324506af96d
4
- data.tar.gz: 8cd38c383042bd27b62126188a90d9b38f23ad4c
2
+ SHA256:
3
+ metadata.gz: 2ba94f8c8d5b5d1f44e5c6becb9e8243a5f01b30c1926b5e8eff93caeec1863e
4
+ data.tar.gz: 4c76c3056698a2152a5bf1ebeeaa6de93a9ed2dd81e8918e92361a0c7a01ded2
5
5
  SHA512:
6
- metadata.gz: 63dfae82dc9c1390c7d99b5653a4569687518f45f3fcad9b3df70059c06e1f539efd21dafae9c6afdbe005c7423dde19a8d88cd347bc21bb120129be46ab6c87
7
- data.tar.gz: c9568095652b6215bdbc0bc92c3a87134da95ab798260c8fb711694fbe85687839e3a55c512e9e012c42cc400f935045e95a14b49fbed3091bb6b054f1699ca0
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
-
@@ -0,0 +1,25 @@
1
+ CKEDITOR.dialog.add 'drop_cap', (editor) -> # Must match the class name of the snippet
2
+ title: 'A drop cap',
3
+ minWidth: 200,
4
+ minHeight: 100,
5
+ contents: [
6
+ {
7
+ id: 'drop_cap_id', # Just an html id, doesn't really matter what is here
8
+ elements: [
9
+ {
10
+ id: 'letter'
11
+ type: 'text',
12
+ label: 'Letter (required)',
13
+ setup: (widget) -> this.setValue(widget.data.letter)
14
+ commit: (widget) -> widget.setData('letter', this.getValue())
15
+ },
16
+ {
17
+ id: 'html_class'
18
+ type: 'text',
19
+ label: 'Additional html classes (optional)',
20
+ setup: (widget) -> this.setValue(widget.data.html_class)
21
+ commit: (widget) -> widget.setData('html_class', this.getValue())
22
+ }
23
+ ]
24
+ }
25
+ ]
@@ -0,0 +1,7 @@
1
+ .dropcap {
2
+ float: left;
3
+ position: relative;
4
+ font-size: larger;
5
+ font-weight: bold;
6
+ margin-right: 0.5rem;
7
+ }
@@ -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?
@@ -28,8 +28,10 @@ module EffectiveRegionsHelper
28
28
  }
29
29
 
30
30
  if defined?(EffectivePages) && defined?(EffectiveRoles)
31
- payload[:roles] = EffectiveRoles.roles_collection(Effective::Menu.new(), current_user)
32
- payload[:pages] = ([['', '']] + Effective::Page.order(:title).map { |page| [page.title, page.id] })
31
+ if(menu = Effective::Menu.new()).respond_to?(:is_role_restricted?)
32
+ payload[:roles] = EffectiveRoles.roles_collection(menu, current_user)
33
+ payload[:pages] = ([['', '']] + Effective::Page.order(:title).map { |page| [page.title, page.id] })
34
+ end
33
35
  end
34
36
 
35
37
  render(:partial => 'effective_regions/include_tags_javascript', :locals => {:payload => payload})
@@ -61,7 +63,7 @@ module EffectiveRegionsHelper
61
63
  region = obj.regions.find { |region| region.title == title }
62
64
 
63
65
  if effectively_editing?
64
- can_edit = (EffectiveRegions.authorized?(controller, :update, obj) rescue false)
66
+ can_edit = EffectiveResources.authorized?(controller, :update, obj)
65
67
  opts[:id] = [model_name_from_record_or_class(obj).param_key(), obj.id, title].join('_')
66
68
  end
67
69
  else # This is a global region
@@ -69,7 +71,7 @@ module EffectiveRegionsHelper
69
71
  region = regions.find { |region| region.title == title } || Effective::Region.new(:title => title)
70
72
 
71
73
  if effectively_editing?
72
- can_edit = (EffectiveRegions.authorized?(controller, :update, region) rescue false)
74
+ can_edit = EffectiveResources.authorized?(controller, :update, region)
73
75
  opts[:id] = title.to_s.parameterize
74
76
  end
75
77
  end
@@ -110,6 +112,4 @@ module EffectiveRegionsHelper
110
112
  end.html_safe
111
113
  end
112
114
 
113
-
114
-
115
115
  end
@@ -1,7 +1,7 @@
1
1
  module ActsAsRegionable
2
2
  extend ActiveSupport::Concern
3
3
 
4
- module ActiveRecord
4
+ module Base
5
5
  def acts_as_regionable(*options)
6
6
  @acts_as_regionable_opts = options || []
7
7
  include ::ActsAsRegionable
@@ -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
-
@@ -2,21 +2,22 @@ module Effective
2
2
  class Region < ActiveRecord::Base
3
3
  self.table_name = EffectiveRegions.regions_table_name.to_s
4
4
 
5
- belongs_to :regionable, :polymorphic => true
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,11 @@
1
+ module Effective
2
+ module Snippets
3
+ class DropCap < Snippet
4
+
5
+ def snippet_attributes
6
+ super + [:letter, :html_class]
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ .dropcap{class: drop_cap.html_class.presence}
2
+ %span= drop_cap.letter
@@ -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
@@ -14,7 +14,7 @@ module EffectiveRegions
14
14
  # Include acts_as_addressable concern and allow any ActiveRecord object to call it
15
15
  initializer 'effective_regions.active_record' do |app|
16
16
  ActiveSupport.on_load :active_record do
17
- ActiveRecord::Base.extend(ActsAsRegionable::ActiveRecord)
17
+ ActiveRecord::Base.extend(ActsAsRegionable::Base)
18
18
  end
19
19
  end
20
20
 
@@ -24,7 +24,7 @@ module EffectiveRegions
24
24
  end
25
25
 
26
26
  initializer "effective_regions.append_precompiled_assets" do |app|
27
- Rails.application.config.assets.precompile += ['ck_assets.js', 'ck_assets.css']
27
+ Rails.application.config.assets.precompile += ['ck_assets.js', 'ck_assets.css', 'drop_cap.css']
28
28
  end
29
29
 
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveRegions
2
- VERSION = '1.8.2'.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.2
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: 2019-04-25 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
@@ -53,17 +67,19 @@ files:
53
67
  - app/assets/javascripts/ck_assets.js.coffee
54
68
  - app/assets/javascripts/effective/snippets/current_date_time.js.coffee
55
69
  - app/assets/javascripts/effective/snippets/current_user_info.js.coffee
70
+ - app/assets/javascripts/effective/snippets/drop_cap.js.coffee
56
71
  - app/assets/stylesheets/ck_assets.scss
72
+ - app/assets/stylesheets/drop_cap.scss
57
73
  - app/controllers/effective/ck_assets_controller.rb
58
74
  - app/controllers/effective/regions_controller.rb
59
75
  - app/helpers/effective_regions_controller_helper.rb
60
76
  - app/helpers/effective_regions_helper.rb
61
77
  - app/models/concerns/acts_as_regionable.rb
62
- - app/models/effective/access_denied.rb
63
78
  - app/models/effective/ck_asset.rb
64
79
  - app/models/effective/region.rb
65
80
  - app/models/effective/snippets/current_date_time.rb
66
81
  - app/models/effective/snippets/current_user_info.rb
82
+ - app/models/effective/snippets/drop_cap.rb
67
83
  - app/models/effective/snippets/snippet.rb
68
84
  - app/models/effective/templates/image_and_title.rb
69
85
  - app/models/effective/templates/template.rb
@@ -73,6 +89,7 @@ files:
73
89
  - app/views/effective/ck_assets/index.html.haml
74
90
  - app/views/effective/snippets/_current_date_time.html.haml
75
91
  - app/views/effective/snippets/_current_user_info.html.haml
92
+ - app/views/effective/snippets/_drop_cap.html.haml
76
93
  - app/views/effective/templates/_image_and_title.html.haml
77
94
  - app/views/effective/templates/_three_column.html.haml
78
95
  - app/views/effective/templates/_two_column.html.haml
@@ -89,7 +106,7 @@ homepage: https://github.com/code-and-effect/effective_regions
89
106
  licenses:
90
107
  - MIT
91
108
  metadata: {}
92
- post_install_message:
109
+ post_install_message:
93
110
  rdoc_options: []
94
111
  require_paths:
95
112
  - lib
@@ -104,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
121
  - !ruby/object:Gem::Version
105
122
  version: '0'
106
123
  requirements: []
107
- rubyforge_project:
108
- rubygems_version: 2.4.5.1
109
- signing_key:
124
+ rubygems_version: 3.1.2
125
+ signing_key:
110
126
  specification_version: 4
111
127
  summary: Create editable content regions within your existing, ordinary ActionView::Base
112
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