effective_pages 2.0.8 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +11 -70
  4. data/app/controllers/admin/menus_controller.rb +6 -48
  5. data/app/controllers/admin/pages_controller.rb +11 -102
  6. data/app/controllers/effective/pages_controller.rb +14 -8
  7. data/app/datatables/effective_pages_datatable.rb +20 -2
  8. data/app/datatables/effective_pages_menu_datatable.rb +38 -0
  9. data/app/helpers/effective_menus_helper.rb +31 -136
  10. data/app/helpers/effective_pages_helper.rb +4 -2
  11. data/app/models/effective/page.rb +65 -22
  12. data/app/views/admin/menus/index.html.haml +10 -2
  13. data/app/views/admin/pages/_form.html.haml +20 -25
  14. data/app/views/admin/pages/_form_access.html.haml +10 -0
  15. data/app/views/admin/pages/_form_content.html.haml +3 -0
  16. data/app/views/admin/pages/_form_menu.html.haml +16 -0
  17. data/app/views/admin/pages/_form_page.html.haml +31 -0
  18. data/app/views/admin/pages/_rich_text_areas.html.haml +2 -0
  19. data/app/views/effective/pages/_menu.html.haml +20 -0
  20. data/config/effective_pages.rb +9 -38
  21. data/config/routes.rb +6 -9
  22. data/db/migrate/01_create_effective_pages.rb.erb +12 -30
  23. data/lib/effective_pages.rb +17 -61
  24. data/lib/effective_pages/version.rb +1 -1
  25. data/lib/generators/effective_pages/install_generator.rb +1 -1
  26. data/lib/generators/templates/example.html.haml +4 -5
  27. data/lib/tasks/effective_pages_tasks.rake +1 -1
  28. metadata +11 -38
  29. data/app/datatables/effective_menus_datatable.rb +0 -16
  30. data/app/helpers/effective_breadcrumbs_helper.rb +0 -41
  31. data/app/helpers/effective_menus_admin_helper.rb +0 -8
  32. data/app/models/effective/access_denied.rb +0 -17
  33. data/app/models/effective/menu.rb +0 -172
  34. data/app/models/effective/menu_item.rb +0 -78
  35. data/app/views/admin/menu_items/_actions.html.haml +0 -4
  36. data/app/views/admin/menu_items/_expand.html.haml +0 -2
  37. data/app/views/admin/menu_items/_item.html.haml +0 -13
  38. data/app/views/admin/menu_items/_new.html.haml +0 -3
  39. data/app/views/admin/menus/_actions.html.haml +0 -2
  40. data/app/views/admin/menus/_form.html.haml +0 -4
  41. data/app/views/admin/menus/edit.html.haml +0 -3
  42. data/app/views/admin/menus/new.html.haml +0 -3
  43. data/app/views/admin/menus/show.html.haml +0 -39
  44. data/app/views/admin/pages/_actions.html.haml +0 -7
  45. data/app/views/admin/pages/_roles.html.haml +0 -1
  46. data/app/views/admin/pages/edit.html.haml +0 -3
  47. data/app/views/admin/pages/index.html.haml +0 -6
  48. data/app/views/admin/pages/new.html.haml +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 215d1a7ca112ac8f5f799b186fa6fab449340ea338e77da1676cb5c4745fff0c
4
- data.tar.gz: 6332e9e8799752a6ff3d93117fb7f0b10b78ef3691e6b62faccf73a76e4da587
3
+ metadata.gz: 2624cae83c49b16480071da85aaac6bf14daac37bb3c761af9a5eb463c4f1559
4
+ data.tar.gz: 5cea72cad0f89b57bd47d62a25f1d694e0b5accd1546bd0f190dc104da3fbe10
5
5
  SHA512:
6
- metadata.gz: 3c2329ad44abe3d85007d94e4e76e487a9b2decda4e4ea91f9f7c61676a576ac20b6a77dc7b1b1481904903611152e024b3b7aadcd9ea1a9767ac91d9b7a8c85
7
- data.tar.gz: fb1f224d1b1696c7f4bacbc9a0563760d1d7e4727a9d35b9cc842cae1ebeb5f87e453fa59ed2ff66dc2b8e8bc01c4baa1998838e277fbd066a7ff65777ad9f51
6
+ metadata.gz: 576642b33ebfe721192d30e860d6d864d659abba485a24e158e33234f4dde18b4a3548b33d043024114fe89eae8e3c6ab8854b3dd9dc8e5e23b6c5d617d0d023
7
+ data.tar.gz: 512237ffc6d895b2d547fe0ffd8d9807931c5e925bcabb912eec86defe56745335a3f1d9c6b3fe848ed0e5613bf90505c79e91504cf125440896029eaa9b0c0e
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2018 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
@@ -6,18 +6,14 @@ Create content pages ontop of one or more templates -- just regular Rails views
6
6
 
