Merge pull request #11 from finnlabs/refactor/activity_providers

[Refactoring] Activity providers
pull/6827/head
sschu 11 years ago
commit aac03511e7
  1. 1
      CHANGELOG.md
  2. 41
      app/models/activity/document_activity_provider.rb
  3. 12
      app/models/document.rb
  4. 3
      lib/open_project/documents/engine.rb

@ -1,5 +1,6 @@
# Changelog
* `#3329` Refactor Duplicated Code Journals
* Adaptations for new icon font
## 1.0.0.pre5

@ -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

@ -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

@ -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

Loading…
Cancel
Save