Class: Course::Discussion::PostsController

Inherits:
ComponentController show all
Includes:
PostsConcern
Defined in:
app/controllers/course/discussion/posts_controller.rb

Instance Method Summary collapse

Methods included from PostsConcern

#skip_update_topic_status, #update_topic_pending_status

Methods included from ApplicationSignInCallbacksConcern

#sign_in

Methods included from ApplicationPaginationConcern

#page_param

Methods included from ApplicationAnnouncementsConcern

#global_announcements, #unread_global_announcements

Methods included from ApplicationInstanceUserConcern

#current_instance_user

Methods included from ApplicationUserTimeZoneConcern

#set_time_zone

Methods included from ApplicationUserConcern

#handle_access_denied, #publicly_accessible?

Methods included from ApplicationComponentsConcern

#handle_component_not_found

Instance Method Details

#createObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/course/discussion/posts_controller.rb', line 9

def create
  result = @post.transaction do
    # Set parent as the topologically last pre-existing post, if it exists.
    # @post is in @topic.posts, so we filter out @post, which has no id yet.
    if @topic.posts.length > 1
      @post.parent = @topic.posts.ordered_topologically.flatten.select(&:id).last
    end
    raise ActiveRecord::Rollback unless @post.save && create_topic_subscription && update_topic_pending_status
    true
  end

  if result
    send_created_notification(@post)
    respond_to do |format|
      format.js
      format.json { render @post }
    end
  else
    head :bad_request
  end
end

#create_topic_subscriptionObject (protected)


59
60
61
# File 'app/controllers/course/discussion/posts_controller.rb', line 59

def create_topic_subscription
  @topic.ensure_subscribed_by(current_user)
end

#destroyObject


42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/course/discussion/posts_controller.rb', line 42

def destroy
  if @post.destroy
    respond_to do |format|
      format.js
      format.json { head :ok }
    end
  else
    head :bad_request
  end
end

#discussion_topicObject (protected)


55
56
57
# File 'app/controllers/course/discussion/posts_controller.rb', line 55

def discussion_topic
  @topic
end

#updateObject


31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/course/discussion/posts_controller.rb', line 31

def update
  if @post.update_attributes(post_params)
    respond_to do |format|
      format.js
      format.json { render @post }
    end
  else
    head :bad_request
  end
end