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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Make journals attachable in a basic form
Kabiru Mwenja00c7d1537a69
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rbindex ce975eb36b8..ccd240b741a 100644--- a/app/controllers/work_packages/activities_tab_controller.rb+++ b/app/controllers/work_packages/activities_tab_controller.rb@@ -111,6 +111,7 @@ class WorkPackages::ActivitiesTabController < ApplicationControllercall = create_journal_service_callif call.success? && call.result+ claim_journal_attachments_for(call.result)set_last_server_timestamp_to_headershandle_successful_create_call(call)else@@ -233,7 +234,7 @@ class WorkPackages::ActivitiesTabController < ApplicationControllerenddef journal_params- params.expect(journal: %i[notes restricted])+ params.expect(journal: [:notes, :restricted, { attachment_ids: [] }])enddef handle_successful_create_call(call)@@ -326,6 +327,13 @@ class WorkPackages::ActivitiesTabController < ApplicationControllerJournals::UpdateService.new(model: @journal, user: User.current).call(notes:)end+ def claim_journal_attachments_for(journal)+ return if (attachment_ids = journal_params[:attachment_ids]).blank?++ journal.attachments = Attachment.where(author: User.current, id: attachment_ids, container: nil)+ journal.save+ end+def generate_time_based_update_streams(last_update_timestamp)journals = @work_package.journalsdiff --git a/app/forms/work_packages/activities_tab/journals/notes_form.rb b/app/forms/work_packages/activities_tab/journals/notes_form.rbindex dd73f510f37..f2dc13f4540 100644--- a/app/forms/work_packages/activities_tab/journals/notes_form.rb+++ b/app/forms/work_packages/activities_tab/journals/notes_form.rb@@ -47,8 +47,8 @@ module WorkPackages::ActivitiesTab::Journalsdef resourcereturn unless object- API::V3::WorkPackages::WorkPackageRepresenter- .create(object.journable, current_user: User.current, embed_links: false)+ API::V3::Activities::ActivityRepresenter+ .create(object, current_user: User.current, embed_links: false)endendenddiff --git a/app/models/journal.rb b/app/models/journal.rbindex 83c2627873d..7756a3fa19d 100644--- a/app/models/journal.rb+++ b/app/models/journal.rb@@ -36,6 +36,13 @@ class Journal < ApplicationRecordinclude Journal::Timestampsinclude Reactable+ # Inline attachments for Journal#notes aka comments+ # FIXME: Not the final version- permissions need to be revised+ acts_as_attachable view_permission: :view_work_packages,+ add_permission: :add_work_package_notes,+ delete_permission: :edit_own_work_package_notes,+ only_user_allowed: true+register_journal_formatter OpenProject::JournalFormatter::ActiveStatusregister_journal_formatter OpenProject::JournalFormatter::AgendaItemDiffregister_journal_formatter OpenProject::JournalFormatter::AgendaItemDurationdiff --git a/lib/api/v3/activities/activities_api.rb b/lib/api/v3/activities/activities_api.rbindex 822315e622d..3240e20f55f 100644--- a/lib/api/v3/activities/activities_api.rb+++ b/lib/api/v3/activities/activities_api.rb@@ -56,6 +56,8 @@ module API{ notes: declared_params[:comment] }}).mount++ mount ::API::V3::Attachments::AttachmentsByActivityCommentAPIendendenddiff --git a/lib/api/v3/activities/activity_representer.rb b/lib/api/v3/activities/activity_representer.rbindex a24438b5a45..8cb9b7eee3b 100644--- a/lib/api/v3/activities/activity_representer.rb+++ b/lib/api/v3/activities/activity_representer.rb@@ -33,6 +33,8 @@ module APIinclude API::V3::Utilitiesinclude API::Decorators::DatePropertyinclude API::Decorators::FormattableProperty+ include API::Caching::CachedRepresenter+ include ::API::V3::Attachments::AttachableRepresenterMixininclude ActivityPropertyFormattersself_link path: :activity,diff --git a/lib/api/v3/attachments/attachable_representer_mixin.rb b/lib/api/v3/attachments/attachable_representer_mixin.rbindex 6991ea2e493..d4ba31a5050 100644--- a/lib/api/v3/attachments/attachable_representer_mixin.rb+++ b/lib/api/v3/attachments/attachable_representer_mixin.rb@@ -82,7 +82,7 @@ module APIenddef attachments_by_resource- path = "attachments_by_#{_type.singularize.underscore}"+ path = "attachments_by_#{_type.gsub('::', '_').singularize.underscore}"api_v3_paths.send(path, represented.id)enddiff --git a/lib/api/v3/attachments/attachments_by_activity_comment_api.rb b/lib/api/v3/attachments/attachments_by_activity_comment_api.rbnew file mode 100644index 00000000000..db956cc57ec--- /dev/null+++ b/lib/api/v3/attachments/attachments_by_activity_comment_api.rb@@ -0,0 +1,60 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++require "api/v3/attachments/attachment_collection_representer"++module API+ module V3+ module Attachments+ class AttachmentsByActivityCommentAPI < ::API::OpenProjectAPI+ resources :attachments do+ helpers API::V3::Attachments::AttachmentsByContainerAPI::Helpers++ helpers do+ def container+ @activity+ end++ def get_attachment_self_path+ api_v3_paths.attachments_by_activity_comment(container.id)+ end+ end++ get &API::V3::Attachments::AttachmentsByContainerAPI.read+ post &API::V3::Attachments::AttachmentsByContainerAPI.create(%i[add_work_package_notes])++ namespace :prepare do+ post &API::V3::Attachments::AttachmentsByContainerAPI.prepare(%i[add_work_package_notes])+ end+ end+ end+ end+ end+enddiff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rbindex ec04d1085fe..afecdcee01b 100644--- a/lib/api/v3/utilities/path_helper.rb+++ b/lib/api/v3/utilities/path_helper.rb@@ -123,6 +123,10 @@ module API"#{root}/attachments/#{id}/content"end+ def self.attachments_by_activity_comment(id)+ "#{root}/activities/#{id}/attachments"+ end+def self.attachments_by_post(id)"#{post(id)}/attachments"end@@ -547,7 +551,7 @@ module APIresources :work_package, except: :schemadef self.work_package(id, timestamps: nil)- "#{root}/work_packages/#{id}" + \+ "#{root}/work_packages/#{id}" +if (param_value = timestamps_to_param_value(timestamps)).present? && Array(timestamps).any?(&:historic?)"?#{{ timestamps: param_value }.to_query}"end.to_s