effective_posts 0.4.7 → 0.5.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: b6c0cbc8c247c67715094aba5e52ea2f212cdbe3
4
- data.tar.gz: a67ae4457e20eb7675c78dc1c769a1b1cc84595b
3
+ metadata.gz: 5cbae7b7138b3a8c12923d42784c42ba660abfb1
4
+ data.tar.gz: d3235a3688cd1d3dc9f1d7af60fb142f00a58c78
5
5
  SHA512:
6
- metadata.gz: 1999a9f99ca390aab1e0576f8a1d5df86b0d33ccc7b29ea66b3903dd69777ac0ba29341a91f18abd1dc9e8360c98f5409d93cdeb4fe5f088d861cff8ae6b27e0
7
- data.tar.gz: b09a6b63101b33d938f70230485668f0c2c1dd1b34d1bd01650a04757c9aa01d1943e9a5226af362d4826bff0ba9f4931bcb2d04b3621a7946b65956872eba3c
6
+ metadata.gz: f63838c6ffa90c6eaa6efb925c8cbd39a9b2bc9155605bebd8be62c44e8d29a5f0439bc9e89c8d25142bb143ce3ee537c17246a0f711bd33b56cfe7d12d35e10
7
+ data.tar.gz: aa39d8b2d97656f24e387abc3f7de7108a5607ea7378f5b1e61b7bb3f014cc70157c63a678b6b8e9a4a26074a1a906a94d467b114355377d39050b50660677d7
data/README.md CHANGED
@@ -140,7 +140,11 @@ The permissions you actually want to define are as follows (using CanCan):
140
140
 
141
141
  ```ruby
142
142
  can [:index, :show], Effective::Post
143
- can [:manage], Effective::Post if user.is?(:admin)
143
+
144
+ if user.admin?
145
+ can :manage, Effective::Post
146
+ can :admin, :effective_pages
147
+ end
144
148
  ```
145
149
 
146
150
  ## Future Plans
@@ -156,9 +160,6 @@ There are some obvious additional features that have yet to be implemented:
156
160
 
