Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

137 lines
3.8 KiB
Ruby
Raw Permalink Normal View History

2025-07-18 17:36:37 +01:00
# frozen_string_literal: true
#-- copyright
2020-01-15 11:31:26 +01:00
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
2011-05-30 20:52:25 +02:00
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
2011-05-30 20:52:25 +02:00
#
2013-09-16 17:59:31 +02:00
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
2021-01-13 17:47:45 +01:00
# Copyright (C) 2006-2013 Jean-Philippe Lang
2013-09-16 17:59:31 +02:00
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
2019-03-12 10:34:45 +01:00
class ForumsController < ApplicationController
2009-10-21 17:07:18 +00:00
default_search_scope :messages
2026-02-02 17:51:48 +01:00
before_action :find_project_by_project_id
2019-03-12 10:34:45 +01:00
before_action :new_forum, only: %i[new create]
before_action :find_forum, only: %i[show edit update move destroy]
2026-02-02 17:51:48 +01:00
before_action :authorize
2019-08-20 08:09:55 +02:00
accept_key_auth :show
2007-05-13 17:09:56 +00:00
include SortHelper
2013-06-19 16:16:26 +02:00
include PaginationHelper
2011-05-30 20:52:25 +02:00
2007-05-13 17:09:56 +00:00
def index
2019-03-12 10:34:45 +01:00
@forums = @project.forums
2007-05-13 17:09:56 +00:00
end
current_menu_item [:index, :show] do
2019-03-12 10:34:45 +01:00
:forums
end
2026-02-09 15:26:41 +01:00
def show # rubocop:disable Metrics/AbcSize
2020-12-03 12:00:19 +01:00
sort_init "updated_at", "desc"
sort_update "created_at" => "#{Message.table_name}.created_at",
2014-03-19 09:13:27 +01:00
"replies" => "#{Message.table_name}.replies_count",
2020-12-03 12:00:19 +01:00
"updated_at" => "#{Message.table_name}.updated_at"
2014-03-19 09:13:27 +01:00
2009-04-24 16:51:07 +00:00
respond_to do |format|
format.html do
2014-04-30 15:36:24 +02:00
set_topics
2009-04-24 16:51:07 +00:00
@message = Message.new
2014-11-03 21:10:20 +01:00
render action: "show", layout: !request.xhr?
end
2026-02-02 17:51:48 +01:00
# The JSON template does not exist anymore, this never rendered
# format.json do
# set_topics
# render template: "messages/index"
# end
format.atom do
2019-03-12 10:34:45 +01:00
@messages = @forum
2018-07-09 13:12:45 +02:00
.messages
.order(["#{Message.table_name}.sticked_on ASC", sort_clause].compact.join(", "))
2019-03-12 10:34:45 +01:00
.includes(:author, :forum)
.limit(Setting.feeds_limit.to_i)
2013-06-19 16:16:26 +02:00
2019-03-12 10:34:45 +01:00
render_feed(@messages, title: "#{@project}: #{@forum}")
end
2009-04-24 16:51:07 +00:00
end
2007-05-13 17:09:56 +00:00
end
2011-05-30 20:52:25 +02:00
2014-04-30 15:36:24 +02:00
def set_topics
2019-03-12 10:34:45 +01:00
@topics = @forum
2018-07-09 13:12:45 +02:00
.topics
.order(["#{Message.table_name}.sticked_on ASC", sort_clause].compact.join(", "))
.includes(:author, last_reply: :author)
2019-01-09 08:46:59 +01:00
.page(page_param)
.per_page(per_page_param)
2014-04-30 15:36:24 +02:00
end
2018-07-09 13:12:45 +02:00
def new; end
2012-08-09 16:41:00 +02:00
2023-03-09 10:25:57 +01:00
def edit; end
2012-08-09 16:41:00 +02:00
def create
2019-03-12 10:34:45 +01:00
if @forum.save
2020-09-16 11:26:15 +02:00
flash[:notice] = I18n.t(:notice_successful_create)
2026-02-02 17:51:48 +01:00
redirect_to project_forums_path(@project)
else
render :new
2007-05-13 17:09:56 +00:00
end
end
2012-08-09 16:41:00 +02:00
def update
2019-09-20 08:34:51 +02:00
if @forum.update(permitted_params.forum)
2020-09-16 11:26:15 +02:00
flash[:notice] = I18n.t(:notice_successful_update)
2026-02-02 17:51:48 +01:00
redirect_to project_forums_path(@project)
else
2026-02-02 17:51:48 +01:00
render :edit, status: :unprocessable_entity
2007-05-13 17:09:56 +00:00
end
end
2013-10-31 08:12:37 +01:00
def move
2026-02-02 17:51:48 +01:00
@forum.update!(permitted_params.forum_move)
flash[:notice] = t(:notice_successful_update)
redirect_to project_forums_path(@project)
2013-10-31 08:12:37 +01:00
end
2007-05-13 17:09:56 +00:00
def destroy
2026-02-02 17:51:48 +01:00
@forum.destroy!
2020-09-16 11:26:15 +02:00
flash[:notice] = I18n.t(:notice_successful_delete)
2026-04-22 16:44:50 +02:00
redirect_to project_forums_path(@project), status: :see_other
2007-05-13 17:09:56 +00:00
end
2011-05-30 20:52:25 +02:00
private
2019-03-12 10:34:45 +01:00
def find_forum
@forum = @project.forums.find(params[:id])
2007-05-13 17:09:56 +00:00
end
2013-10-21 18:22:19 +02:00
2019-03-12 10:34:45 +01:00
def new_forum
@forum = Forum.new(permitted_params.forum?)
@forum.project = @project
2013-10-21 18:22:19 +02:00
end
2007-05-13 17:09:56 +00:00
end