7
7
  Use this gem to create a fully-functional CMS that provides full or restricted editing for your end users.
8
8
 
9
- Built ontop of effective_regions and effective_ckeditor.
10
9
 
10
+ ## effective_pages 3.0
11
11
 
12
- ## effective_pages 2.0
13
-
14
- This is the 2.0 series of effective_pages.
15
-
16
- This requires Twitter Bootstrap 4 and Rails 5.1+
17
-
18
- Please check out [bootstrap3 branch](https://github.com/code-and-effect/effective_datatables/tree/bootstrap3) for more information using this gem with Bootstrap 3.
12
+ This is the 3.0 series of effective_pages.
19
13
 
14
+ This requires Twitter Bootstrap 4 and Rails 6+
20
15
 
16
+ Please check out [Effective Posts 0.x](https://github.com/code-and-effect/effective_posts/tree/bootstrap3) for more information using this gem with Bootstrap 3.
21
17
  ## Getting Started
22
18
 
23
19
  Please first install the [effective_regions](https://github.com/code-and-effect/effective_regions) and [effective_datatables](https://github.com/code-and-effect/effective_datatables) gems.
@@ -90,6 +86,7 @@ An example of a two-column layout I like to create is as follows:
90
86
 
91
87
  ```haml
92
88
  %h1
89
+
93
90
  = simple_effective_region page, :header do
94
91
  = page.title
95
92
 
@@ -121,19 +118,11 @@ effective_pages.page_url(page)
121
118
 
122
119
  If you would like to use an Effective::Page for your home/root page, add the following to your routes.rb:
123
120
 
124
- Rails 3 Syntax:
125
-
126
121
  ```ruby
127
- root :to => 'Effective::Pages#show', :id => 'home'
122
+ root to: 'effective/pages#show', id: 'home'
128
123
  ```
129
124
 
130
- Rails 4 Syntax:
131
-
132
- ```ruby
133
- root :to => 'effective/pages#show', :id => 'home'
134
- ```
135
-
136
- and make sure a page with slug 'home' exists.
125
+ and make sure a page with slug `home` exists.
137
126
 
138
127
 
139
128
  ### Header Tags
@@ -156,10 +145,10 @@ This helper is entirely optional and in no way required for effective_pages to w
156
145
 
157
146
  ### Body Tag Classes
158
147
 
159
- Another optional helper. Add the following to your `<body>` tag:
148
+ Another optional helper. Add the following to your `<body>` tag:
160
149
 
161
150
  ```haml
162
- %body{:class => effective_pages_body_classes}
151
+ %body{class: effective_pages_body_classes}
163
152
  ```
164
153
 
165
154
  to apply the following html classes: `params[:controller]`, `params[:action]`, `signed-in` / `not-signed-in`, `@page.template` and any thing set in the `@body_classes` instance variable.
@@ -176,54 +165,7 @@ Use this functionality to create member-only type pages.
176
165
 
177
166
  ## Authorization
178
167
 
179
- All authorization checks are handled via the config.authorization_method found in the `config/initializers/effective_pages.rb` file.
180
-
181
- It is intended for flow through to CanCan or Pundit, but neither of those gems are required.
182
-
183
- This method is called by all controller actions with the appropriate action and resource
184
-
185
- Action will be one of [:index, :show, :new, :create, :edit, :update, :destroy]
186
-
187
- Resource will the appropriate Effective::Page object or class
188
-
189
- The authorization method is defined in the initializer file:
190
-
191
- ```ruby
192
- # As a Proc (with CanCan)
193
- config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) }
194
- ```
195
-
196
- ```ruby
197
- # As a Custom Method
198
- config.authorization_method = :my_authorization_method
199
- ```
200
-
201
- and then in your application_controller.rb:
202
-
203
- ```ruby
204
- def my_authorization_method(action, resource)
205
- current_user.is?(:admin) || EffectivePunditPolicy.new(current_user, resource).send('#{action}?')
206
- end
207
- ```
208
-
209
- or disabled entirely:
210
-
211
- ```ruby
212
- config.authorization_method = false
213
- ```
214
-
215
- If the method or proc returns false (user is not authorized) an Effective::AccessDenied exception will be raised
216
-
217
- You can rescue from this exception by adding the following to your application_controller.rb:
218
-
219
- ```ruby
220
- rescue_from Effective::AccessDenied do |exception|
221
- respond_to do |format|
222
- format.html { render 'static_pages/access_denied', :status => 403 }
223
- format.any { render :text => 'Access Denied', :status => 403 }
224
- end
225
- end
226
- ```
168
+ All authorization checks are handled via the effective_resources gem found in the `config/initializers/effective_resources.rb` file.
227
169
 
228
170
  ### Permissions
229
171
 
@@ -234,6 +176,7 @@ can [:show], Effective::Page
234
176
 
235
177
  if user.is?(:admin)
236
178
  can :manage, Effective::Page
179
+ can :manage, Effective::Menu
237
180
  can :admin, :effective_pages # Can access the admin screens
238
181
  end
239
182
  ```
@@ -250,5 +193,3 @@ MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
250
193
  4. Push to the branch (`git push origin my-new-feature`)
251
194
  5. Bonus points for test coverage
252
195
  6. Create new Pull Request
253
-
254
-
@@ -1,56 +1,14 @@
1
1
  module Admin
2
2
  class MenusController < ApplicationController
3
- before_action(:authenticate_user!) # Devise
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_pages) }
4
5
 
