enju_news 0.1.1 → 0.2.0.beta.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +3 -3
  3. data/app/controllers/news_feeds_controller.rb +11 -1
  4. data/app/controllers/news_posts_controller.rb +12 -2
  5. data/app/models/news_post.rb +12 -0
  6. data/app/policies/news_feed_policy.rb +21 -0
  7. data/app/policies/news_post_policy.rb +21 -0
  8. data/app/views/news_feeds/index.html.erb +4 -2
  9. data/app/views/news_posts/index.html.erb +3 -1
  10. data/lib/enju_news/engine.rb +1 -1
  11. data/lib/enju_news/version.rb +1 -1
  12. data/spec/controllers/news_feeds_controller_spec.rb +12 -12
  13. data/spec/controllers/news_posts_controller_spec.rb +10 -10
  14. data/spec/dummy/app/controllers/application_controller.rb +5 -2
  15. data/spec/dummy/app/models/user.rb +1 -2
  16. data/spec/dummy/config/application.rb +7 -24
  17. data/spec/dummy/config/environments/development.rb +25 -14
  18. data/spec/dummy/config/environments/production.rb +50 -31
  19. data/spec/dummy/config/environments/test.rb +23 -18
  20. data/spec/dummy/db/migrate/149_create_message_templates.rb +18 -0
  21. data/spec/dummy/db/migrate/154_create_messages.rb +23 -0
  22. data/spec/dummy/db/migrate/20080819181903_create_message_requests.rb +18 -0
  23. data/spec/dummy/db/migrate/20110913115320_add_lft_and_rgt_to_message.rb +11 -0
  24. data/spec/dummy/db/migrate/20120125050502_add_depth_to_message.rb +6 -0
  25. data/spec/dummy/db/migrate/20140110122216_create_user_import_files.rb +1 -1
  26. data/spec/dummy/db/migrate/20140518111006_create_message_transitions.rb +18 -0
  27. data/spec/dummy/db/migrate/20140518135713_create_message_request_transitions.rb +18 -0
  28. data/spec/dummy/db/migrate/20140524074813_create_user_import_file_transitions.rb +5 -1
  29. data/spec/dummy/db/migrate/20140709113905_create_user_export_file_transitions.rb +5 -1
  30. data/spec/dummy/db/migrate/20140821151023_create_colors.rb +14 -0
  31. data/spec/dummy/db/migrate/20150506105356_add_error_message_to_user_import_result.rb +5 -0
  32. data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +13 -0
  33. data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +13 -0
  34. data/spec/dummy/db/migrate/20151213072705_add_footer_banner_to_library_group.rb +9 -0
  35. data/spec/dummy/db/migrate/20160610093229_add_html_snippet_to_library_group.rb +5 -0
  36. data/spec/dummy/db/migrate/20160627232219_add_most_recent_to_user_import_file_transitions.rb +9 -0
  37. data/spec/dummy/db/migrate/20160627232316_add_most_recent_to_user_export_file_transitions.rb +9 -0
  38. data/spec/dummy/db/migrate/20160703185015_add_most_recent_to_message_transitions.rb +9 -0
  39. data/spec/dummy/db/migrate/20160813191647_add_max_number_of_results_to_library_group.rb +5 -0
  40. data/spec/dummy/db/migrate/20160813191733_add_family_name_first_to_library_group.rb +5 -0
  41. data/spec/dummy/db/migrate/20160813192542_add_pub_year_facet_range_interval_to_library_group.rb +5 -0
  42. data/spec/dummy/db/migrate/20160813203039_add_user_id_to_library_group.rb +5 -0
  43. data/spec/dummy/db/migrate/20160814165332_add_most_recent_to_message_request_transitions.rb +9 -0
  44. data/spec/dummy/db/schema.rb +48 -5
  45. data/spec/fixtures/library_groups.yml +1 -6
  46. data/spec/models/news_feed_spec.rb +1 -1
  47. data/spec/models/news_post_spec.rb +1 -1
  48. data/spec/rails_helper.rb +60 -0
  49. data/spec/spec_helper.rb +84 -52
  50. data/spec/support/devise.rb +2 -2
  51. metadata +114 -17
  52. data/app/models/enju_news/ability.rb +0 -18
  53. data/spec/dummy/app/models/ability.rb +0 -18
  54. data/spec/dummy/config/application.yml +0 -42
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f990cda7c68cbca65c77e8c4586e2738d121e92
4
- data.tar.gz: 1ddee41de86bdbc94821594fdb17260f09b76d17
3
+ metadata.gz: 27eacbefe4bd18016876aa0946e0653bd602a739
4
+ data.tar.gz: f76a744164203b419b4aed9b47d561cd8579fb25
5
5
  SHA512:
