thredded 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16d3cfd85997b2495d072774e55f3c491824d21b
4
- data.tar.gz: 0adb8511cd83a9ab1f7c5c0275d30778f466e8c9
3
+ metadata.gz: 7c2929ae0328e4fd8c0faf14a7dbd5ba4a1bd4b3
4
+ data.tar.gz: 50f7bb4efdbdf97b372ceb9da07ef6b6bf6aa692
5
5
  SHA512:
6
- metadata.gz: 7e10056d0888670f993b7b3ee062e8a8214d2c72f7c4da9d2b91d55c5faf664f6d7677d54a0f655739883e1cdf28e707a78dfa70a28c5fc4250333d622f1cee2
7
- data.tar.gz: cbd651748b820ab011e19c4af9586910906d26a4a5fe0574284a7eced94383be631adea6a30e2a3527979ab239e9f2845c6645a409e79bcd0b330398fd6b5ca6
6
+ metadata.gz: a1c7d85da251177d9c62120f40281e2710a4e9c61c5622e998dd47179ac75aa5f60651176fefdc50adc787de144da33868c525c8c88fc3193095fd0278a6cd8c
7
+ data.tar.gz: 15cc242a83c68ac14700c019bc59624a64260f43d0510b5bd234e43ab322b983f30a283b1170b70285bbc39be95f78c5da8cf699d412de4f986cf750d4489468
@@ -2,10 +2,13 @@ module Thredded
2
2
  class ApplicationController < ::ApplicationController
3
3
  helper Thredded::Engine.helpers
4
4
  helper_method :messageboard, :topic, :preferences
5
- before_filter :update_user_activity
6
5
 
7
6
  rescue_from CanCan::AccessDenied do |exception|
8
- redirect_to root_path, alert: exception.message
7
+ redirect_to thredded.root_path, alert: exception.message
8
+ end
9
+
10
+ rescue_from Thredded::Errors::MessageboardNotFound do |exception|
11
+ redirect_to thredded.root_path, alert: exception.message
9
12
  end
10
13
 
11
14
  private
@@ -21,9 +24,7 @@ module Thredded
21
24
  end
22
25
 
23
26
  def messageboard
24
- if params.key? :messageboard_id
25
- @messageboard ||= Messageboard.where(slug: params[:messageboard_id]).first
26
- end
27
+ @messageboard ||= Messageboard.find_by_slug(params[:messageboard_id])
27
28
  end
28
29
 
29
30
  def preferences
@@ -37,12 +38,5 @@ module Thredded
37
38
  @topic ||= messageboard.topics.find(params[:topic_id])
38
39
  end
39
40
  end
40
-
41
- def ensure_messageboard_exists
42
- if messageboard.blank?
43
- redirect_to thredded.root_path,
44
- flash: { error: 'This messageboard does not exist.' }
45
- end
46
- end
47
41
  end
48
42
  end
@@ -1,7 +1,5 @@
1
1
  module Thredded
2
2
  class MessageboardsController < Thredded::ApplicationController
3
- before_filter :messageboard, only: :show
4
-
5
3
  def index
6
4
  @messageboards = Messageboard.where(closed: false).decorate
7
5
  end
@@ -2,10 +2,10 @@ module Thredded
2
2
  class PostsController < Thredded::ApplicationController
3
3
  load_and_authorize_resource only: [:index, :show]
4
4
  helper_method :messageboard, :topic, :user_topic
5
+ before_filter :update_user_activity
5
6
 
6
7
  rescue_from Thredded::Errors::TopicNotFound do |exception|
7
- redirect_to messageboard_topics_path(messageboard),
8
- alert: 'This topic does not exist.'
8
+ redirect_to messageboard_topics_path(messageboard), alert: exception.message
9
9
  end
10
10
 
11
11
  def index
@@ -1,7 +1,5 @@
1
1
  module Thredded
2
2
  class PrivateTopicsController < Thredded::ApplicationController
3
- before_filter :ensure_messageboard_exists
4
-
5
3
  def index
6
4
  if cannot? :read, messageboard
7
5
  error = 'You are not authorized access to this messageboard.'
@@ -1,7 +1,7 @@
1
1
  module Thredded
2
2
  class TopicsController < Thredded::ApplicationController
3
- before_filter :ensure_messageboard_exists
4
3
  helper_method :current_page
4
+ before_filter :update_user_activity
5
5
 
6
6
  def index
7
7
  if cannot? :read, messageboard
@@ -5,15 +5,10 @@ module Thredded
5
5
  FILTERS = %w{markdown bbcode}
6
6
 
7
7
  extend FriendlyId
8
- friendly_id :name
8
+ friendly_id :name, use: :slugged
9
9
 
10
10
  validates :filter, presence: true
11
11
  validates :filter, inclusion: { in: FILTERS }
12
- validates :name, format: {
13
- with: /\A[\w\-]+\z/,
14
- on: :create,
15
- message: 'should be letters, nums, dash, underscore only.'
16
- }
17
12
  validates :name, length: {
18
13
  within: 1..16,
19
14
  message: 'should be between 1 and 16 characters'
@@ -32,6 +27,14 @@ module Thredded
32
27
  has_many :private_topics
33
28
  has_many :users, through: :roles, class_name: Thredded.user_class
34
29
 
30
+ def self.find_by_slug(slug)
31
+ begin
32
+ friendly.find(slug)
33
+ rescue ActiveRecord::RecordNotFound
34
+ raise Thredded::Errors::MessageboardNotFound
35
+ end
36
+ end
37
+
35
38
  def self.default_scope
36
39
  where(closed: false).order('topics_count DESC')
37
40
  end
@@ -15,7 +15,7 @@ Thredded::Engine.routes.draw do
15
15
  get '/:messageboard_id/preferences/edit' => 'preferences#edit'
16
16
  get '/:messageboard_id/new(.:format)' => 'topics#new', as: :new_messageboard_topic
17
17
  get '/:messageboard_id/:id/edit(.:format)' => 'topics#edit', as: :edit_messageboard_topic
18
- get '/:messageboard_id/:topic_id/:page(.:format)' => 'posts#index',
18
+ get '/:messageboard_id/:topic_id/page-:page(.:format)' => 'posts#index',
19
19
  as: :paged_messageboard_topic_posts, constraints: { page: /\d+/ }
20
20
 
21
21
  resources :messageboards, only: [:index], path: '' do
@@ -3,6 +3,16 @@ module Thredded
3
3
  end
4
4
 
5
5
  module Errors
6
- class TopicNotFound < Thredded::Error; end
6
+ class TopicNotFound < Thredded::Error
7
+ def message
8
+ 'This topic does not exist.'
9
+ end
10
+ end
11
+
12
+ class MessageboardNotFound < Thredded::Error
13
+ def message
14
+ 'This messageboard does not exist.'
15
+ end
16
+ end
7
17
  end
8
18
  end
@@ -1,3 +1,3 @@
1
1
  module Thredded
2
- VERSION = '0.0.7'
2
+ VERSION = '0.0.8'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thredded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel Oliveira
@@ -516,7 +516,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
516
516
  version: '0'
517
517
  requirements: []
518
518
  rubyforge_project:
519
- rubygems_version: 2.0.7
519
+ rubygems_version: 2.1.10
520
520
  signing_key:
521
521
  specification_version: 4
522
522
  summary: A forum engine