enju_bookmark 0.1.3 → 0.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +3 -3
  3. data/app/controllers/bookmark_stats_controller.rb +12 -2
  4. data/app/controllers/bookmarks_controller.rb +12 -6
  5. data/app/controllers/tags_controller.rb +11 -3
  6. data/app/models/bookmark.rb +1 -1
  7. data/app/models/concerns/enju_bookmark/enju_user.rb +19 -0
  8. data/app/policies/bookmark_policy.rb +41 -0
  9. data/app/policies/bookmark_stat_policy.rb +21 -0
  10. data/app/policies/tag_policy.rb +21 -0
  11. data/app/views/bookmarks/_index.html.erb +2 -2
  12. data/app/views/bookmarks/_index_user.html.erb +1 -1
  13. data/app/views/manifestations/_tag_list.html.erb +1 -1
  14. data/config/routes.rb +0 -1
  15. data/lib/enju_bookmark.rb +0 -3
  16. data/lib/enju_bookmark/version.rb +1 -1
  17. data/spec/controllers/bookmark_stats_controller_spec.rb +6 -6
  18. data/spec/controllers/bookmarks_controller_spec.rb +2 -2
  19. data/spec/dummy/app/controllers/application_controller.rb +6 -2
  20. data/spec/dummy/app/models/user.rb +2 -2
  21. data/spec/dummy/config/application.rb +6 -25
  22. data/spec/dummy/config/environments/development.rb +22 -18
  23. data/spec/dummy/config/environments/production.rb +46 -34
  24. data/spec/dummy/config/environments/test.rb +21 -14
  25. data/spec/dummy/config/initializers/enju_leaf.rb +2 -0
  26. data/spec/dummy/db/migrate/20150124152756_add_foreign_key_to_shelves_referencing_libraries.rb +6 -0
  27. data/spec/dummy/db/migrate/20150924115059_create_withdraws.rb +13 -0
  28. data/spec/dummy/db/migrate/20151213070943_add_translation_table_to_library_group.rb +13 -0
  29. data/spec/dummy/db/migrate/20151213072705_add_footer_banner_to_library_group.rb +9 -0
  30. data/spec/dummy/db/schema.rb +138 -114
  31. data/spec/support/devise.rb +2 -2
  32. metadata +82 -46
  33. data/app/controllers/bookmark_stat_has_manifestations_controller.rb +0 -88
  34. data/app/models/enju_bookmark/ability.rb +0 -43
  35. data/lib/enju_bookmark/calculate_stat.rb +0 -30
  36. data/lib/enju_bookmark/user.rb +0 -28
  37. data/spec/dummy/config/application.yml +0 -47
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8480c656a5c124a1c329cdea0f4eabdb6e8f1d53
4
- data.tar.gz: 2b3f19135a4a63652b9a19c8d0a55f5fe9f08f31
3
+ metadata.gz: 7d29d0fddca44893e5562cd0d2d77aafb506b578
4
+ data.tar.gz: 138f6083c430c54cd07f35245481756a927e9662
5
5
  SHA512:
6
- metadata.gz: ab5139d7ac7897c270e880fdea30546e400bc5874509c9b5668fc2296d8cf2c73a2f120806fa512965b8cb8cabde3e7ebc6f5bfaa7b216d1b64cc5ff25204a38
7
- data.tar.gz: 000cd94adda324e68b0f27b4bbd8e38fcd812896e6e2937b093d1bee837b86294eab3e832c5b2c7bc7fa428d8c0b661e1f9b9800db1c28c03cfd6821582e7cd7
6
+ metadata.gz: 8813e85136888ec9663dd34ef615cde96d1e86d9cb0ddb34b75280cdb2518e82ec96bae3fd96d4e44deda65c1ee039419f8113b96873123b3a61a78cc54100cf
7
+ data.tar.gz: a9e1b7ceb5b2d2bda680563d8a5296a4ee61fba9a0f3de401c785bfa268af8d0bf44c7a79e417ef33cf7a8121005dcfc0a0c5141246f47ffd8e65f39aef9d102
@@ -1,7 +1,7 @@
1
1
  = EnjuBookmark
