effective_pages 1.0.17 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06060a89741e53a47c0cca1d55400a53f4d5e105
4
- data.tar.gz: fe0f7a48af172d1460b58afeaa9226f988f43477
3
+ metadata.gz: 922310db05a57eef7ef291c30097716e2d81fca8
4
+ data.tar.gz: c923e43f89d461bf5a2a13cd7051be76a45b748d
5
5
  SHA512:
6
- metadata.gz: cf7922ca318903f343dce0468e45d14a78dd428d7caf6659633d38fed88dfc1ae3f4589d958754731bbf422e70223b8a401ec973e08e4f409084990dac37d1c5
7
- data.tar.gz: 4b3214cf3574c17e5081a698ca5c84b0dca5415b5790904e968b3b761953aef95e3f0cd0a6ef2e30f1deac74516bc07c8401131902d7f612d53aec2559c9981b
6
+ metadata.gz: be05a9ddedd4958b5be1f04266f27aa9097d8f079caa5048c8ba31c4bdf4b4769457bcb7e85481dbb39b3d043268c11298104b15b685f1b69b982eb8e15ed06e
7
+ data.tar.gz: 251b3d2b50834499f591137cb65db4bf7de386424d26e9a482e753d8d2cb355217e72c1e3fee931a3bcca78cb4b79576123b0665861faae2d79f4a1c9209290a
data/README.md CHANGED
@@ -413,9 +413,6 @@ end
413
413
 
414
414
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
415
415
 
