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

Only send custom invite message when sharing work packages

Klaus Zanders2934ebd73374
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb
index f4e0d8a6d08..9624cb1f199 100644
--- a/app/controllers/shares_controller.rb
+++ b/app/controllers/shares_controller.rb
@@ -56,7 +56,7 @@ class SharesController < ApplicationController
visible_shares_before_adding = sharing_strategy.shares.present?
- find_or_create_users(send_notification: false) do |member_params|
+ find_or_create_users(send_notification: send_notification?) do |member_params|
user = User.find_by(id: member_params[:user_id])
if user.present? && user.locked?
@errors.add(:base, I18n.t("sharing.warning_locked_user", user: user.name))
@@ -297,6 +297,12 @@ class SharesController < ApplicationController
respond_with_turbo_streams
end
+ def send_notification?
+ return false if @entity.is_a?(WorkPackage) # For WorkPackages we have a custom notification
+
+ true
+ end
+
def load_entity # rubocop:disable Metrics/AbcSize
if params["work_package_id"]
@entity = WorkPackage.visible.find(params["work_package_id"])
diff --git a/app/services/shares/create_service.rb b/app/services/shares/create_service.rb
index 6b045190f33..9b5cceea4a4 100644
--- a/app/services/shares/create_service.rb
+++ b/app/services/shares/create_service.rb
@@ -55,7 +55,8 @@ class Shares::CreateService < BaseServices::Create
end
def send_notification(share)
- # TODO: We should select what sort of notification is sent out based on the shared entity
+ return unless share.entity.is_a?(WorkPackage)
+
OpenProject::Notifications.send(OpenProject::Events::WORK_PACKAGE_SHARED,
work_package_member: share,
send_notifications: true)