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

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.rb
index 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 < ApplicationController
call = create_journal_service_call
if call.success? && call.result
+ claim_journal_attachments_for(call.result)
set_last_server_timestamp_to_headers
handle_successful_create_call(call)
else
@@ -233,7 +234,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def journal_params
- params.expect(journal: %i[notes restricted])
+ params.expect(journal: [:notes, :restricted, { attachment_ids: [] }])
end
def handle_successful_create_call(call)
@@ -326,6 +327,13 @@ class WorkPackages::ActivitiesTabController < ApplicationController
Journals::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
.journals
diff --git a/app/forms/work_packages/activities_tab/journals/notes_form.rb b/app/forms/work_packages/activities_tab/journals/notes_form.rb
index 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::Journals
def resource
return 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)
end
end
end
diff --git a/app/models/journal.rb b/app/models/journal.rb
index 83c2627873d..7756a3fa19d 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -36,6 +36,13 @@ class Journal < ApplicationRecord
include Journal::Timestamps
include 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::ActiveStatus
register_journal_formatter OpenProject::JournalFormatter::AgendaItemDiff
register_journal_formatter OpenProject::JournalFormatter::AgendaItemDuration
diff --git a/lib/api/v3/activities/activities_api.rb b/lib/api/v3/activities/activities_api.rb
index 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::AttachmentsByActivityCommentAPI
end
end
end
diff --git a/lib/api/v3/activities/activity_representer.rb b/lib/api/v3/activities/activity_representer.rb
index a24438b5a45..8cb9b7eee3b 100644
--- a/lib/api/v3/activities/activity_representer.rb
+++ b/lib/api/v3/activities/activity_representer.rb
@@ -33,6 +33,8 @@ module API
include API::V3::Utilities
include API::Decorators::DateProperty
include API::Decorators::FormattableProperty
+ include API::Caching::CachedRepresenter
+ include ::API::V3::Attachments::AttachableRepresenterMixin
include ActivityPropertyFormatters
self_link path: :activity,
diff --git a/lib/api/v3/attachments/attachable_representer_mixin.rb b/lib/api/v3/attachments/attachable_representer_mixin.rb
index 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 API
end
def attachments_by_resource
- path = "attachments_by_#{_type.singularize.underscore}"
+ path = "attachments_by_#{_type.gsub('::', '_').singularize.underscore}"
api_v3_paths.send(path, represented.id)
end
diff --git a/lib/api/v3/attachments/attachments_by_activity_comment_api.rb b/lib/api/v3/attachments/attachments_by_activity_comment_api.rb
new file mode 100644
index 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
+end
diff --git a/lib/api/v3/utilities/path_helper.rb b/lib/api/v3/utilities/path_helper.rb
index 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 API
resources :work_package, except: :schema
def 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