416
- Code and Effect is the product arm of [AgileStyle](http://www.agilestyle.com/), an Edmonton-based shop that specializes in building custom web applications with Ruby on Rails.
417
-
418
-
419
416
  ## Testing
420
417
 
421
418
  Run tests by:
@@ -10,24 +10,21 @@ module Admin
10
10
  @datatable = Effective::Datatables::Menus.new() if defined?(EffectiveDatatables)
11
11
  @page_title = 'Menus'
12
12
 
13
- EffectivePages.authorized?(self, :admin, :effective_pages)
14
- EffectivePages.authorized?(self, :index, Effective::Menu)
13
+ authorize_effective_menus!
15
14
  end
16
15
 
17
16
  def new
18
17
  @menu = Effective::Menu.new()
19
18
  @page_title = 'New Menu'
20
19
 
21
- EffectivePages.authorized?(self, :admin, :effective_pages)
22
- EffectivePages.authorized?(self, :new, @menu)
20
+ authorize_effective_menus!
23
21
  end
24
22
 
25
23
  def create
26
24
  @menu = Effective::Menu.new(menu_params)
27
25
  @page_title = 'New Menu'
28
26
 
29
- EffectivePages.authorized?(self, :admin, :effective_pages)
30
- EffectivePages.authorized?(self, :create, @menu)
27
+ authorize_effective_menus!
31
28
 
32
29
  if @menu.save
33
30
  flash[:success] = 'Successfully created menu'
@@ -42,16 +39,14 @@ module Admin
42
39
  @menu = Effective::Menu.find(params[:id])
43
40
  @page_title = 'Edit Menu'
44
41
 
45
- EffectivePages.authorized?(self, :admin, :effective_pages)
46
- EffectivePages.authorized?(self, :edit, @menu)
42
+ authorize_effective_menus!
47
43
  end
48
44
 
49
45
  def update
50
46
  @menu = Effective::Menu.find(params[:id])
51
47
  @page_title = 'Edit Menu'
52
48
 
53
- EffectivePages.authorized?(self, :admin, :effective_pages)
54
- EffectivePages.authorized?(self, :update, @menu)
49
+ authorize_effective_menus!
55
50
 
56
51
  if @menu.update_attributes(menu_params)
57
52
  flash[:success] = 'Successfully updated menu'
@@ -65,8 +60,7 @@ module Admin
65
60
  def destroy
66
61
  @menu = Effective::Menu.find(params[:id])
67
62
 
68
- EffectivePages.authorized?(self, :admin, :effective_pages)
69
- EffectivePages.authorized?(self, :destroy, @menu)
63
+ authorize_effective_menus!
70
64
 
71
65
  if @menu.destroy
72
66
  flash[:success] = 'Successfully deleted menu'
@@ -79,6 +73,11 @@ module Admin
79
73
 
80
74
  private
81
75
 
76
+ def authorize_effective_menus!
77
+ EffectivePages.authorized?(self, :admin, :effective_pages)
78
+ EffectivePages.authorized?(self, action_name.to_sym, @menu || Effective::Menu)
79
+ end
80
+
82
81
  def menu_params
83
82
  params.require(:effective_menu).permit(:title)
84
83
  end
@@ -5,28 +5,24 @@ module Admin
5
5
  layout (EffectivePages.layout.kind_of?(Hash) ? EffectivePages.layout[:admin] : EffectivePages.layout)
6
6
 
7
7
  def index
8
+ @datatable = Effective::Datatables::Pages.new() if defined?(EffectiveDatatables)
8
9
  @page_title = 'Pages'
9
10
 
10
- EffectivePages.authorized?(self, :admin, :effective_pages)
11
- EffectivePages.authorized?(self, :index, Effective::Page)
12
-
13
- @datatable = Effective::Datatables::Pages.new() if defined?(EffectiveDatatables)
11
+ authorize_effective_pages!
14
12
  end
15
13
 
16
14
  def new
17
15
  @page = Effective::Page.new()
18
16
  @page_title = 'New Page'
19
17
 
20
- EffectivePages.authorized?(self, :admin, :effective_pages)
21
- EffectivePages.authorized?(self, :new, @page)
18
+ authorize_effective_pages!
22
19
  end
23
20
 
24
21
  def create
25
22
  @page = Effective::Page.new(page_params)
26
23
  @page_title = 'New Page'
27
24
 
28
- EffectivePages.authorized?(self, :admin, :effective_pages)
29
- EffectivePages.authorized?(self, :create, @page)
25
+ authorize_effective_pages!
30
26
 
31
27
  if @page.save
32
28
  if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
@@ -47,16 +43,14 @@ module Admin
47
43
  @page = Effective::Page.find(params[:id])
48
44
  @page_title = 'Edit Page'
49
45
 
50
- EffectivePages.authorized?(self, :admin, :effective_pages)
51
- EffectivePages.authorized?(self, :edit, @page)
46
+ authorize_effective_pages!
52
47
  end
53
48
 
54
49
  def update
55
50
  @page = Effective::Page.find(params[:id])
56
51
  @page_title = 'Edit Page'
57
52
 
58
- EffectivePages.authorized?(self, :admin, :effective_pages)
59
- EffectivePages.authorized?(self, :update, @page)
53
+ authorize_effective_pages!
60
54
 
61
55
  if @page.update_attributes(page_params)
62
56
  if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
@@ -76,8 +70,7 @@ module Admin
76
70
  def destroy
77
71
  @page = Effective::Page.find(params[:id])
78
72
 
79
- EffectivePages.authorized?(self, :admin, :effective_pages)
80
- EffectivePages.authorized?(self, :destroy, @page)
73
+ authorize_effective_pages!
81
74
 
82
75
  if @page.destroy
83
76
  flash[:success] = 'Successfully deleted page'
@@ -90,6 +83,11 @@ module Admin
90
83
 
91
84
  private
92
85
 
86
+ def authorize_effective_pages!
87
+ EffectivePages.authorized?(self, :admin, :effective_pages)
88
+ EffectivePages.authorized?(self, action_name.to_sym, @page|| Effective::Page)
89
+ end
90
+
93
91
  def page_params
94
92
  params.require(:effective_page).permit(EffectivePages.permitted_params)
95
93
  end
@@ -4,7 +4,3 @@
4
4
  - if defined?(EffectiveRegions)
5
5
  = link_to (effective_regions.edit_path('/')), title: 'Edit Content', 'data-no-turbolink': true, target: '_blank' do
6
6
  %span.glyphicon.glyphicon-edit
7
-
8
- = link_to effective_pages.admin_menu_path(menu), title: 'Delete', data: { method: :delete, confirm: 'Are you sure? This menu will be made unavailable.' } do
9
- %span.glyphicon.glyphicon-trash
10
-
@@ -2,7 +2,7 @@
2
2
  = f.input :title, :hint => "Give this menu a title"
3
3
 
4
4
  - if defined?(EffectiveRoles)
5
- %h3 Menu Item Visibility
5
+ %h2 Menu Item Visibility
6
6
 
7
7
  %table.table
8
8
  %thead
@@ -1,2 +1,3 @@
1
- %h2= @page_title
2
- = render :partial => 'form', :as => :menu, :object => @menu
1
+ %h1.effective-admin-heading= @page_title
2
+
3
+ = render partial: 'form', as: :menu, object: @menu
@@ -1,9 +1,3 @@
1
- %h2= @page_title
1
+ %h1.effective-admin-heading= @page_title
2
2
 
3
- %p.text-right= link_to 'New Menu', effective_pages.new_admin_menu_path, :class => 'btn btn-primary'
4
-
5
- = render_datatable @datatable do
6
- %p There are no menus
7
-
8
- - if @datatable.present?
9
- %p.text-right= link_to 'New Menu', effective_pages.new_admin_menu_path, :class => 'btn btn-primary'
3
+ = render_datatable(@datatable)
@@ -1,2 +1,3 @@
1
- %h2= @page_title
2
- = render :partial => 'form', :as => :menu, :object => @menu
1
+ %h1.effective-admin-heading= @page_title
2
+
3
+ = render partial: 'form', as: :menu, object: @menu
@@ -1,2 +1,3 @@
1
- %h2= @page_title
2
- = render :partial => 'form', :as => :page, :object => @page
1
+ %h1.effective-admin-heading= @page_title
2
+
3
+ = render partial: 'form', as: :page, object: @page
@@ -1,9 +1,6 @@
1
- %h2= @page_title
1
+ %h1.effective-admin-heading= @page_title
2
2
 
3
- %p.text-right= link_to 'New Page', effective_pages.new_admin_page_path, :class => 'btn btn-primary'
3
+ %p.text-right.effective-admin-actions
4
+ = link_to 'New Page', effective_pages.new_admin_page_path, :class => 'btn btn-primary'
4
5
 
5
- = render_datatable @datatable do
6
- %p There are no pages
7
-
8
- - if @datatable.present?
9
- %p.text-right= link_to 'New Page', effective_pages.new_admin_page_path, :class => 'btn btn-primary'
6
+ = render_datatable(@datatable)
@@ -1,2 +1,3 @@
1
- %h2= @page_title
2
- = render :partial => 'form', :as => :page, :object => @page
1
+ %h1.effective-admin-heading= @page_title
2
+
3
+ = render partial: 'form', as: :page, object: @page
@@ -1,5 +1,3 @@
1
- # EffectivePages Rails Engine
2
-
3
1
  EffectivePages.setup do |config|
4
2
  config.pages_table_name = :pages
5
3
  config.menus_table_name = :menus
@@ -39,9 +37,27 @@ EffectivePages.setup do |config|
39
37
  #config.acts_as_asset_box = header_image: true
40
38
  #config.acts_as_asset_box = { header_image: true, body_images: 1..4 }
41
39
 
42
- # Use CanCan: authorize!(action, resource)
40
+ # Authorization Method
41
+ #
42
+ # This method is called by all controller actions with the appropriate action and resource
43
+ # If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
44
+ #
45
+ # Use via Proc (and with CanCan):
46
+ # config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
47
+ #
48
+ # Use via custom method:
49
+ # config.authorization_method = :my_authorization_method
50
+ #
51
+ # And then in your application_controller.rb:
52
+ #
53
+ # def my_authorization_method(action, resource)
54
+ # current_user.is?(:admin)
55
+ # end
56
+ #
57
+ # Or disable the check completely:
58
+ # config.authorization_method = false
59
+ config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) && resource.roles_permit?(current_user) } # CanCanCan
43
60
  # Use effective_roles: resource.roles_permit?(current_user)