2
- {<img src="https://travis-ci.org/next-l/enju_bookmark.svg?branch=1.1" alt="Build Status" />}[https://travis-ci.org/next-l/enju_bookmark]
3
- {<img src="https://coveralls.io/repos/next-l/enju_bookmark/badge.svg?branch=1.1&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_bookmark?branch=1.1]
4
- {<img src="https://hakiri.io/github/next-l/enju_bookmark/1.1.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_bookmark/1.1]
2
+ {<img src="https://travis-ci.org/next-l/enju_bookmark.svg?branch=1.2" alt="Build Status" />}[https://travis-ci.org/next-l/enju_bookmark]
3
+ {<img src="https://coveralls.io/repos/next-l/enju_bookmark/badge.svg?branch=1.2&service=github" alt="Coverage Status" />}[https://coveralls.io/github/next-l/enju_bookmark?branch=1.2]
4
+ {<img src="https://hakiri.io/github/next-l/enju_bookmark/1.2.svg" alt="security" />}[https://hakiri.io/github/next-l/enju_bookmark/1.2]
5
5
 
6
6
  This project rocks and uses MIT-LICENSE.
7
7
 
@@ -1,6 +1,7 @@
1
1
  class BookmarkStatsController < ApplicationController
2
- load_and_authorize_resource
3
- after_filter :convert_charset, only: :show
2
+ before_action :set_bookmark_stat, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
4
+ after_action :convert_charset, only: :show
4
5
 
5
6
  # GET /bookmark_stats
6
7
  # GET /bookmark_stats.json
@@ -87,6 +88,15 @@ class BookmarkStatsController < ApplicationController
87
88
  end
88
89
 
89
90
  private
91
+ def set_bookmark_stat
92
+ @bookmark_stat = BookmarkStat.find(params[:id])
93
+ authorize @bookmark_stat
94
+ end
95
+
96
+ def check_policy
97
+ authorize BookmarkStat
98
+ end
99
+
90
100
  def bookmark_stat_params
91
101
  params.require(:bookmark_stat).permit(:start_date, :end_date, :note)
92
102
  end
@@ -1,10 +1,7 @@
1
- # -*- encoding: utf-8 -*-
2
1
  class BookmarksController < ApplicationController
3
- before_filter :store_location
4
- load_and_authorize_resource except: :index
5
- authorize_resource only: :index
6
- before_filter :get_user, only: :index
7
- after_filter :solr_commit, only: [:create, :update, :destroy]
2
+ before_action :set_bookmark, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
4
+ before_action :get_user, only: :index
8
5
 
9
6
  # GET /bookmarks
10
7
  # GET /bookmarks.json
@@ -145,6 +142,15 @@ class BookmarksController < ApplicationController
145
142
  end
146
143
 
147
144
  private
145
+ def set_bookmark
146
+ @bookmark = Bookmark.find(params[:id])
147
+ authorize @bookmark
148
+ end
149
+
150
+ def check_policy
151
+ authorize Bookmark
152
+ end
153
+
148
154
  def bookmark_params
149
155
  params.require(:bookmark).permit(:title, :url, :note, :shared, :tag_list)
150
156
  end
@@ -1,7 +1,6 @@
1
1
  class TagsController < ApplicationController
2
- load_and_authorize_resource
3
- before_filter :get_user
4
- after_filter :solr_commit, only: [:create, :update, :destroy]
2
+ before_action :set_tag, only: [:show, :edit, :update, :destroy]
3
+ before_action :check_policy, only: [:index, :new, :create]
5
4
 
6
5
  def index
7
6
  session[:params] ={} unless session[:params]
@@ -71,6 +70,15 @@ class TagsController < ApplicationController
71
70
  end
72
71
 
73
72
  private
73
+ def set_tag
74
+ @tag = Tag.find(params[:id])
75
+ authorize @tag
76
+ end
77
+
78
+ def check_policy
79
+ authorize Tag
80
+ end
81
+
74
82
  def tag_params
75
83
  params.require(:tag).permit(:name, :name_transcription)
76
84
  end
@@ -18,7 +18,7 @@ class Bookmark < ActiveRecord::Base
18
18
  before_save :replace_space_in_tags
19
19
 
20
20
  acts_as_taggable_on :tags
21
- normalize_attributes :url
21
+ strip_attributes only: :url
22
22
 
23
23
  searchable do
24
24
  text :title do
@@ -0,0 +1,19 @@
1
+ module EnjuBookmark
2
+ module EnjuUser
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :bookmarks, :dependent => :destroy
7
+ acts_as_tagger
8
+ end
9
+
10
+ def owned_tags_by_solr
11
+ bookmark_ids = bookmarks.collect(&:id)
12
+ if bookmark_ids.empty?
13
+ []
14
+ else
15
+ Tag.bookmarked(bookmark_ids)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,41 @@
1
+ class BookmarkPolicy < ApplicationPolicy
2
+ def index?
3
+ user.try(:has_role?, 'User')
4
+ end
5
+
6
+ def show?
7
+ case user.try(:role).try(:name)
8
+ when 'Administrator'
9
+ true
10
+ when 'Librarian'
11
+ true
12
+ when 'User'
13
+ if record.user == user
14
+ true
15
+ elsif user.profile.try(:share_bookmarks)
16
+ true
17
+ else
18
+ false
19
+ end
20
+ end
21
+ end
22
+
23
+ def create?
24
+ user.try(:has_role?, 'User')
25
+ end
26
+
27
+ def update?
28
+ case user.try(:role).try(:name)
29
+ when 'Administrator'
30
+ true
31
+ when 'Librarian'
32
+ true
33
+ when 'User'
34
+ true if record.user == user
35
+ end
36
+ end
37
+
38
+ def destroy?
39
+ update?
40
+ end
41
+ end
@@ -0,0 +1,21 @@
1
+ class BookmarkStatPolicy < ApplicationPolicy
2
+ def index?
3
+ true
4
+ end
5
+
6
+ def show?
7
+ true
8
+ end
9
+
10
+ def create?
11
+ user.try(:has_role?, 'Librarian')
12
+ end
13
+
14
+ def update?
15
+ user.try(:has_role?, 'Librarian')
16
+ end
17
+
18
+ def destroy?
19
+ user.try(:has_role?, 'Administrator')
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ class TagPolicy < ApplicationPolicy
2
+ def index?
3
+ true
4
+ end
5
+
6
+ def show?
7
+ true
8
+ end
9
+
10
+ def create?
11
+ user.try(:has_role?, 'Librarian')
12
+ end
13
+
14
+ def update?
15
+ user.try(:has_role?, 'Librarian')
16
+ end
17
+
18
+ def destroy?
19
+ user.try(:has_role?, 'Librarian')
20
+ end
21
+ end
@@ -27,8 +27,8 @@
27
27
  </td>
28
28
  <td><%= l(bookmark.created_at) -%></td>
29
29
  <td>
30
- <%- if can? :delete, bookmark -%>
31
- <%= link_to t('page.show'), bookmark_path(bookmark) -%>
30
+ <%= link_to t('page.show'), bookmark_path(bookmark) -%>
31
+ <%- if policy(bookmark).destroy? -%>
32
32
  <%= link_to t('page.destroy'), bookmark_path(bookmark), data: {confirm: t('page.are_you_sure')}, method: :delete -%>
33
33
  <%- end -%>
34
34
  </td>
@@ -30,7 +30,7 @@
30
30
  </td>
31
31
  <td><%= l(bookmark.created_at) -%></td>
32
32
  <td>
33
- <%- if can? :delete, bookmark -%>
33
+ <%- if policy(bookmark).destroy? -%>
34
34
  <%= link_to t('page.destroy'), bookmark, data: {confirm: t('page.are_you_sure')}, method: :delete -%>
35
35
  <%- end -%>
36
36
  </td>
@@ -2,7 +2,7 @@
2
2
  <%- if manifestation.tags -%>
3
3
  <%- manifestation.tags.each do |tag| -%>
4
4
  <%= link_to_tag(tag) -%>
5
- <%- if can? :delete, tag -%>
5
+ <%- if policy(tag).destroy? -%>
6
6
  <%= link_to image_tag('icons/tag_blue_edit.png', alt: t('page.edit')), tag_path(tag.name) -%>
7
7
  <%- end -%>
8
8
  <%- end -%>
@@ -2,5 +2,4 @@ Rails.application.routes.draw do
2
2
  resources :bookmarks
3
3
  resources :tags
4
4
  resources :bookmark_stats
5
- resources :bookmark_stat_has_manifestations
6
5
  end
@@ -1,9 +1,7 @@
1
1
  require "enju_bookmark/engine"
2
- require "enju_bookmark/user"
3
2
  require "enju_bookmark/profile"
4
3
  require "enju_bookmark/manifestation"
5
4
  require "enju_bookmark/bookmark_url"
6
- require "enju_bookmark/calculate_stat"
7
5
  require "enju_bookmark/expire_tag_cloud"
8
6
  require "enju_bookmark/bookmark_helper"
9
7
  #require "enju_bookmark/suggest_tag"
@@ -11,6 +9,5 @@ require "enju_bookmark/bookmark_helper"
11
9
  module EnjuBookmark
12
10
  end
13
11
 
14
- ActiveRecord::Base.send :include, EnjuBookmark::BookmarkUser
15
12
  ActiveRecord::Base.send :include, EnjuBookmark::BookmarkProfile
16
13
  ActiveRecord::Base.send :include, EnjuBookmark::BookmarkManifestation
@@ -1,3 +1,3 @@
1
1
  module EnjuBookmark
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0.beta.1"
3
3
  end
@@ -109,7 +109,7 @@ describe BookmarkStatsController do
109
109
 
110
110
  it "should not assign the requested bookmark_stat as @bookmark_stat" do
111
111
  get :new
112
- expect(assigns(:bookmark_stat)).not_to be_valid
112
+ expect(assigns(:bookmark_stat)).to be_nil
113
113
  expect(response).to be_forbidden
114
114
  end
115
115
  end
@@ -117,7 +117,7 @@ describe BookmarkStatsController do
117
117
  describe "When not logged in" do
118
118
  it "should not assign the requested bookmark_stat as @bookmark_stat" do
119
119
  get :new
120
- expect(assigns(:bookmark_stat)).not_to be_valid
120
+ expect(assigns(:bookmark_stat)).to be_nil
121
121
  expect(response).to redirect_to(new_user_session_url)
122
122
  end
123
123
  end
@@ -231,7 +231,7 @@ describe BookmarkStatsController do
231
231
  describe "with valid params" do
232
232
  it "assigns a newly created bookmark_stat as @bookmark_stat" do
233
233
  post :create, :bookmark_stat => @attrs
234
- expect(assigns(:bookmark_stat)).to be_valid
234
+ expect(assigns(:bookmark_stat)).to be_nil
235
235
  end
236
236
 
237
237
  it "should be forbidden" do
@@ -243,7 +243,7 @@ describe BookmarkStatsController do
243
243
  describe "with invalid params" do
244
244
  it "assigns a newly created but unsaved bookmark_stat as @bookmark_stat" do
245
245
  post :create, :bookmark_stat => @invalid_attrs
246
- expect(assigns(:bookmark_stat)).not_to be_valid
246
+ expect(assigns(:bookmark_stat)).to be_nil
247
247
  end
248
248
 
249
249
  it "should be forbidden" do
@@ -257,7 +257,7 @@ describe BookmarkStatsController do
257
257
  describe "with valid params" do
258
258
  it "assigns a newly created bookmark_stat as @bookmark_stat" do
259
259
  post :create, :bookmark_stat => @attrs
260
- expect(assigns(:bookmark_stat)).to be_valid
260
+ expect(assigns(:bookmark_stat)).to be_nil
261
261
  end
262
262
 
263
263
  it "should be forbidden" do
@@ -269,7 +269,7 @@ describe BookmarkStatsController do
269
269
  describe "with invalid params" do
270
270
  it "assigns a newly created but unsaved bookmark_stat as @bookmark_stat" do
271
271
  post :create, :bookmark_stat => @invalid_attrs
272
- expect(assigns(:bookmark_stat)).not_to be_valid
272
+ expect(assigns(:bookmark_stat)).to be_nil
273
273
  end
274
274
 
275
275
  it "should be forbidden" do
@@ -287,7 +287,7 @@ describe BookmarksController do
287
287
  describe "with valid params" do
288
288
  it "assigns a newly created bookmark as @bookmark" do
289
289
  post :create, :bookmark => @attrs
290
- expect(assigns(:bookmark)).not_to be_valid
290
+ expect(assigns(:bookmark)).to be_nil
291
291
  end
292
292
 
293
293
  it "should be forbidden" do
@@ -299,7 +299,7 @@ describe BookmarksController do
299
299
  describe "with invalid params" do
300
300
  it "assigns a newly created but unsaved bookmark as @bookmark" do
301
301
  post :create, :bookmark => @invalid_attrs
302
- expect(assigns(:bookmark)).not_to be_valid
302
+ expect(assigns(:bookmark)).to be_nil
303
303
  end
304
304
 
305
305
  it "should be forbidden" do
@@ -1,6 +1,10 @@
1
1
  class ApplicationController < ActionController::Base
2
2
  protect_from_forgery
3
+ include EnjuLeaf::Controller
4
+ include EnjuBiblio::Controller
5
+ include EnjuLibrary::Controller
6
+ before_action :set_paper_trail_whodunnit
7
+ after_action :verify_authorized
3
8
 
4
- enju_leaf
5
- enju_library
9
+ include Pundit
6
10
  end
@@ -4,6 +4,6 @@ class User < ActiveRecord::Base
4
4
  :recoverable, :rememberable, :trackable, #, :validatable
5
5
  :lockable, :lock_strategy => :none, :unlock_strategy => :none
6
6
 
7
- enju_leaf_user_model
8
- enju_bookmark_user_model
7
+ include EnjuLeaf::EnjuUser
8
+ include EnjuBookmark::EnjuUser
9
9
  end
@@ -2,8 +2,10 @@ require File.expand_path('../boot', __FILE__)
2
2
 
3
3
  require 'rails/all'
4
4
 
5
- Bundler.require
6
- require "enju_bookmark"
5
+ Bundler.require(*Rails.groups)
6
+ require 'enju_bookmark'
7
+ require 'enju_leaf'
8
+ require 'enju_circulation'
7
9
 
8
10
  module Dummy
9
11
  class Application < Rails::Application
@@ -11,16 +13,6 @@ module Dummy
11
13
  # Application configuration should go into files in config/initializers
12
14
  # -- all .rb files in that directory are automatically loaded.
13
15
 
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
16
  # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
17
  # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
18
  # config.time_zone = 'Central Time (US & Canada)'
@@ -29,19 +21,8 @@ module Dummy
29
21
  # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
22
  # config.i18n.default_locale = :de
31
23
 
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'
24
+ # Do not swallow errors in after_commit/after_rollback callbacks.
25
+ config.active_record.raise_in_transactional_callbacks = true
43
26
  end
44
27
  end
45
28
 
46
- require 'enju_leaf'
47
- require 'enju_circulation'
@@ -1,37 +1,41 @@
1
- Dummy::Application.configure do
2
- # Settings specified here will take precedence over those in config/application.rb
1
+ Rails.application.configure do
2
+ # Settings specified here will take precedence over those in config/application.rb.
3
3
 
4
4
  # In the development environment your application's code is reloaded on
5
5
  # every request. This slows down response time but is perfect for development
6
6
  # since you don't have to restart the web server when you make code changes.
7
7
  config.cache_classes = false
8
8
 
9
- # Log error messages when you accidentally call methods on nil.
10
- config.whiny_nils = true
9
+ # Do not eager load code on boot.
10
+ config.eager_load = false
11
11
 
12
- # Show full error reports and disable caching
12
+ # Show full error reports and disable caching.
13
13
  config.consider_all_requests_local = true
14
14
  config.action_controller.perform_caching = false
15
15
 
16
- # Don't care if the mailer can't send
16
+ # Don't care if the mailer can't send.
17
17
  config.action_mailer.raise_delivery_errors = false
18
18
 
19
- # Print deprecation notices to the Rails logger
19
+ # Print deprecation notices to the Rails logger.
20
20
  config.active_support.deprecation = :log
21
21
 
22
- # Only use best-standards-support built into browsers
23
- config.action_dispatch.best_standards_support = :builtin
22
+ # Raise an error on page load if there are pending migrations.
23
+ config.active_record.migration_error = :page_load
24
24
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
25
+ # Debug mode disables concatenation and preprocessing of assets.
26
+ # This option may cause significant delays in view rendering with a large
27
+ # number of complex assets.
28
+ config.assets.debug = true
27
29
 
28
- # Log the query plan for queries taking more than this (works
29
- # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
30
+ # Asset digests allow you to set far-future HTTP expiration dates on all assets,
31
+ # yet still be able to expire them through the digest params.
32
+ config.assets.digest = true
31
33
 
32
- # Do not compress assets
33
- config.assets.compress = false
34
+ # Adds additional error checking when serving assets at runtime.
35
+ # Checks for improperly declared sprockets dependencies.
36
+ # Raises helpful error messages.
37
+ config.assets.raise_runtime_errors = true
34
38
 
35
- # Expands the lines which load the assets
36
- config.assets.debug = true
39
+ # Raises error for missing translations
40
+ # config.action_view.raise_on_missing_translations = true
37
41
  end