From 746e9f411edcb8e355316593171fa1f58ee6d508 Mon Sep 17 00:00:00 2001 From: Hagen Schink Date: Mon, 16 Dec 2013 12:46:38 +0100 Subject: [PATCH] Adapts core activity changes --- CHANGELOG.md | 1 + .../activity/document_activity_provider.rb | 41 +++++++++++++++++++ app/models/document.rb | 12 +++--- lib/open_project/documents/engine.rb | 3 ++ 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 app/models/activity/document_activity_provider.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 4beb5d9818..2fbacb9a2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # Changelog +* `#3329` Refactor Duplicated Code Journals * Adaptations for new icon font ## 1.0.0.pre5 diff --git a/app/models/activity/document_activity_provider.rb b/app/models/activity/document_activity_provider.rb new file mode 100644 index 0000000000..3b4ecec29e --- /dev/null +++ b/app/models/activity/document_activity_provider.rb @@ -0,0 +1,41 @@ +#-- copyright +# OpenProject is a project management system. +# +# Copyright (C) 2012-2013 the OpenProject Foundation (OPF) +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License version 3. +# +# See doc/COPYRIGHT.rdoc for more details. +#++ + +class Activity::DocumentActivityProvider < Activity::BaseActivityProvider + acts_as_activity_provider type: 'documents', + permission: :view_documents + + def event_query_projection(activity) + [ + activity_journal_projection_statement(:title, 'document_title', activity), + activity_journal_projection_statement(:project_id, 'project_id', activity) + ] + end + + def event_title(event, activity) + "#{Document.model_name.human}: #{event['document_title']}" + end + + def event_path(event, activity) + Rails.application.routes.url_helpers.project_document_path(url_helper_parameter(event)) + end + + def event_url(event, activity) + Rails.application.routes.url_helpers.project_document_url(url_helper_parameter(event), + host: ::Setting.host_name) + end + + private + + def url_helper_parameter(event) + event['journable_id'] + end +end diff --git a/app/models/document.rb b/app/models/document.rb index ae77ddbe9c..5dc89d6b8c 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -16,11 +16,13 @@ class Document < ActiveRecord::Base belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" acts_as_attachable :delete_permission => :manage_documents - acts_as_journalized :event_title => Proc.new {|o| "#{Document.model_name.human}: #{o.journal.journable.title}"}, - :event_url => Proc.new {|o| {:controller => '/documents', :action => 'show', :id => o.journal.journable_id}}, - :event_author => (Proc.new do |o| - o.journal.journable.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC").try(:author) - end) + acts_as_journalized + acts_as_event title: Proc.new { |o| "#{Document.model_name.human}: #{o.title}" }, + url: Proc.new { |o| { controller: '/documents', action: 'show', id: o.id } }, + author: ( Proc.new do |o| + o.attachments.find(:first, order: "#{Attachment.table_name}.created_on ASC").try(:author) + end) + acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project diff --git a/lib/open_project/documents/engine.rb b/lib/open_project/documents/engine.rb index 1e52fee839..2cbfcc8010 100644 --- a/lib/open_project/documents/engine.rb +++ b/lib/open_project/documents/engine.rb @@ -29,6 +29,9 @@ module OpenProject::Documents Redmine::Notifiable.all << Redmine::Notifiable.new('document_added') + Redmine::Activity.map do |activity| + activity.register :documents, class_name: 'Activity::DocumentActivityProvider', default: false + end end Redmine::Search.register :documents