44
- config.authorization_method = Proc.new { |controller, action, resource| true }
45
61
 
46
62
  # Layout Settings
47
63
  # Configure the Layout per controller, or all at once
@@ -13,7 +13,7 @@ module EffectivePages
13
13
  # Set up our default configuration options.
14
14
  initializer "effective_pages.defaults", before: :load_config_initializers do |app|
15
15
  # Set up our defaults, as per our initializer template
16
- eval File.read("#{config.root}/lib/generators/templates/effective_pages.rb")
16
+ eval File.read("#{config.root}/config/effective_pages.rb")
17
17
  end
18
18
 
19
19
  initializer 'effective_pages.effective_assets_validation', after: :load_config_initializers do
@@ -1,3 +1,3 @@
1
1
  module EffectivePages
2
- VERSION = '1.0.17'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -3,9 +3,9 @@ module EffectivePages
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  include Rails::Generators::Migration
5
5
 
6
- desc "Creates an EffectivePages initializer in your application."
6
+ desc 'Creates an EffectivePages initializer in your application.'
7
7
 
8
- source_root File.expand_path("../../templates", __FILE__)
8
+ source_root File.expand_path('../../templates', __FILE__)
9
9
 
10
10
  def self.next_migration_number(dirname)
11
11
  if not ActiveRecord::Base.timestamped_migrations