5
- helper EffectiveMenusAdminHelper
6
+ include Effective::CrudController
6
7
 
7
- layout (EffectivePages.layout.kind_of?(Hash) ? EffectivePages.layout[:admin] : EffectivePages.layout)
8
+ resource_scope -> { Effective::Page.all }
8
9
 
9
- def index
10
- @datatable = EffectiveMenusDatatable.new(self)
11
- @page_title = 'Menus'
12
-
13
- authorize_effective_menus!
14
- end
15
-
16
- def new
17
- @menu = Effective::Menu.new()
18
- @page_title = 'New Menu'
19
-
20
- authorize_effective_menus!
21
- end
22
-
23
- def create
24
- @menu = Effective::Menu.new(menu_params)
25
- @page_title = 'New Menu'
26
-
27
- authorize_effective_menus!
28
-
29
- if @menu.save
30
- flash[:success] = 'Successfully created menu'
31
- redirect_to effective_pages.admin_menu_path(@menu)
32
- else
33
- flash.now[:danger] = 'Unable to create menu'
34
- render :action => :new
35
- end
36
- end
37
-
38
- def show
39
- @menu = Effective::Menu.find(params[:id])
40
- @page_title = @menu.to_s
41
-
42
- authorize_effective_menus!
43
- end
44
-
45
- private
46
-
47
- def authorize_effective_menus!
48
- EffectivePages.authorized?(self, :admin, :effective_pages)
49
- EffectivePages.authorized?(self, action_name.to_sym, @menu || Effective::Menu)
50
- end
51
-
52
- def menu_params
53
- params.require(:effective_menu).permit(:title)
10
+ if (config = EffectivePages.layout)
11
+ layout(config.kind_of?(Hash) ? config[:admin] : config)
54
12
  end
55
13
 
56
14
  end
@@ -1,112 +1,21 @@
1
1
  module Admin
2
2
  class PagesController < ApplicationController
3
- before_action(:authenticate_user!) # Devise
3
+ before_action(:authenticate_user!) if defined?(Devise)
4
+ before_action { EffectiveResources.authorize!(self, :admin, :effective_pages) }
4
5
 
5
- layout (EffectivePages.layout.kind_of?(Hash) ? EffectivePages.layout[:admin] : EffectivePages.layout)
6
+ include Effective::CrudController
6
7
 
