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
Merge remote-tracking branch 'origin/dev' into implementation/60980-introduce-work-package-restricted-comments-as-part-of-journal-notes
Bruno Pagnobe9afb37b82d
diff --cc app/services/journals/create_service.rbindex 5528533287e,906c40c6ba2..350f5192f92--- a/app/services/journals/create_service.rb+++ b/app/services/journals/create_service.rb@@@ -41,16 -41,17 +41,17 @@@# rubocop:disable Rails/SquishedSQLHeredocsmodule Journalsclass CreateService- attr_accessor :journable, :user+ attr_reader :journable, :user, :associationsdef initialize(journable, user)- self.user = user- self.journable = journable+ @user = user+ @journable = journable+ @associations = Association.for(self)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 journalreload_journals@@@ -62,24 -63,22 +63,26 @@@private+ def journable_id = journable.id+- # If the journalizing happens within the configured aggregation time, is carried out by the same user, has an- # identical cause and only the predecessor or the journal to be created has notes, the changes are aggregated.+ # Aggregatable journals must meet the following criteria:+ #+ # * The journalizing happens within the configured aggregation time+ # * The journalizing is carried out by the same user+ # * The cause is identical+ # * ONLY one note exists between the predecessor and the journal to be created+ # * The predecessor and the journal to be created have the same restriction+ ## Instead of removing the predecessor, return it here so that it can be stripped in the journal creating# SQL to than be refilled. That way, references to the journal, including ones users have, are kept intact.- def aggregatable_predecessor(notes, cause)+ def aggregatable_predecessor(notes, restricted, cause)predecessor = journable.last_journal- if aggregatable?(predecessor, notes, cause)- predecessor- end+ predecessor if aggregatable?(predecessor, notes, restricted, cause)end- def create_journal(notes, cause)- predecessor = aggregatable_predecessor(notes, cause)+ def create_journal(notes, restricted, cause)+ predecessor = aggregatable_predecessor(notes, restricted, cause)log_journal_creation(predecessor)@@@ -306,12 -258,9 +262,9 @@@WHERE#{column} = :#{column}SQL-- sanitize sql,- 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 predecessorupdate_journal_sql(predecessor, notes, cause)else@@@ -347,8 -296,8 +300,8 @@@cause: cause_sql(cause))end- def insert_journal_sql(notes, cause)+ def insert_journal_sql(notes, restricted, cause)- journal_sql = <<~SQL+ sql = <<~SQLINSERT INTOjournals (journable_id,@@@ -381,11 -328,10 +334,11 @@@RETURNING *SQL- sanitize(journal_sql,+ sanitize(sql,notes:,+ restricted:,cause: cause_sql(cause),- journable_id: journable.id,+ journable_id:,journable_type:,user_id: user.id,data_type: journable.class.journal_class.name)diff --cc lib_static/plugins/acts_as_journalized/lib/acts/journalized/save_hooks.rbindex eafdc1e1e35,e4ba7ae01a6..0f4e545ed84--- 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@@@ -73,7 -73,12 +73,12 @@@ module Acts::Journalizeendend+ def touch_and_save_journals+ update_column(:updated_at, Time.current)+ save_journals+ 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 ||= userself.journal_notes ||= notesself.journal_cause ||= causediff --cc spec/models/activities/fetcher_integration_spec.rbindex c35bbbc2f4e,6d3ff9aa4dc..12bf6e7ecb1--- a/spec/models/activities/fetcher_integration_spec.rb+++ b/spec/models/activities/fetcher_integration_spec.rb@@@ -60,30 -56,69 +60,80 @@@ RSpec.describe Activities::Fetcher, "inlet(:repository) { create(:repository_subversion, project:) }let(:changeset) { create(:changeset, committer: event_user.login, repository:) }let(:wiki) { create(:wiki, project:) }- let(:wiki_page) do- create(:wiki_page, wiki:, author: event_user, text: "some text")+ let(:wiki_page) { create(:wiki_page, wiki:, author: event_user, text: "some text") }+ let(:restricted_note) do+ create(:work_package_journal,+ journable: work_package,+ user: admin,+ notes: "Restricted comment",+ restricted: true,+ version: 2,+ data: build(:journal_work_package_journal,+ subject: work_package.subject,+ status_id: work_package.status_id,+ type_id: work_package.type_id,+ project_id: work_package.project_id))end- subject { instance.events(from: 30.days.ago, to: 1.day.from_now) }+ subject(:event_journables) { instance.events(from: 30.days.ago, to: 1.day.from_now).map { it.journal.journable } }- context "for global activities" do- let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page, restricted_note.journable] }+ def activities_of_types(*klasses)+ activities.select do |activity|+ klasses.any? do |klass|+ activity.is_a?(klass)+ end+ end+ end++ shared_examples "specifying scope" do+ context "without scope set" do+ it "finds events of all types" do+ expect(event_journables)+ .to match_array(activities)+ end+ end++ context "with scope :all" do+ before { options[:scope] = :all }++ it "finds events of all types" do+ expect(event_journables)+ .to match_array(activities)+ end+ end++ context "with scope :default" do+ before { options[:scope] = :default }++ it "finds events that are registered to be shown by default" do+ expect(event_journables)+ .to match_array(activities_of_types(WorkPackage, Changeset))+ end+ end++ context "with scope of event types" do+ before { options[:scope] = %w[time_entries messages project_details] }++ it "finds only events matching the scope" do+ expect(event_journables)+ .to match_array(activities_of_types(Message, TimeEntry, Project))+ end+ end++ context "with scope of compatibility alias of project_attributes for project_details" do+ before { options[:scope] = %w[project_attributes] }- it "finds events of all types" do- expect(subject.map(&:journable_id))- .to match_array(activities.map(&:id))+ it "finds only events matching the scope" do+ expect(event_journables)+ .to match_array(activities_of_types(Project))+ endend+ end++ context "for global activities" do+ let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page] }++ include_examples "specifying scope"context "if lacking permissions" dobefore do@@@ -107,48 -142,14 +157,42 @@@.to be_emptyendend+- context "if restricting the scope" do- before do- options[:scope] = %w(time_entries messages)- end-- it "finds only events matching the scope" do- expect(subject.map(&:journable_id))- .to contain_exactly(message.id, time_entry.id)- end- end-+ context "if user cannot see restricted journals" do+ before do+ role.role_permissions+ .find_by(permission: "view_comments_with_restricted_visibility")+ .destroy++ # reload otherwise permissions don't update+ event_user.reload++++ # make sure restricted_note is created++ restricted_note+ end++ it "does not find events with restricted journals" do- expect(subject.map(&:journal).select(&:restricted)).to be_empty++ expect(instance.events.map(&:journal).select(&:restricted)).to be_empty+ end+ end++ context "if user can see restricted journals" do++ before do++ # make sure restricted_note is created++ restricted_note++ end+++ it "finds events with restricted journals" do- expect(subject.map(&:journal).select(&:restricted).map(&:journable_id)).to include(restricted_note.journable_id)++ expect(instance.events.map(&:journal).select(&:restricted)).to include(restricted_note)+ end+ endendcontext "for activities in a project" dolet(:options) { { project: } }- let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page, restricted_note.journable] }-+ let!(:activities) { [project, work_package, message, news, time_entry, changeset, wiki_page] }- it "finds events of all types" do- expect(subject.map(&:journable_id))- .to match_array(activities.map(&:id))- end+ include_examples "specifying scope"context "if lacking permissions" dobefore do@@@ -177,38 -178,6 +221,35 @@@.to be_emptyendend+- context "if restricting the scope" do- before do- options[:scope] = %w(time_entries messages)- end-- it "finds only events matching the scope" do- expect(subject.map(&:journable_id))- .to contain_exactly(message.id, time_entry.id)- end- end-+ context "if user cannot see restricted journals" do+ before do+ role.role_permissions+ .find_by(permission: "view_comments_with_restricted_visibility")+ .destroy++ # reload otherwise permissions don't update+ event_user.reload++++ # make sure restricted_note is created++ restricted_note+ end++ it "does not find events with restricted journals" do- expect(subject.map(&:journal).select(&:restricted)).to be_empty++ expect(instance.events.map(&:journal).select(&:restricted)).to be_empty+ end+ end++ context "if user can see restricted journals" do++ before do++ # make sure restricted_note is created++ restricted_note++ end+++ it "finds events with restricted journals" do- expect(subject.map(&:journal).select(&:restricted).map(&:journable_id)).to include(restricted_note.journable_id)++ expect(instance.events.map(&:journal).select(&:restricted)).to include(restricted_note)+ end+ endendcontext "for activities in a subproject" do