157
161
  MIT License. Copyright [Code and Effect Inc.](http://www.codeandeffect.com/)
158
162
 
159
- 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.
160
-
161
-
162
163
  ## Testing
163
164
 
164
165
  Run tests by:
@@ -6,16 +6,16 @@ module Admin
6
6
 
7
7
  def index
8
8
  @page_title = 'Posts'
9
- EffectivePosts.authorized?(self, :index, Effective::Post)
9
+ @datatable = Effective::Datatables::Posts.new()
10
10
 
11
- @datatable = Effective::Datatables::Posts.new() if defined?(EffectiveDatatables)
11
+ authorize_effective_posts!
12
12
  end
13
13
 
14
14
  def new
15
15
  @post = Effective::Post.new(published_at: Time.zone.now)
16
16
  @page_title = 'New Post'
17
17
 
18
- EffectivePosts.authorized?(self, :new, @post)
18
+ authorize_effective_posts!
19
19
  end
20
20
 
21
21
  def create
@@ -24,7 +24,7 @@ module Admin
24
24
 
25
25
  @page_title = 'New Post'
26
26
 
27
- EffectivePosts.authorized?(self, :create, @post)
27
+ authorize_effective_posts!
28
28
 
29
29
  if @post.save
30
30
  if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
@@ -46,14 +46,14 @@ module Admin
46
46
  @post = Effective::Post.find(params[:id])
47
47
  @page_title = 'Edit Post'
48
48
 
49
- EffectivePosts.authorized?(self, :edit, @post)
49
+ authorize_effective_posts!
50
50
  end
51
51
 
52
52
  def update
53
53
  @post = Effective::Post.find(params[:id])
54
54
  @page_title = 'Edit Post'
55
55
 
56
- EffectivePosts.authorized?(self, :update, @post)
56
+ authorize_effective_posts!
57
57
 
58
58
  if @post.update_attributes(post_params)
59
59
  if params[:commit] == 'Save and Edit Content' && defined?(EffectiveRegions)
@@ -74,7 +74,7 @@ module Admin
74
74
  def destroy
75
75
  @post = Effective::Post.find(params[:id])
76
76
 
77
- EffectivePosts.authorized?(self, :destroy, @post)
77
+ authorize_effective_posts!
78
78
 
79
79
  if @post.destroy
80
80
  flash[:success] = 'Successfully deleted post'
@@ -87,8 +87,9 @@ module Admin
87
87
 
88
88
  def approve
89
89
  @post = Effective::Post.find(params[:id])
90
+ @page_title = 'Approve Post'
90
91
 
91
- EffectivePosts.authorized?(self, :approve, @post)
92
+ authorize_effective_posts!
92
93
 
93
94
  if @post.update_attributes(draft: false)
94
95
  flash[:success] = 'Successfully approved post. It is now displayed on the website.'
@@ -100,15 +101,19 @@ module Admin
100
101
  end
101
102
 
102
103
  def excerpts
104
+ @posts = Effective::Post.includes(:regions)
103
105
  @page_title = 'Post Excerpts'
104
106
 
105
- EffectivePosts.authorized?(self, :index, Effective::Post)
106
-
107
- @posts = Effective::Post.includes(:regions)
107
+ authorize_effective_posts!
108
108
  end
109
109
 
110
110
  private
111
111
 
112
+ def authorize_effective_posts!
113
+ EffectivePosts.authorized?(self, :admin, :effective_posts)
114
+ EffectivePosts.authorized?(self, action_name.to_sym, @post || Effective::Post)
115
+ end
116
+
112
117
  def post_params
113
118
  params.require(:effective_post).permit(EffectivePosts.permitted_params)
114
119
  end
@@ -13,7 +13,7 @@ module Effective
13
13
 
14
14
  EffectivePosts.authorized?(self, :index, Effective::Post)
15
15
 
16
- @page_title = (params[:page_title] || params[:category] || 'Posts').titleize
16
+ @page_title = (params[:page_title] || params[:category] || params[:defaults].try(:[], :category) || 'Posts').titleize
17
17
  end
18
18
 
19
19
  def show
@@ -1,2 +1,3 @@
1
- %h2= @page_title
1
+ %h1.effective-admin-heading= @page_title
2
+
2
3
  = render partial: 'form', as: :post, object: @post
@@ -1,4 +1,4 @@
1
- %h2= @page_title
1
+ %h1.effective-admin-heading= @page_title
2
2
 
3
3
  - @posts.find_each do |post|
4
4
  .row
@@ -1,9 +1,6 @@
1
- %h2= @page_title
1
+ %h1.effective-admin-heading= @page_title
2
2
 
3
- %p.text-right= link_to 'New Post', effective_posts.new_admin_post_path, :class => 'btn btn-primary'
3
+ %p.text-right.effective-admin-actions
4
+ = link_to 'New Post', effective_posts.new_admin_post_path, class: 'btn btn-primary'
4
5
 
5
- = render_datatable @datatable do
6
- %p There are no posts
7
-
8
- - if @datatable.present?
9
- %p.text-right= link_to 'New Post', effective_posts.new_admin_post_path, :class => 'btn btn-primary'
6
+ = render_datatable(@datatable)
@@ -1,2 +1,3 @@
1
- %h2= @page_title
1
+ %h1.effective-admin-heading= @page_title
2
+
2
3
  = render partial: 'form', as: :post, object: @post
@@ -1,5 +1,3 @@
1
- # EffectivePosts Rails Engine
2
-
3
1
  EffectivePosts.setup do |config|
4
2
  config.posts_table_name = :posts
5
3
 
@@ -24,9 +22,27 @@ EffectivePosts.setup do |config|
24
22
  # The author is the user that created the Effective::Post object
25
23
  config.post_meta_author = true
26
24
 
27
- # Use CanCan: authorize!(action, resource)
25
+ # Authorization Method
26
+ #
27
+ # This method is called by all controller actions with the appropriate action and resource
28
+ # If the method returns false, an Effective::AccessDenied Error will be raised (see README.md for complete info)
29
+ #
30
+ # Use via Proc (and with CanCan):
31
+ # config.authorization_method = Proc.new { |controller, action, resource| can?(action, resource) }
32
+ #
33
+ # Use via custom method:
34
+ # config.authorization_method = :my_authorization_method
35
+ #
36
+ # And then in your application_controller.rb:
37
+ #
38
+ # def my_authorization_method(action, resource)
39
+ # current_user.is?(:admin)
40
+ # end
41
+ #
42
+ # Or disable the check completely:
43
+ # config.authorization_method = false
44
+ config.authorization_method = Proc.new { |controller, action, resource| authorize!(action, resource) && resource.roles_permit?(current_user) } # CanCanCan
28
45
  # Use effective_roles: resource.roles_permit?(current_user)
29
- config.authorization_method = Proc.new { |controller, action, resource| true }
30
46
 
31
47
  # Layout Settings
32
48
  # Configure the Layout per controller, or all at once
@@ -12,7 +12,7 @@ module EffectivePosts
12
12
  # Set up our default configuration options.
13
13
  initializer "effective_posts.defaults", :before => :load_config_initializers do |app|
14
14
  # Set up our defaults, as per our initializer template
15
- eval File.read("#{config.root}/lib/generators/templates/effective_posts.rb")
15
+ eval File.read("#{config.root}/config/effective_posts.rb")
16
16
  end
17
17
  end
18
18
  end
@@ -1,3 +1,3 @@
1
1
  module EffectivePosts
2
- VERSION = '0.4.7'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -3,9 +3,9 @@ module EffectivePosts
3
3
  class InstallGenerator < Rails::Generators::Base
4
4
  include Rails::Generators::Migration
5
5
 
6
- desc "Creates an EffectivePosts initializer in your application."
6
+ desc 'Creates an EffectivePosts 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,13 +16,13 @@ module EffectivePosts
16
16
  end
17
17
 
18
18
  def copy_initializer
19
- template "effective_posts.rb", "config/initializers/effective_posts.rb"
19
+ template ('../' * 3) + 'config/effective_posts.rb', 'config/initializers/effective_posts.rb'
20
20
  end
21
21
 
22
22
  def create_migration_file
23
23
  @posts_table_name = ':' + EffectivePosts.posts_table_name.to_s
24
24
 
25
- migration_template '../../../db/migrate/01_create_effective_posts.rb.erb', 'db/migrate/create_effective_posts.rb'
25
+ migration_template ('../' * 3) + 'db/migrate/01_create_effective_posts.rb.erb', 'db/migrate/create_effective_posts.rb'
26
26
  end
27
27
 
28
28
  def copy_mailer_preview
@@ -34,10 +34,6 @@ module EffectivePosts
34
34
  puts "couldn't find action_mailer.preview_path. Skipping effective_posts_mailer_preview."
35
35
  end
36
36
  end
37
-
38
- def show_readme
39
- readme "README" if behavior == :invoke
40
- end
41
37
  end
42
38
  end
43
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.5.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-09-28 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
@@ -187,18 +187,14 @@ files:
187
187
  - app/views/kaminari/_paginator.html.haml
188
188
  - app/views/kaminari/_prev_page.html.haml
189
189
  - app/views/layouts/effective_posts_mailer_layout.html.haml
190
+ - config/effective_posts.rb
190
191
  - config/routes.rb
191
192
  - db/migrate/01_create_effective_posts.rb.erb
192
193
  - lib/effective_posts.rb
193
194
  - lib/effective_posts/engine.rb
194
195
  - lib/effective_posts/version.rb
195
196
  - lib/generators/effective_posts/install_generator.rb
196
- - lib/generators/templates/README
197
- - lib/generators/templates/effective_posts.rb
198
197
  - lib/generators/templates/effective_posts_mailer_preview.rb
199
- - spec/effective_pages_spec.rb
200
- - spec/spec_helper.rb
201
- - spec/support/factories.rb
202
198
  homepage: https://github.com/code-and-effect/effective_posts
203
199
  licenses:
204
200
  - MIT
@@ -224,7 +220,4 @@ signing_key:
224
220
  specification_version: 4
225
221
  summary: A blog implementation with WYSIWYG content editing, post scheduling, pagination
226
222
  and optional top level routes for each post category.
227
- test_files:
228
- - spec/effective_pages_spec.rb
229
- - spec/spec_helper.rb
230
- - spec/support/factories.rb
223
+ test_files: []
@@ -1 +0,0 @@
1
- Thanks for using EffectivePosts
@@ -1,7 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe EffectivePosts do
4
- it 'should be a module' do
5
- assert_kind_of Module, EffectivePosts
6
- end
7
- end
data/spec/spec_helper.rb DELETED
@@ -1,43 +0,0 @@
1
- ENV["RAILS_ENV"] ||= 'test'
2
-
3
- require File.expand_path("../dummy/config/environment", __FILE__)
4
-
5
- require 'rspec/rails'
6
- require 'rspec/autorun'
7
- require 'capybara/rspec'
8
- require 'capybara/poltergeist'
9
- require 'factory_girl_rails'
10
- require 'haml'
11
-
12
- # Requires supporting ruby files with custom matchers and macros, etc,
13
- # in spec/support/ and its subdirectories.
14
- Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f }
15
-
16
- RSpec.configure do |config|
17
- config.fixture_path = "#{::Rails.root}/spec/fixtures"
18
-
19
- config.include Capybara::DSL
20
-
21
- Capybara.current_driver = :poltergeist
22
- Capybara.javascript_driver = :poltergeist
23
- Capybara.default_wait_time = 5
24
-
25
- Rails.logger.level = 4 # Output only minimal stuff to test.log
26
-
27
- config.use_transactional_fixtures = true # Make this false to once again use DatabaseCleaner
28
- config.infer_base_class_for_anonymous_controllers = false
29
- config.order = 'random'
30
- end
31
-
32
- class ActiveRecord::Base
33
- mattr_accessor :shared_connection
34
- @@shared_connection = nil
35
-
36
- def self.connection
37
- @@shared_connection || retrieve_connection
38
- end
39
- end
40
-
41
- # Forces all threads to share the same connection. This works on
42
- # Capybara because it starts the web server in a thread.
43
- ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
@@ -1,15 +0,0 @@
1
- require 'factory_girl'
2
-
3
- FactoryGirl.define do
4
- factory :post, :class => Effective::Post do
5
- sequence(:title) { |n| "Title #{n}" }
6
- sequence(:slug) { |n| "title-#{n}" }
7
-
8
- meta_description 'meta description'
9
- draft false
10
-
11
- template 'example'
12
- layout 'application'
13
- end
14
- end
15
-