@@ -16,7 +16,7 @@ module EffectivePages
16
16
  end
17
17
 
18
18
  def copy_initializer
19
- template "effective_pages.rb", "config/initializers/effective_pages.rb"
19
+ template ('../' * 3) + 'config/effective_pages.rb', 'config/initializers/effective_pages.rb'
20
20
  end
21
21
 
22
22
  def create_migration_file
@@ -24,7 +24,7 @@ module EffectivePages
24
24
  @menus_table_name = ':' + EffectivePages.menus_table_name.to_s
25
25
  @menu_items_table_name = ':' + EffectivePages.menu_items_table_name.to_s
26
26
 
27
- migration_template '../../../db/migrate/01_create_effective_pages.rb.erb', 'db/migrate/create_effective_pages.rb'
27
+ migration_template ('../' * 3) + 'db/migrate/01_create_effective_pages.rb.erb', 'db/migrate/create_effective_pages.rb'
28
28
  end
29
29
 
30
30
  def copy_example_page
@@ -32,7 +32,7 @@ module EffectivePages
32
32
  end
33
33
 
34
34
  def setup_routes
35
- inject_into_file "config/routes.rb", "\n # if you want EffectivePages to render the home / root page\n # uncomment the following line and create an Effective::Page with slug == 'home' \n # root :to => 'Effective::Pages#show', :id => 'home'\n", :before => /root (:?)to.*/
35
+ inject_into_file 'config/routes.rb', "\n # if you want EffectivePages to render the home / root page\n # uncomment the following line and create an Effective::Page with slug == 'home' \n # root :to => 'Effective::Pages#show', :id => 'home'\n", :before => /root (:?)to.*/
36
36
  end
37
37
 
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.17
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-26 00:00:00.000000000 Z
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -179,13 +179,13 @@ files:
179
179
  - app/views/admin/pages/edit.html.haml
180
180
  - app/views/admin/pages/index.html.haml
181
181
  - app/views/admin/pages/new.html.haml
182
+ - config/effective_pages.rb
182
183
  - config/routes.rb
183
184
  - db/migrate/01_create_effective_pages.rb.erb
184
185
  - lib/effective_pages.rb
185
186
  - lib/effective_pages/engine.rb
186
187
  - lib/effective_pages/version.rb
187
188
  - lib/generators/effective_pages/install_generator.rb
188
- - lib/generators/templates/effective_pages.rb
189
189
  - lib/generators/templates/example.html.haml
190
190
  - lib/tasks/effective_pages_tasks.rake
191
191
  - spec/controllers/effective/pages_controller_spec.rb