Class: Thredded::PrivateTopicsController

Inherits:
ApplicationController show all
Includes:
NewPrivatePostParams, NewPrivateTopicParams
Defined in:
app/controllers/thredded/private_topics_controller.rb

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


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

def create
  @private_topic = Thredded::PrivateTopicForm.new(new_private_topic_params)
  if @private_topic.save
    redirect_to @private_topic.private_topic
  else
    render :new
  end
end

#editObject


55
56
57
58
59
# File 'app/controllers/thredded/private_topics_controller.rb', line 55

def edit
  authorize private_topic, :update?
  return redirect_to(canonical_topic_params) unless params_match?(canonical_topic_params)
  render
end

#indexObject


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/controllers/thredded/private_topics_controller.rb', line 10

def index
  page_scope = Thredded::PrivateTopic
    .distinct
    .for_user(thredded_current_user)
    .order_recently_posted_first
    .send(Kaminari.config.page_method_name, params[:page])
  return redirect_to(last_page_params(page_scope)) if page_beyond_last?(page_scope)
  @private_topics = Thredded::PrivateTopicsPageView.new(thredded_current_user, page_scope)

  Thredded::PrivateTopicForm.new(user: thredded_current_user).tap do |form|
    @new_private_topic = form if policy(form.private_topic).create?
  end
end

#newObject


41
42
43
44
# File 'app/controllers/thredded/private_topics_controller.rb', line 41

def new
  @private_topic = Thredded::PrivateTopicForm.new(new_private_topic_params)
  authorize_creating @private_topic.private_topic
end

#showObject


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/controllers/thredded/private_topics_controller.rb', line 24

def show
  authorize private_topic, :read?
  return redirect_to(canonical_topic_params) unless params_match?(canonical_topic_params)

  page_scope = private_topic
    .posts
    .includes(:user)
    .order_oldest_first
    .send(Kaminari.config.page_method_name, current_page)
  return redirect_to(last_page_params(page_scope)) if page_beyond_last?(page_scope)
  @posts = Thredded::TopicPostsPageView.new(thredded_current_user, private_topic, page_scope)
  Thredded::UserPrivateTopicReadState.touch!(thredded_current_user.id, page_scope.last) if thredded_signed_in?
  @new_post = Thredded::PrivatePostForm.new(
    user: thredded_current_user, topic: private_topic, post_params: new_private_post_params
  )
end

#updateObject


61
62
63
64
65
66
67
68
69
# File 'app/controllers/thredded/private_topics_controller.rb', line 61

def update
  authorize private_topic, :update?
  if private_topic.update(private_topic_params)
    redirect_to private_topic_url(private_topic),
                notice: t('thredded.private_topics.updated_notice')
  else
    render :edit
  end
end