2014-03-23 00:22:25 +00:00
|
|
|
class ForumsController < ApplicationController
|
2020-03-16 23:57:47 +00:00
|
|
|
before_action :get_forum, only: [:show, :edit, :update, :up, :down, :destroy]
|
2014-05-02 16:43:23 +00:00
|
|
|
layout 'forums'
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def index
|
|
|
|
@categories = Category.domain(Category::DOMAIN_FORUMS).ordered
|
|
|
|
@nobody = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
raise AccessError unless @forum.can_show? cuser
|
2014-04-13 11:16:51 +00:00
|
|
|
|
|
|
|
@topics = Topic.where(forum_id: @forum.id)
|
2014-08-10 19:41:05 +00:00
|
|
|
.joins(posts: :user)
|
2020-03-16 01:08:21 +00:00
|
|
|
.includes(:lock)
|
2014-04-13 11:16:51 +00:00
|
|
|
.group('topics.id')
|
2014-08-10 19:41:05 +00:00
|
|
|
.order('state DESC, (SELECT created_at FROM posts p2 WHERE p2.topic_id = topics.id ORDER BY created_at DESC LIMIT 1) DESC')
|
2014-04-13 11:16:51 +00:00
|
|
|
.paginate(page: params[:page], per_page: 30)
|
|
|
|
|
2020-03-15 18:31:00 +00:00
|
|
|
@forum.mark_as_read! for: cuser if cuser
|
2014-03-23 00:22:25 +00:00
|
|
|
@nobody = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@forum = Forum.new
|
|
|
|
raise AccessError unless @forum.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @forum.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@forum = Forum.new(params[:forum])
|
|
|
|
raise AccessError unless @forum.can_create? cuser
|
|
|
|
|
|
|
|
if @forum.save
|
|
|
|
flash[:notice] = t(:forums_create)
|
|
|
|
redirect_to(@forum)
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :new
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
raise AccessError unless @forum.can_update? cuser
|
|
|
|
if @forum.update_attributes(params[:forum])
|
|
|
|
flash[:notice] = t(:forums_update)
|
|
|
|
redirect_to(@forum)
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def up
|
|
|
|
raise AccessError unless @forum.can_update? cuser
|
2014-04-12 01:35:42 +00:00
|
|
|
@forum.move_up(category_id: @forum.category.id)
|
2014-03-23 00:22:25 +00:00
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
|
|
|
|
def down
|
|
|
|
raise AccessError unless @forum.can_update? cuser
|
2014-04-12 01:35:42 +00:00
|
|
|
@forum.move_down(category_id: @forum.category.id)
|
2014-03-23 00:22:25 +00:00
|
|
|
redirect_to_back
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @forum.can_destroy? cuser
|
|
|
|
@forum.destroy
|
|
|
|
redirect_to(forums_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_forum
|
|
|
|
@forum = Forum.find(params[:id])
|
|
|
|
end
|
|
|
|
end
|