Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Display project activities in activity page

Christophe Bliardb0d583a95e26
diff --git a/app/models/activities/base_activity_provider.rb b/app/models/activities/base_activity_provider.rb
index 7ec7be02148..ed3a372f0c4 100644
--- a/app/models/activities/base_activity_provider.rb
+++ b/app/models/activities/base_activity_provider.rb
@@ -138,7 +138,7 @@ class Activities::BaseActivityProvider
def apply_event_projection(query)
projection = event_projection
- projection << event_query_projection if respond_to?(:event_query_projection)
+ projection += event_query_projection
query.project(projection)
end
diff --git a/app/models/activities/project_activity_provider.rb b/app/models/activities/project_activity_provider.rb
new file mode 100644
index 00000000000..e481c91dd1d
--- /dev/null
+++ b/app/models/activities/project_activity_provider.rb
@@ -0,0 +1,58 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2013 Jean-Philippe Lang
+# 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 Activities::ProjectActivityProvider < Activities::BaseActivityProvider
+ activity_provider_for type: 'projects',
+ permission: :view_project
+
+ def event_query_projection
+ [
+ projection_statement(journals_table, :journable_id, 'project_id'),
+ projection_statement(projects_table, :identifier, 'project_identifier'),
+ projection_statement(projects_table, :name, 'project_name')
+ ]
+ end
+
+ protected
+
+ def join_with_projects_table(query)
+ query.join(projects_table).on(projects_table[:id].eq(journals_table['journable_id']))
+ end
+
+ def event_title(event)
+ I18n.t('events.title.project', name: event['project_name'])
+ end
+
+ def event_path(event)
+ url_helpers.project_path(event['project_identifier'])
+ end
+
+ def event_url(event)
+ url_helpers.project_url(event['project_identifier'])
+ end
+end
diff --git a/app/models/projects/activity.rb b/app/models/projects/activity.rb
index 02c103ea8fa..750d2433c63 100644
--- a/app/models/projects/activity.rb
+++ b/app/models/projects/activity.rb
@@ -37,7 +37,8 @@ module Projects::Activity
OpenProject::ProjectLatestActivity.registered.map do |params|
build_latest_project_activity_for(on: params[:on].constantize,
chain: Array(params[:chain]).map(&:constantize),
- attribute: params[:attribute])
+ attribute: params[:attribute],
+ project_id_attribute: params[:project_id_attribute])
end
end
@@ -60,14 +61,14 @@ module Projects::Activity
latest_project_activity.join(' UNION ALL ')
end
- def build_latest_project_activity_for(on:, chain:, attribute:)
+ def build_latest_project_activity_for(on:, chain:, attribute:, project_id_attribute:)
join_chain = Array(chain).dup.push(on)
from = join_chain.first
joins = build_joins_from_chain(join_chain)
<<-SQL
- SELECT project_id, MAX(#{on.table_name}.#{attribute}) updated_at
+ SELECT #{project_id_attribute} project_id, MAX(#{on.table_name}.#{attribute}) updated_at
FROM #{from.table_name}
#{joins.join(' ')}
WHERE #{on.table_name}.#{attribute} IS NOT NULL
diff --git a/config/constants/open_project/project_latest_activity.rb b/config/constants/open_project/project_latest_activity.rb
index 404d99d5e39..537f1f2c654 100644
--- a/config/constants/open_project/project_latest_activity.rb
+++ b/config/constants/open_project/project_latest_activity.rb
@@ -27,12 +27,13 @@
module OpenProject
module ProjectLatestActivity
class << self
- def register(on:, attribute:, chain: [])
+ def register(on:, attribute:, chain: [], project_id_attribute: :project_id)
@registered ||= Set.new
- @registered << { on: on,
- chain: chain,
- attribute: attribute }
+ @registered << { on:,
+ chain:,
+ attribute:,
+ project_id_attribute: }
end
attr_reader :registered
diff --git a/config/initializers/activity.rb b/config/initializers/activity.rb
index 451eedd1b21..7fa006959c9 100644
--- a/config/initializers/activity.rb
+++ b/config/initializers/activity.rb
@@ -31,6 +31,7 @@ require_relative '../constants/open_project/project_latest_activity'
Rails.application.reloader.to_prepare do
OpenProject::Activity.map do |activity|
activity.register :work_packages, class_name: '::Activities::WorkPackageActivityProvider'
+ activity.register :projects, class_name: 'Activities::ProjectActivityProvider'
activity.register :changesets, class_name: 'Activities::ChangesetActivityProvider'
activity.register :news, class_name: 'Activities::NewsActivityProvider',
default: false
@@ -43,13 +44,17 @@ Rails.application.reloader.to_prepare do
OpenProject::ProjectLatestActivity.register on: 'WorkPackage',
attribute: :updated_at
- OpenProject::ProjectLatestActivity.register on: 'News',
- attribute: :updated_at
+ OpenProject::ProjectLatestActivity.register on: 'Project',
+ attribute: :updated_at,
+ project_id_attribute: :id
OpenProject::ProjectLatestActivity.register on: 'Changeset',
chain: 'Repository',
attribute: :committed_on
+ OpenProject::ProjectLatestActivity.register on: 'News',
+ attribute: :updated_at
+
OpenProject::ProjectLatestActivity.register on: 'WikiContent',
chain: %w(Wiki WikiPage),
attribute: :updated_at
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 80d7cd4760b..beebb25ee52 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1382,6 +1382,7 @@ en:
events:
project: 'Project edited'
+ projects: 'Project edited'
changeset: 'Changeset edited'
message: Message edited
news: News
@@ -1391,6 +1392,8 @@ en:
work_package_closed: 'Work Package closed'
work_package_edit: 'Work Package edited'
work_package_note: 'Work Package note added'
+ title:
+ project: "Project: %{name}"
export:
your_work_packages_export: "Your work packages export"
@@ -3346,13 +3349,13 @@ en:
oauth_state_not_present: "OAuth2 'state' not found in 'callback' endpoint (redirect_uri)."
oauth_state_not_present_explanation: >
The 'state' is used to indicate to OpenProject where to continue
- after a successful OAuth2 authorization.
- A missing 'state' is an internal error that may appear during setup.
+ after a successful OAuth2 authorization.
+ A missing 'state' is an internal error that may appear during setup.
Please contact your system administrator.
rack_oauth2:
client_secret_invalid: "Client secret is invalid (client_secret_invalid)"
invalid_request: >
- OAuth2 Authorization Server responded with 'invalid_request'.
+ OAuth2 Authorization Server responded with 'invalid_request'.
This error appears if you try to authorize multiple times or in case of technical issues.
invalid_response: "OAuth2 Authorization Server provided an invalid response (invalid_response)"
invalid_grant: "The OAuth2 Authorization Server asks you to reauthorize (invalid_grant)."