Files

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

154 lines
4.7 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.
#++
class ActivitiesController < ApplicationController
2023-06-21 16:52:52 +02:00
include Layout
menu_item :activity
before_action :warn_if_no_projects_visible,
:load_and_authorize_in_optional_project,
2020-04-27 08:04:28 +02:00
:verify_activities_module_activated,
:determine_subprojects,
2024-02-01 17:31:25 +01:00
:determine_author,
2023-06-21 16:52:52 +02:00
:set_activity
before_action :determine_date_range,
:set_current_activity_page,
only: :index
2020-04-27 08:04:28 +02:00
after_action :set_session
2011-05-30 20:52:25 +02:00
2020-04-27 08:04:28 +02:00
accept_key_auth :index
2014-01-30 09:06:09 +01:00
rescue_from ActiveRecord::RecordNotFound do |exception|
op_handle_warning "Failed to find all resources in activities: #{exception.message}"
render_404(message: I18n.t(:error_can_not_find_all_resources))
end
2020-04-27 08:04:28 +02:00
def index
2023-02-16 15:32:19 +01:00
@events = @activity.events(from: @date_from.to_datetime, to: @date_to.to_datetime)
2019-04-15 13:58:09 +02:00
2019-03-07 09:02:56 +01:00
respond_to do |format|
format.html { respond_html }
format.atom { respond_atom }
end
end
2023-06-21 16:52:52 +02:00
def menu
render layout: nil
end
private
2023-06-21 16:52:52 +02:00
def set_activity
@activity = Activities::Fetcher.new(User.current,
project: @project,
with_subprojects: @with_subprojects,
author: @author,
scope: activity_scope)
end
def verify_activities_module_activated
render_403 if @project && !@project.module_enabled?("activity")
end
2020-04-27 08:04:28 +02:00
def determine_date_range
@days = Setting.activity_days_default.to_i
if params[:from]
2021-02-11 16:02:18 +01:00
begin; @date_to = params[:from].to_date + 1.day; rescue StandardError; end
2020-04-27 08:04:28 +02:00
end
@date_to ||= User.current.today + 1.day
@date_from = @date_to - @days
end
def determine_subprojects
2023-07-20 15:55:53 +02:00
# In OP < 13.0 session[:activity] was an Array.
# If such a session is still present, we need to reset it.
# This line can probably be removed in OP 14.0.
session[:activity] = nil unless session[:activity].is_a?(Hash)
2023-06-21 16:52:52 +02:00
@with_subprojects = if params[:with_subprojects].nil? &&
(session[:activity].nil? || session[:activity][:with_subprojects].nil?)
2020-04-27 08:04:28 +02:00
Setting.display_subprojects_work_packages?
2023-06-21 16:52:52 +02:00
elsif params[:with_subprojects].nil?
session[:activity][:with_subprojects]
2020-04-27 08:04:28 +02:00
else
params[:with_subprojects] == "1"
end
end
def determine_author
@author = params[:user_id].blank? ? nil : User.active.find(params[:user_id])
end
2023-02-16 15:32:19 +01:00
def respond_html
2023-07-08 11:33:39 -05:00
render locals: { menu_name: project_or_global_menu }
2020-04-27 08:04:28 +02:00
end
2023-02-16 15:32:19 +01:00
def respond_atom
2020-04-27 08:04:28 +02:00
title = t(:label_activity)
if @author
title = @author.name
elsif @activity.scope.size == 1
title = t("label_#{@activity.scope.first.singularize}_plural")
end
2023-02-16 15:32:19 +01:00
render_feed(@events, title: "#{@project || Setting.app_title}: #{title}")
end
2014-01-30 09:06:09 +01:00
2020-04-27 08:04:28 +02:00
def activity_scope
if params[:event_types]
params[:event_types]
2014-01-30 09:06:09 +01:00
elsif session[:activity]
2023-06-21 16:52:52 +02:00
session[:activity][:scope]
2020-04-27 08:04:28 +02:00
elsif @author.nil?
:default
2014-01-30 09:06:09 +01:00
else
2020-04-27 08:04:28 +02:00
:all
2014-01-30 09:06:09 +01:00
end
2020-04-27 08:04:28 +02:00
end
2014-01-30 09:06:09 +01:00
def set_current_activity_page
@activity_page = @project ? "projects/#{@project.identifier}" : "all"
end
2020-04-27 08:04:28 +02:00
def set_session
2023-06-21 16:52:52 +02:00
session[:activity] = { scope: @activity.scope,
with_subprojects: @with_subprojects }
2014-01-30 09:06:09 +01:00
end
def warn_if_no_projects_visible
unless current_user.allowed_in_any_project?(:view_project_activity)
render_404(message: I18n.t("homescreen.additional.no_visible_projects"))
end
end
end