Class: Thredded::PrivatePostsController

Inherits:
ApplicationController show all
Includes:
ActionView::RecordIdentifier, NewPrivatePostParams
Defined in:
app/controllers/thredded/private_posts_controller.rb

Overview

A controller for managing PrivatePosts.

Instance Method Summary collapse

Methods included from UrlsHelper

#delete_post_path, #edit_post_path, #edit_preferences_path, #edit_preferences_url, #mark_unread_path, #permalink_path, #post_path, #post_url, #quote_post_path, #search_path, #send_private_message_path, #topic_path, #topic_url, #unread_topics_path, #user_path

Instance Method Details

#createObject



20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/thredded/private_posts_controller.rb', line 20

def create
  @post_form = Thredded::PrivatePostForm.new(
    user: thredded_current_user, topic: parent_topic, post_params: new_private_post_params
  )
  authorize_creating @post_form.post
  if @post_form.save
    redirect_to post_path(@post_form.post, user: thredded_current_user)
  else
    render :new
  end
end

#destroyObject



46
47
48
49
50
51
52
# File 'app/controllers/thredded/private_posts_controller.rb', line 46

def destroy
  authorize post, :destroy?
  post.destroy!

  redirect_back fallback_location: topic_url(topic),
                notice: I18n.t('thredded.posts.deleted_notice')
end

#editObject



32
33
34
35
36
37
# File 'app/controllers/thredded/private_posts_controller.rb', line 32

def edit
  @post_form = Thredded::PrivatePostForm.for_persisted(post)
  authorize @post_form.post, :update?
  return redirect_to(canonical_topic_params) unless params_match?(canonical_topic_params)
  render
end

#mark_as_readObject



54
55
56
57
58
59
60
61
# File 'app/controllers/thredded/private_posts_controller.rb', line 54

def mark_as_read
  authorize post, :read?
  UserPrivateTopicReadState.touch!(thredded_current_user.id, post)
  respond_to do |format|
    format.html { redirect_back fallback_location: post_path(post, user: thredded_current_user) }
    format.json { render(json: { read: true }) }
  end
end

#mark_as_unreadObject



63
64
65
66
67
68
69
70
# File 'app/controllers/thredded/private_posts_controller.rb', line 63

def mark_as_unread
  authorize post, :read?
  post.mark_as_unread(thredded_current_user)
  respond_to do |format|
    format.html { after_mark_as_unread } # customization hook
    format.json { render(json: { read: false }) }
  end
end

#newObject



13
14
15
16
17
18
# File 'app/controllers/thredded/private_posts_controller.rb', line 13

def new
  @post_form = Thredded::PrivatePostForm.new(
    user: thredded_current_user, topic: parent_topic, post_params: new_private_post_params
  )
  authorize_creating @post_form.post
end

#quoteObject



72
73
74
75
# File 'app/controllers/thredded/private_posts_controller.rb', line 72

def quote
  authorize_reading post
  render plain: Thredded::ContentFormatter.quote_content(post.content)
end

#updateObject



39
40
41
42
43
44
# File 'app/controllers/thredded/private_posts_controller.rb', line 39

def update
  authorize post, :update?
  post.update(new_private_post_params)

  redirect_to post_path(post, user: thredded_current_user)
end