7
- def index
8
- @datatable = EffectivePagesDatatable.new(self)
9
- @page_title = 'Pages'
10
-
11
- authorize_effective_pages!
12
- end
13
-
14
- def new
15
- @page = Effective::Page.new()
16
- @page_title = 'New Page'
17
-
18
- authorize_effective_pages!
19
- end
20
-
21
- def create
22
- @page = Effective::Page.new(page_params)
23
- @page_title = 'New Page'
24
-
25
- authorize_effective_pages!
26
-
27
- if @page.save
28
- if params[:commit] == 'Save and Edit Content'
29
- redirect_to effective_regions.edit_path(effective_pages.page_path(@page), :exit => effective_pages.edit_admin_page_path(@page))
30
- elsif params[:commit] == 'Save and Add New'
31
- flash[:success] = 'Successfully created page'
32
- redirect_to effective_pages.new_admin_page_path
33
- elsif params[:commit] == 'Save and View'
34
- redirect_to effective_pages.page_path(@page)
35
- else
36
- flash[:success] = 'Successfully created page'
37
- redirect_to effective_pages.edit_admin_page_path(@page)
38
- end
39
- else
40
- flash.now[:danger] = 'Unable to create page'
41
- render :action => :new
42
- end
43
- end
44
-
45
- def edit
46
- @page = Effective::Page.find(params[:id])
47
- @page_title = 'Edit Page'
48
-
49
- authorize_effective_pages!
8
+ if (config = EffectivePages.layout)
9
+ layout(config.kind_of?(Hash) ? config[:admin] : config)
50
10
  end
51
11
 
52
- def update
53
- @page = Effective::Page.find(params[:id])
54
- @page_title = 'Edit Page'
55
-
56
- authorize_effective_pages!
57
-
58
- if @page.update_attributes(page_params)
59
- if params[:commit] == 'Save and Edit Content'
60
- redirect_to effective_regions.edit_path(effective_pages.page_path(@page), :exit => effective_pages.edit_admin_page_path(@page))
61
- elsif params[:commit] == 'Save and Add New'
62
- flash[:success] = 'Successfully updated page'
63
- redirect_to effective_pages.new_admin_page_path
64
- elsif params[:commit] == 'Save and View'
65
- redirect_to effective_pages.page_path(@page)
66
- elsif params[:commit] == 'Duplicate'
67
- begin
68
- page = @page.duplicate!
69
- flash[:success] = 'Successfully saved and duplicated page.'
70
- flash[:info] = "You are now editting the duplicated page. This new page has been created as a Draft."
71
- rescue => e
72
- flash.delete(:success)
73
- flash[:danger] = "Unable to duplicate page: #{e.message}"
74
- end
75
-
76
- redirect_to effective_pages.edit_admin_page_path(page || @page)
77
- else
78
- flash[:success] = 'Successfully updated page'
79
- redirect_to effective_pages.edit_admin_page_path(@page)
80
- end
81
- else
82
- flash.now[:danger] = 'Unable to update page'
83
- render :action => :edit
84
- end
85
- end
86
-
87
- def destroy
88
- @page = Effective::Page.find(params[:id])
89
-
90
- authorize_effective_pages!
91
-
92
- if @page.destroy
93
- flash[:success] = 'Successfully deleted page'
94
- else
95
- flash[:danger] = 'Unable to delete page'
96
- end
97
-
98
- redirect_to effective_pages.admin_pages_path
99
- end
100
-
101
- private
102
-
103
- def authorize_effective_pages!
104
- EffectivePages.authorized?(self, :admin, :effective_pages)
105
- EffectivePages.authorized?(self, action_name.to_sym, @page|| Effective::Page)
106
- end
12
+ submit :save, 'Save'
13
+ submit :save, 'Save and Add New', redirect: :new
14
+ submit :save, 'Save and View', redirect: -> { effective_pages.page_path(resource) }
15
+ submit :save, 'Duplicate', only: :edit, redirect: -> { effective_pages.new_admin_page_path(duplicate_id: resource.id) }
107
16
 
108
- def page_params
109
- params.require(:effective_page).permit(EffectivePages.permitted_params)
17
+ def permitted_params
18
+ params.require(:effective_page).permit!
110
19
  end
111
20
 
112
21
  end
@@ -1,37 +1,43 @@
1
1
  module Effective
2
2
  class PagesController < ApplicationController
3
+ include Effective::CrudController
4
+
3
5
  def show
4
6
  @pages = Effective::Page.all
5
- @pages = @pages.published unless EffectivePages.authorized?(self, :admin, :effective_pages)
7
+ @pages = @pages.published unless EffectiveResources.authorized?(self, :admin, :effective_pages)
6
8
 
7
9
  @page = @pages.find(params[:id])
8
10
 
9
- raise ActiveRecord::RecordNotFound unless @page.present? # Incase .find() isn't raising it
10
- raise Effective::AccessDenied.new('Access Denied', :show, @page) unless @page.roles_permit?(current_user)
11
+ if @page.authenticate_user? || @page.roles.present?
12
+ authenticate_user!
13
+ end
11
14
 
