2014-03-23 00:22:25 +00:00
|
|
|
class PostsController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_post, except: [:new, :create]
|
2014-03-23 00:22:25 +00:00
|
|
|
respond_to :html, :js
|
2014-04-20 01:29:52 +00:00
|
|
|
layout 'forums'
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def quote
|
|
|
|
raise AccessError unless @post.can_show? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@post = Post.new
|
|
|
|
@post.topic = Topic.find(params[:id])
|
|
|
|
raise AccessError unless @post.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @post.can_update? cuser
|
2014-03-31 21:33:16 +00:00
|
|
|
render layout: 'forums'
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2020-03-18 03:38:17 +00:00
|
|
|
@post = Post.new(Post.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
@post.user = cuser
|
|
|
|
raise AccessError unless @post.can_create? cuser
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
if @post.save
|
|
|
|
flash[:notice] = t(:posts_create)
|
|
|
|
format.js { render }
|
2014-04-27 02:11:47 +00:00
|
|
|
format.html { return_to }
|
2014-03-23 00:22:25 +00:00
|
|
|
else
|
2014-04-20 01:29:52 +00:00
|
|
|
format.html { render :new }
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @post.can_update? cuser, params[:post]
|
2020-03-18 03:38:17 +00:00
|
|
|
if @post.update_attributes(Post.params(params, cuser))
|
2014-03-23 00:22:25 +00:00
|
|
|
flash[:notice] = t(:posts_update)
|
|
|
|
redirect_to @post.topic
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def trash
|
|
|
|
raise AccessError unless @post.can_destroy? cuser
|
|
|
|
@post.trash
|
2020-03-18 21:23:30 +00:00
|
|
|
if @post.topic.exists?
|
2014-03-23 00:22:25 +00:00
|
|
|
redirect_to @post.topic
|
|
|
|
else
|
|
|
|
redirect_to @post.topic.forum
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @post.can_destroy? cuser
|
|
|
|
@post.destroy
|
2020-03-18 21:23:30 +00:00
|
|
|
if @post.topic.exists?
|
2014-03-23 00:22:25 +00:00
|
|
|
redirect_to @post.topic
|
|
|
|
else
|
|
|
|
redirect_to @post.topic.forum
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_post
|
|
|
|
@post = Post.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|