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

Bare-bones for writing restricted journals

Kabiru Mwenja6c55715f943d
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 2b824dc6b5e..d78ca3f2ead 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -295,13 +295,14 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def create_journal_service_call
- ### taken from ActivitiesByWorkPackageAPI
+ to_boolean = ->(value, default) { ActiveRecord::Type::Boolean.new.cast(value.presence || default) }
+
AddWorkPackageNoteService
.new(user: User.current,
work_package: @work_package)
.call(journal_params[:notes],
- send_notifications: !(params.has_key?(:notify) && params[:notify] == "false"))
- ###
+ send_notifications: to_boolean.call(params[:notify], true),
+ restricted: to_boolean.call(journal_params[:restricted], false))
end
def update_journal_service_call
diff --git a/app/services/add_work_package_note_service.rb b/app/services/add_work_package_note_service.rb
index 69bb8054f41..8f5ae32735b 100644
--- a/app/services/add_work_package_note_service.rb
+++ b/app/services/add_work_package_note_service.rb
@@ -42,9 +42,9 @@ class AddWorkPackageNoteService
self.contract_class = WorkPackages::CreateNoteContract
end
- def call(notes, send_notifications: nil)
+ def call(notes, send_notifications: nil, restricted: false)
in_context(work_package, send_notifications:) do
- work_package.add_journal(user:, notes:)
+ work_package.add_journal(user:, notes:, restricted:)
success, errors = validate_and_yield(work_package, user) do
work_package.save_journals
diff --git a/app/services/journals/create_service.rb b/app/services/journals/create_service.rb
index 505904c3b67..b14d1d750e1 100644
--- a/app/services/journals/create_service.rb
+++ b/app/services/journals/create_service.rb
@@ -48,9 +48,9 @@ module Journals
self.journable = journable
end
- def call(notes: "", cause: CauseOfChange::NoCause.new)
+ def call(notes: "", restricted: false, cause: CauseOfChange::NoCause.new)
Journal.transaction do
- journal = create_journal(notes, cause)
+ journal = create_journal(notes, restricted, cause)
if journal
reload_journals
@@ -74,12 +74,12 @@ module Journals
end
end
- def create_journal(notes, cause)
+ def create_journal(notes, restricted, cause)
predecessor = aggregatable_predecessor(notes, cause)
log_journal_creation(predecessor)
- create_sql = create_journal_sql(predecessor, notes, cause)
+ create_sql = create_journal_sql(predecessor, notes, restricted, cause)
# We need to ensure that the result is genuine. Otherwise,
# calling the service repeatedly for the same journable
@@ -187,8 +187,8 @@ module Journals
# (`insert_attachable`, `insert_customizable` and `insert_storable`) should actually insert data. It is additionally
# used as the values returned by the overall SQL statement so that an AR instance can be instantiated with it.
#
- def create_journal_sql(predecessor, notes, cause)
- journal_modifications = journal_modification_sql(predecessor, notes, cause)
+ def create_journal_sql(predecessor, notes, restricted, cause)
+ journal_modifications = journal_modification_sql(predecessor, notes, restricted, cause)
relation_modifications = relation_modifications_sql(predecessor)
journal_cte_clauses = [journal_modifications]
@@ -200,7 +200,7 @@ module Journals
SQL
end
- def journal_modification_sql(predecessor, notes, cause)
+ def journal_modification_sql(predecessor, notes, restricted, cause)
<<~SQL
cleanup_predecessor_data AS (
#{cleanup_predecessor_data(predecessor)}
@@ -217,7 +217,7 @@ module Journals
), update_predecessor AS (
#{update_predecessor_sql(predecessor, notes, cause)}
), inserted_journal AS (
- #{update_or_insert_journal_sql(predecessor, notes, cause)}
+ #{update_or_insert_journal_sql(predecessor, notes, restricted, cause)}
)
SQL
end
@@ -307,11 +307,11 @@ module Journals
column => predecessor.send(referenced_id)
end
- def update_or_insert_journal_sql(predecessor, notes, cause)
+ def update_or_insert_journal_sql(predecessor, notes, restricted, cause)
if predecessor
update_journal_sql(predecessor, notes, cause)
else
- insert_journal_sql(notes, cause)
+ insert_journal_sql(notes, restricted, cause)
end
end
@@ -343,7 +343,7 @@ module Journals
cause: cause_sql(cause))
end
- def insert_journal_sql(notes, cause)
+ def insert_journal_sql(notes, restricted, cause)
journal_sql = <<~SQL
INSERT INTO
journals (
@@ -352,6 +352,7 @@ module Journals
version,
user_id,
notes,
+ restricted,
created_at,
updated_at,
data_id,
@@ -365,6 +366,7 @@ module Journals
COALESCE(max_journals.version, 0) + 1,
:user_id,
:notes,
+ :restricted,
(SELECT updated_at FROM fetch_time),
(SELECT updated_at FROM fetch_time),
insert_data.id,
@@ -377,6 +379,7 @@ module Journals
sanitize(journal_sql,
notes:,
+ restricted:,
cause: cause_sql(cause),
journable_id: journable.id,
journable_type:,
diff --git a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb
index 239a673c998..eafdc1e1e35 100644
--- a/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb
+++ b/lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rb
@@ -53,7 +53,7 @@ module Acts::Journalized
base.class_eval do
after_save :save_journals
- attr_accessor :journal_notes, :journal_user, :journal_cause
+ attr_accessor :journal_notes, :journal_user, :journal_restricted, :journal_cause
end
end
@@ -61,7 +61,7 @@ module Acts::Journalized
with_ensured_journal_attributes do
create_call = Journals::CreateService
.new(self, @journal_user)
- .call(notes: @journal_notes, cause: @journal_cause)
+ .call(notes: @journal_notes, restricted: @journal_restricted, cause: @journal_cause)
if create_call.success? && create_call.result
OpenProject::Notifications.send(OpenProject::Events::JOURNAL_CREATED,
@@ -73,10 +73,11 @@ module Acts::Journalized
end
end
- def add_journal(user: User.current, notes: "", cause: CauseOfChange::NoCause.new)
+ def add_journal(user: User.current, notes: "", restricted: false, cause: CauseOfChange::NoCause.new)
self.journal_user ||= user
self.journal_notes ||= notes
self.journal_cause ||= cause
+ self.journal_restricted ||= restricted
end
private
@@ -85,12 +86,14 @@ module Acts::Journalized
self.journal_user ||= User.current
self.journal_notes ||= ""
self.journal_cause ||= CauseOfChange::NoCause.new
+ self.journal_restricted ||= false
yield
ensure
self.journal_user = nil
self.journal_notes = nil
self.journal_cause = nil
+ self.journal_restricted = nil
end
end
end