12
- EffectivePages.authorized?(self, :show, @page)
15
+ raise Effective::AccessDenied.new('Access Denied', :show, @page) unless @page.roles_permit?(current_user)
16
+ EffectiveResources.authorize!(self, :show, @page)
13
17
 
14
18
  @page_title = @page.title
15
19
  @meta_description = @page.meta_description
16
20
  @canonical_url = effective_pages.page_url(@page)
17
21
 
18
- if EffectivePages.authorized?(self, :admin, :effective_pages)
22
+ if EffectiveResources.authorized?(self, :admin, :effective_pages)
19
23
  flash.now[:warning] = [
20
24
  'Hi Admin!',
21
25
  ('You are viewing a hidden page.' unless @page.published?),
22
26
  'Click here to',
23
- ("<a href='#{effective_regions.edit_path(effective_pages.page_path(@page))}' class='alert-link' data-no-turbolink='true' data-turbolinks='false'>edit page content</a> or" unless admin_edit?),
24
27
  ("<a href='#{effective_pages.edit_admin_page_path(@page)}' class='alert-link'>edit page settings</a>.")
25
28
  ].compact.join(' ')
26
29
  end
27
30
 
28
- render @page.template, layout: @page.layout, locals: { page: @page }
31
+ template = File.join(EffectivePages.pages_path, @page.template)
32
+ layout = File.join(EffectivePages.layouts_path, @page.layout)
33
+
34
+ render(template, layout: layout, locals: { page: @page })
29
35
  end
30
36
 
31
37
  private
32
38
 
33
39
  def admin_edit?
34
- EffectivePages.authorized?(self, :admin, :effective_posts) && (params[:edit].to_s == 'true')
40
+ EffectiveResources.authorized?(self, :admin, :effective_pages) && (params[:edit].to_s == 'true')
35
41
  end
36
42
 
37
43
  end
@@ -1,5 +1,12 @@
1
1
  class EffectivePagesDatatable < Effective::Datatable
2
2
 
3
+ filters do
4
+ scope :published
5
+ scope :draft
6
+ scope :on_menu
7
+ scope :all
8
+ end
9
+
3
10
  datatable do
4
11
  order :title, :asc
5
12
  length :all
@@ -18,11 +25,22 @@ class EffectivePagesDatatable < Effective::Datatable
18
25
  col :layout, visible: false
19
26
  col :tempate, visible: false
20
27
 
21
- actions_col partial: 'admin/pages/actions', partial_as: :page
28
+ col :menu
29
+ col :menu_name, visible: false
30
+ col :menu_url, visible: false
31
+ col :menu_parent, visible: false
32
+ col :menu_position, visible: false
33
+
34
+ col :authenticate_user, visible: false
35
+ col :roles, visible: false
36
+
37
+ actions_col do |page|
38
+ dropdown_link_to('View', effective_pages.page_path(page), target: '_blank')
39
+ end
22
40
  end
23
41
 
24
42
  collection do
25
- Effective::Page.all
43
+ Effective::Page.deep.all
26
44
  end
27
45
 
28
46
  end
@@ -0,0 +1,38 @@
1
+ class EffectivePagesMenuDatatable < Effective::Datatable
2
+
3
+ datatable do
4
+ reorder :menu_position
5
+
6
+ if attributes[:menu_parent_id].present?
7
+ col :menu_parent
8
+ end
9
+
10
+ col :title do |page|
11
+ link_to(page, effective_pages.edit_admin_page_path(page))
12
+ end
13
+
14
+ col :menu_url, label: 'Redirect Url'
15
+ col :menu_position, label: 'Position', visible: false
16
+ col :menu_children, label: 'Children'
17
+
18
+ actions_col(new: false, destroy: false)
19
+ end
20
+
21
+ collection(apply_belongs_to: false) do
22
+ scope = Effective::Page.deep.for_menu(menu)
23
+
24
+ scope = if attributes[:menu_parent_id].present?
25
+ scope.where(menu_parent_id: attributes[:menu_parent_id])
26
+ else
27
+ scope.where(menu_parent_id: nil)
28
+ end
29
+
30
+ scope
31
+ end
32
+
33
+ def menu
34
+ menu = EffectivePages.menus.find { |menu| menu.to_s == attributes[:menu].to_s }
35
+ menu || raise("unexpected menu: #{attributes[:menu] || 'none'}")
36
+ end
37
+
38
+ end