Remove usage of journals.activity_type

In https://github.com/opf/openproject/pull/11741#discussion_r1039350659
Jens suggested to remove `activity_type` and rely on `journalized_type`
instead as there is a 1:1 relationship between them.

`activity_type` was introduced to differentiate between different types
of activity for the same journalized model (e.g. creation vs editing),
but this field is not used in practice.
pull/11756/head
Christophe Bliard 2 years ago
parent 601d57061e
commit d5a3b0019f
No known key found for this signature in database
GPG Key ID: 2BC07603210C3FA4
  1. 4
      app/models/activities/base_activity_provider.rb
  2. 1
      app/models/journal.rb
  3. 4
      app/models/wiki_content.rb
  4. 5
      app/models/work_package.rb
  5. 3
      app/services/journals/create_service.rb
  6. 6
      lib_static/plugins/acts_as_journalized/lib/acts/journalized/creation.rb
  7. 5
      modules/budgets/app/models/budget.rb
  8. 1
      modules/meeting/spec/factories/meeting_journal_factory.rb
  9. 4
      spec/factories/journal_factory.rb

@ -122,9 +122,7 @@ class Activities::BaseActivityProvider
end
def activitied_type
activity_type = self.class.name
class_name = activity_type.demodulize
class_name = self.class.name.demodulize
class_name.gsub('ActivityProvider', '').constantize
end

@ -28,6 +28,7 @@
class Journal < ApplicationRecord
self.table_name = 'journals'
self.ignored_columns += ['activity_type']
include ::JournalChanges
include ::JournalFormatter

@ -48,10 +48,6 @@ class WikiContent < ApplicationRecord
}
}
def activity_type
'wiki_edits'
end
def visible?(user = User.current)
page.visible?(user)
end

@ -207,11 +207,6 @@ class WorkPackage < ApplicationRecord
(usr || User.current).allowed_to?(:view_work_packages, project)
end
# ACTS AS JOURNALIZED
def activity_type
'work_packages'
end
# RELATIONS
def blockers
# return work_packages that block me

@ -251,7 +251,6 @@ module Journals
journable_id,
journable_type,
version,
activity_type,
user_id,
notes,
created_at,
@ -263,7 +262,6 @@ module Journals
:journable_id,
:journable_type,
COALESCE(max_journals.version, 0) + 1,
:activity_type,
:user_id,
:notes,
#{journal_timestamp_sql(notes, ':created_at')},
@ -277,7 +275,6 @@ module Journals
sanitize(journal_sql,
notes:,
journable_id: journable.id,
activity_type: journable.activity_type,
journable_type:,
user_id: user.id,
created_at: journable_timestamp,

@ -82,12 +82,6 @@ module Acts::Journalized
def journaled_columns_names
self.class.journal_class.journaled_attributes
end
# Returns the activity type. Should be overridden in the journalized class to offer
# multiple types
def activity_type
self.class.name.underscore.pluralize
end
end
end
end

@ -128,11 +128,6 @@ class Budget < ApplicationRecord
subject
end
# override acts_as_journalized method
def activity_type
self.class.plural_name
end
def material_budget
@material_budget ||= material_budget_items.visible_costs.inject(BigDecimal('0.0000')) { |sum, i| sum += i.costs }
end

@ -33,7 +33,6 @@ FactoryBot.define do
factory :meeting_content_journal, class: 'Journal' do
journable_type { 'MeetingContent' }
activity_type { 'meetings' }
end
end
end

@ -34,7 +34,6 @@ FactoryBot.define do
factory :work_package_journal, class: 'Journal' do
journable_type { 'WorkPackage' }
activity_type { 'work_packages' }
data { build(:journal_work_package_journal) }
callback(:after_stub) do |journal, options|
@ -44,19 +43,16 @@ FactoryBot.define do
factory :wiki_content_journal, class: 'Journal' do
journable_type { 'WikiContent' }
activity_type { 'wiki_edits' }
data { build(:journal_wiki_content_journal) }
end
factory :message_journal, class: 'Journal' do
journable_type { 'Message' }
activity_type { 'messages' }
data { build(:journal_message_journal) }
end
factory :news_journal, class: 'Journal' do
journable_type { 'News' }
activity_type { 'news' }
data { build(:journal_message_journal) }
end
end

Loading…
Cancel
Save