6
- metadata.gz: f23f6f506fdd9b8627ce9e74248d9cc7076540f4e22e652ed528fe467ce9d818235a97b961bc02fd083d9dc890a31f7469ead5de3c8771de1aead562099e4aaa
7
- data.tar.gz: 8a1b9134dce47f214d93e1748ec3ed137b0d779b3236b08bc72ecce44ca0cbf5206b44ac5b1744aa95fa052f570a33db7faf574f7a30f2f28777841178dd9843
6
+ metadata.gz: fe78c9b1b78c6e33ad4de9c680bd594a59ce6b88d1008567cab0dba27baf3a205cd496a7790a9a4d5adb1840511e6ade4d8133b9d9467b5393886c33e42bfd50
7
+ data.tar.gz: eea53bb6d08a22fe889653de1b62cba4befa63dd52a2e1ae7af4c9b5deeb2eb0081ac2086eb455491a26586a1c16dc63fda04bbb83e5a42b9e1f7717c3d82fce
@@ -1,7 +1,7 @@
1
1
  = EnjuNews
2
- {<img src="https://travis-ci.org/next-l/enju_news.svg?branch=1.1" alt="Build Status" />}[https://travis-ci.org/next-l/enju_news]
3
- {<img src="https://coveralls.io/repos/next-l/enju_news/badge.svg?branch=1.1&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_news?branch=1.1]
4
- {<img src="https://hakiri.io/github/next-l/enju_news/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_news/1.1]
2
+ {<img src="https://travis-ci.org/next-l/enju_news.svg?branch=1.2" alt="Build Status" />}[https://travis-ci.org/next-l/enju_news]
3
+ {<img src="https://coveralls.io/repos/next-l/enju_news/badge.svg?branch=1.2&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_news?branch=1.2]
4
+ {<img src="https://hakiri.io/github/next-l/enju_news/1.2.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_news/1.2]
5
5
 
6
6
  This project rocks and uses MIT-LICENSE.
7
7
 
@@ -1,5 +1,6 @@
1
1
  class NewsFeedsController < ApplicationController
2
- load_and_authorize_resource
2
+ before_action :set_news_feed, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
3
4
 
4
5
  # GET /news_feeds
5
6
  # GET /news_feeds.json
@@ -91,6 +92,15 @@ class NewsFeedsController < ApplicationController
91
92
  end
92
93
 
93
94
  private
95
+ def set_news_feed
96
+ @news_feed = NewsFeed.find(params[:id])
97
+ authorize @news_feed
98
+ end
99
+
100
+ def check_policy
101
+ authorize NewsFeed
102
+ end
103
+
94
104
  def news_feed_params
95
105
  params.require(:news_feed).permit(:title, :url)
96
106
  end
@@ -1,6 +1,7 @@
1
1
  class NewsPostsController < ApplicationController
2
- load_and_authorize_resource
3
- before_filter :prepare_options, only: [:new, :edit]
2
+ before_action :set_news_post, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
4
+ before_action :prepare_options, only: [:new, :edit]
4
5
 
5
6
  # GET /news_posts
6
7
  # GET /news_posts.json
@@ -93,6 +94,15 @@ class NewsPostsController < ApplicationController
93
94
  end
94
95
 
95
96
  private
97
+ def set_news_post
98
+ @news_post = NewsPost.find(params[:id])
99
+ authorize @news_post
100
+ end
101
+
102
+ def check_policy
103
+ authorize NewsPost
104
+ end
105
+
96
106
  def news_post_params
97
107
  params.require(:news_post).permit(:title, :body)
98
108
  end
@@ -1,11 +1,13 @@
1
1
  class NewsPost < ActiveRecord::Base
2
2
  scope :published, -> { where(draft: false) }
3
+ scope :current, -> { where('start_date <= ? AND end_date >= ?', Time.zone.now, Time.zone.now) }
3
4
  default_scope { order('news_posts.start_date DESC') }
4
5
  belongs_to :user
5
6
  belongs_to :required_role, class_name: 'Role', foreign_key: 'required_role_id', validate: true
6
7
 
7
8
  validates_presence_of :title, :body, :user_id
8
9
  validates_associated :user
10
+ validate :check_date
9
11
 
10
12
  acts_as_list
11
13
 
@@ -17,6 +19,16 @@ class NewsPost < ActiveRecord::Base
17
19
  def self.per_page
18
20
  10
19
21
  end
22
+
23
+ def check_date
24
+ if start_date and end_date
25
+ self.end_date = end_date.end_of_day
26
+ if start_date >= end_date
27
+ errors.add(:start_date)
28
+ errors.add(:end_date)
29
+ end
30
+ end
31
+ end
20
32
  end
21
33
 
22
34
  # == Schema Information
@@ -0,0 +1,21 @@
1
+ class NewsFeedPolicy < ApplicationPolicy
2
+ def index?
3
+ true if user.try(:has_role?, 'Librarian')
4
+ end
5
+
6
+ def show?
7
+ true if user.try(:has_role?, 'Librarian')
8
+ end
9
+
10
+ def create?
11
+ true if user.try(:has_role?, 'Administrator')
12
+ end
13
+
14
+ def update?
15
+ true if user.try(:has_role?, 'Administrator')
16
+ end
17
+
18
+ def destroy?
19
+ true if user.try(:has_role?, 'Administrator')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class NewsPostPolicy < ApplicationPolicy
2
+ def index?
3
+ true
4
+ end
5
+
6
+ def show?
7
+ true
8
+ end
9
+
10
+ def create?
11
+ true if user.try(:has_role?, 'Administrator')
12
+ end
13
+
14
+ def update?
15
+ true if user.try(:has_role?, 'Administrator')
16
+ end
17
+
18
+ def destroy?
19
+ true if user.try(:has_role?, 'Administrator')
20
+ end
21
+ end
@@ -13,15 +13,17 @@
13
13
  <%- @news_feeds.each do |news_feed| -%>
14
14
  <tr class="line<%= cycle("0", "1") -%>">
15
15
  <td>
16
- <%- if can? :delete, news_feed -%>
16
+ <%- if policy(news_feed).update? -%>
17
17
  <%= move_position(news_feed) -%>
18
18
  <%- end -%>
19
19
  </td>
20
20
  <td><%= link_to h(news_feed.title), news_feed -%></td>
21
21
  <td><%= link_to h(news_feed.url), news_feed.url -%></td>
22
22
  <td>
23
- <%- if can? :delete, news_feed -%>
23
+ <%- if policy(news_feed).update? -%>
24
24
  <%= link_to t('page.edit'), edit_news_feed_path(news_feed) -%>
25
+ <%- end -%>
26
+ <%- if policy(news_feed).destroy? -%>
25
27
  <%= link_to t('page.destroy'), news_feed, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
26
28
  <%- end -%>
27
29
  </td>
@@ -22,8 +22,10 @@
22
22
  </td>
23
23
  <td><%= news_post.required_role.display_name.localize -%></td>
24
24
  <td>
25
- <% if can? :delete, news_post %>
25
+ <% if policy(news_post).update? %>
26
26
  <%= link_to t('page.edit'), edit_news_post_path(news_post) -%>
27
+ <% end %>
28
+ <% if policy(news_post).destroy? %>
27
29
  <%= link_to t('page.destroy'), news_post, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
28
30
  <% end %>
29
31
  </td>
@@ -1,4 +1,4 @@
1
- require 'faraday'
1
+ require 'enju_library'
2
2
 
3
3
  module EnjuNews
4
4
  class Engine < ::Rails::Engine
@@ -1,3 +1,3 @@
1
1
  module EnjuNews
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0.beta.2"
3
3
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe NewsFeedsController do
4
4
  fixtures :all
@@ -35,7 +35,7 @@ describe NewsFeedsController do
35
35
 
36
36
  it "assigns empty as @news_feeds" do
37
37
  get :index
38
- assigns(:news_feeds).should be_empty
38
+ assigns(:news_feeds).should be_nil
39
39
  response.should be_forbidden
40
40
  end
41
41
  end
@@ -43,7 +43,7 @@ describe NewsFeedsController do
43
43
  describe "When not logged in" do
44
44
  it "assigns all news_feeds as @news_feeds" do
45
45
  get :index
46
- assigns(:news_feeds).should be_empty
46
+ assigns(:news_feeds).should be_nil
47
47
  response.should redirect_to(new_user_session_url)
48
48
  end
49
49
  end
@@ -105,7 +105,7 @@ describe NewsFeedsController do
105
105
 
106
106
  it "should not assign the requested news_feed as @news_feed" do
107
107
  get :new
108
- assigns(:news_feed).should_not be_valid
108
+ assigns(:news_feed).should be_nil
109
109
  response.should be_forbidden
110
110
  end
111
111
  end
@@ -115,7 +115,7 @@ describe NewsFeedsController do
115
115
 
116
116
  it "should not assign the requested news_feed as @news_feed" do
117
117
  get :new
118
- assigns(:news_feed).should_not be_valid
118
+ assigns(:news_feed).should be_nil
119
119
  response.should be_forbidden
120
120
  end
121
121
  end
@@ -123,7 +123,7 @@ describe NewsFeedsController do
123
123
  describe "When not logged in" do
124
124
  it "should not assign the requested news_feed as @news_feed" do
125
125
  get :new
126
- assigns(:news_feed).should_not be_valid
126
+ assigns(:news_feed).should be_nil
127
127
  response.should redirect_to(new_user_session_url)
128
128
  end
129
129
  end
@@ -209,7 +209,7 @@ describe NewsFeedsController do
209
209
  describe "with valid params" do
210
210
  it "assigns a newly created news_feed as @news_feed" do
211
211
  post :create, :news_feed => @attrs
212
- assigns(:news_feed).should be_valid
212
+ assigns(:news_feed).should be_nil
213
213
  end
214
214
 
215
215
  it "should be forbidden" do
@@ -221,7 +221,7 @@ describe NewsFeedsController do
221
221
  describe "with invalid params" do
222
222
  it "assigns a newly created but unsaved news_feed as @news_feed" do
223
223
  post :create, :news_feed => @invalid_attrs
224
- assigns(:news_feed).should_not be_valid
224
+ assigns(:news_feed).should be_nil
225
225
  end
226
226
 
227
227
  it "should be forbidden" do
@@ -237,7 +237,7 @@ describe NewsFeedsController do
237
237
  describe "with valid params" do
238
238
  it "assigns a newly created news_feed as @news_feed" do
239
239
  post :create, :news_feed => @attrs
240
- assigns(:news_feed).should be_valid
240
+ assigns(:news_feed).should be_nil
241
241
  end
242
242
 
243
243
  it "should be forbidden" do
@@ -249,7 +249,7 @@ describe NewsFeedsController do
249
249
  describe "with invalid params" do
250
250
  it "assigns a newly created but unsaved news_feed as @news_feed" do
251
251
  post :create, :news_feed => @invalid_attrs
252
- assigns(:news_feed).should_not be_valid
252
+ assigns(:news_feed).should be_nil
253
253
  end
254
254
 
255
255
  it "should be forbidden" do
@@ -263,7 +263,7 @@ describe NewsFeedsController do
263
263
  describe "with valid params" do
264
264
  it "assigns a newly created news_feed as @news_feed" do
265
265
  post :create, :news_feed => @attrs
266
- assigns(:news_feed).should be_valid
266
+ assigns(:news_feed).should be_nil
267
267
  end
268
268
 
269
269
  it "should be forbidden" do
@@ -275,7 +275,7 @@ describe NewsFeedsController do
275
275
  describe "with invalid params" do
276
276
  it "assigns a newly created but unsaved news_feed as @news_feed" do
277
277
  post :create, :news_feed => @invalid_attrs
278
- assigns(:news_feed).should_not be_valid
278
+ assigns(:news_feed).should be_nil
279
279
  end
280
280
 
281
281
  it "should be forbidden" do
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require 'rails_helper'
2
2
 
3
3
  describe NewsPostsController do
4
4
  fixtures :all
@@ -103,7 +103,7 @@ describe NewsPostsController do
103
103
 
104
104
  it "should not assign the requested news_post as @news_post" do
105
105
  get :new
106
- assigns(:news_post).should_not be_valid
106
+ assigns(:news_post).should be_nil
107
107
  response.should be_forbidden
108
108
  end
109
109
  end
@@ -113,7 +113,7 @@ describe NewsPostsController do
113
113
 
114
114
  it "should not assign the requested news_post as @news_post" do
115
115
  get :new
116
- assigns(:news_post).should_not be_valid
116
+ assigns(:news_post).should be_nil
117
117
  response.should be_forbidden
118
118
  end
119
119
  end
@@ -121,7 +121,7 @@ describe NewsPostsController do
121
121
  describe "When not logged in" do
122
122
  it "should not assign the requested news_post as @news_post" do
123
123
  get :new
124
- assigns(:news_post).should_not be_valid
124
+ assigns(:news_post).should be_nil
125
125
  response.should redirect_to(new_user_session_url)
126
126
  end
127
127
  end
@@ -207,7 +207,7 @@ describe NewsPostsController do
207
207
  describe "with valid params" do
208
208
  it "assigns a newly created news_post as @news_post" do
209
209
  post :create, :news_post => @attrs
210
- assigns(:news_post).should_not be_valid
210
+ assigns(:news_post).should be_nil
211
211
  end
212
212
 
213
213
  it "should be forbidden" do
@@ -219,7 +219,7 @@ describe NewsPostsController do
219
219
  describe "with invalid params" do
220
220
  it "assigns a newly created but unsaved news_post as @news_post" do
221
221
  post :create, :news_post => @invalid_attrs
222
- assigns(:news_post).should_not be_valid
222
+ assigns(:news_post).should be_nil
223
223
  end
224
224
 
225
225
  it "should be forbidden" do
@@ -235,7 +235,7 @@ describe NewsPostsController do
235
235
  describe "with valid params" do
236
236
  it "assigns a newly created news_post as @news_post" do
237
237
  post :create, :news_post => @attrs
238
- assigns(:news_post).should_not be_valid
238
+ assigns(:news_post).should be_nil
239
239
  end
240
240
 
241
241
  it "should be forbidden" do
@@ -247,7 +247,7 @@ describe NewsPostsController do
247
247
  describe "with invalid params" do
248
248
  it "assigns a newly created but unsaved news_post as @news_post" do
249
249
  post :create, :news_post => @invalid_attrs
250
- assigns(:news_post).should_not be_valid
250
+ assigns(:news_post).should be_nil
251
251
  end
252
252
 
253
253
  it "should be forbidden" do
@@ -261,7 +261,7 @@ describe NewsPostsController do
261
261
  describe "with valid params" do
262
262
  it "assigns a newly created news_post as @news_post" do
263
263
  post :create, :news_post => @attrs
264
- assigns(:news_post).should_not be_valid
264
+ assigns(:news_post).should be_nil
265
265
  end
266
266
 
267
267
  it "should be forbidden" do
@@ -273,7 +273,7 @@ describe NewsPostsController do
273
273
  describe "with invalid params" do
274
274
  it "assigns a newly created but unsaved news_post as @news_post" do
275
275
  post :create, :news_post => @invalid_attrs
276
- assigns(:news_post).should_not be_valid
276
+ assigns(:news_post).should be_nil
277
277
  end
278
278
 
279
279
  it "should be forbidden" do
@@ -1,6 +1,9 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
3
 
4
- enju_leaf
5
- enju_library
4
+ include EnjuLibrary::Controller
5
+ before_action :set_paper_trail_whodunnit
6
+ after_action :verify_authorized
7
+
8
+ include Pundit
6
9
  end
@@ -1,8 +1,7 @@
1
- # -*- encoding: utf-8 -*-
2
1
  class User < ActiveRecord::Base
3
2
  devise :database_authenticatable, #:registerable,
4
3
  :recoverable, :rememberable, :trackable, #, :validatable
5
4
  :lockable, :lock_strategy => :none, :unlock_strategy => :none
6
5
 
7
- enju_leaf_user_model
6
+ include EnjuSeed::EnjuUser
8
7
  end
@@ -2,8 +2,11 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- Bundler.require
6
- require "enju_news"
5
+ Bundler.require(*Rails.groups)
6
+ require 'enju_news'
7
+ require 'enju_leaf'
8
+ require 'globalize'
9
+ require 'globalize-accessors'
7
10
 
8
11
  module Dummy
9
12
  class Application < Rails::Application
@@ -11,16 +14,6 @@ module Dummy
11
14
  # Application configuration should go into files in config/initializers
12
15
  # -- all .rb files in that directory are automatically loaded.
13
16
 
14
- # Custom directories with classes and modules you want to be autoloadable.
15
- # config.autoload_paths += %W(#{config.root}/extras)
16
-
17
- # Only load the plugins named here, in the order given (default is alphabetical).
18
- # :all can be used as a placeholder for all plugins not explicitly named.
19
- # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
20
-
21
- # Activate observers that should always be running.
22
- # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
23
-
24
17
  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
18
  # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
19
  # config.time_zone = 'Central Time (US & Canada)'
@@ -29,18 +22,8 @@ module Dummy
29
22
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
23
  # config.i18n.default_locale = :de
31
24
 
32
- # Configure the default encoding used in templates for Ruby 1.9.
33
- config.encoding = "utf-8"
34
-
35
- # Configure sensitive parameters which will be filtered from the log file.
36
- config.filter_parameters += [:password]
37
-
38
- # Enable the asset pipeline
39
- config.assets.enabled = true
40
-
41
- # Version of your assets, change this if you want to expire all your assets
42
- config.assets.version = '1.0'
25
+ # Do not swallow errors in after_commit/after_rollback callbacks.
26
+ config.active_record.raise_in_transactional_callbacks = true
43
27
  end
44
28
  end
45
29
 
46
- require 'enju_leaf'