move (almost) everything over to acts_as_journalized
This commit is contained in:
parent
4b0bd11f6d
commit
2d282f8deb
|
@ -23,20 +23,18 @@ class Changeset < ActiveRecord::Base
|
|||
has_many :changes, :dependent => :delete_all
|
||||
has_and_belongs_to_many :issues
|
||||
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))},
|
||||
:description => :long_comments,
|
||||
:datetime => :committed_on,
|
||||
:url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.revision}}
|
||||
|
||||
acts_as_journalized :event_title => Proc.new {|o| "#{l(:label_revision)} #{o.revision}" + (o.short_comments.blank? ? '' : (': ' + o.short_comments))},
|
||||
:event_description => :long_comments,
|
||||
:event_datetime => :committed_on,
|
||||
:event_url => Proc.new {|o| {:controller => 'repositories', :action => 'revision', :id => o.repository.project, :rev => o.revision}},
|
||||
:activity_timestamp => "#{table_name}.committed_on",
|
||||
:activity_author_key => :user_id
|
||||
|
||||
acts_as_searchable :columns => 'comments',
|
||||
:include => {:repository => :project},
|
||||
:project_key => "#{Repository.table_name}.project_id",
|
||||
:date_column => 'committed_on'
|
||||
|
||||
acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
|
||||
:author_key => :user_id,
|
||||
:find_options => {:include => [:user, {:repository => :project}]}
|
||||
|
||||
|
||||
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
|
||||
validates_uniqueness_of :revision, :scope => :repository_id
|
||||
validates_uniqueness_of :scmid, :scope => :repository_id, :allow_nil => true
|
||||
|
|
|
@ -20,15 +20,18 @@ 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| "#{l(:label_document)}: #{o.title}"},
|
||||
:event_url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id} },
|
||||
:event_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
|
||||
acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"},
|
||||
:author => Proc.new {|o| (a = o.attachments.find(:first, :order => "#{Attachment.table_name}.created_on ASC")) ? a.author : nil },
|
||||
:url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :find_options => {:include => :project}
|
||||
|
||||
|
||||
|
||||
validates_presence_of :project, :title, :category
|
||||
validates_length_of :title, :maximum => 60
|
||||
|
||||
|
||||
def visible?(user=User.current)
|
||||
!user.nil? && user.allowed_to?(:view_documents, project)
|
||||
end
|
||||
|
|
|
@ -197,11 +197,11 @@ class MailHandler < ActionMailer::Base
|
|||
# Reply will be added to the issue
|
||||
def receive_journal_reply(journal_id)
|
||||
journal = Journal.find_by_id(journal_id)
|
||||
if journal && journal.journalized_type == 'Issue'
|
||||
receive_issue_reply(journal.journalized_id)
|
||||
if journal && journal.versioned_type == 'Issue'
|
||||
receive_issue_reply(journal.versioned_id)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Receives a reply to a forum message
|
||||
def receive_message_reply(message_id)
|
||||
message = Message.find_by_id(message_id)
|
||||
|
|
|
@ -55,7 +55,7 @@ class Mailer < ActionMailer::Base
|
|||
# issue_edit(journal) => tmail object
|
||||
# Mailer.deliver_issue_edit(journal) => sends an email to issue recipients
|
||||
def issue_edit(journal)
|
||||
issue = journal.journalized.reload
|
||||
issue = journal.versioned.reload
|
||||
redmine_headers 'Project' => issue.project.identifier,
|
||||
'Issue-Id' => issue.id,
|
||||
'Issue-Author' => issue.author.login
|
||||
|
|
|
@ -21,21 +21,25 @@ class Message < ActiveRecord::Base
|
|||
acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC"
|
||||
acts_as_attachable
|
||||
belongs_to :last_reply, :class_name => 'Message', :foreign_key => 'last_reply_id'
|
||||
|
||||
|
||||
acts_as_journalized :event_title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
||||
:event_description => :content,
|
||||
:event_type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
||||
:event_url => (Proc.new do |o|
|
||||
if o.parent_id.nil?
|
||||
{:id => o.id}
|
||||
else
|
||||
{:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"}
|
||||
end.reverse_merge :controller => 'messages', :action => 'show', :board_id => o.board_id
|
||||
end)
|
||||
|
||||
acts_as_searchable :columns => ['subject', 'content'],
|
||||
:include => {:board => :project},
|
||||
:project_key => 'project_id',
|
||||
:date_column => "#{table_name}.created_on"
|
||||
acts_as_event :title => Proc.new {|o| "#{o.board.name}: #{o.subject}"},
|
||||
:description => :content,
|
||||
:type => Proc.new {|o| o.parent_id.nil? ? 'message' : 'reply'},
|
||||
:url => Proc.new {|o| {:controller => 'messages', :action => 'show', :board_id => o.board_id}.merge(o.parent_id.nil? ? {:id => o.id} :
|
||||
{:id => o.parent_id, :r => o.id, :anchor => "message-#{o.id}"})}
|
||||
|
||||
acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]},
|
||||
:author_key => :author_id
|
||||
acts_as_watchable
|
||||
|
||||
|
||||
attr_protected :locked, :sticky
|
||||
validates_presence_of :board, :subject, :content
|
||||
validates_length_of :subject, :maximum => 255
|
||||
|
|
|
@ -24,11 +24,9 @@ class News < ActiveRecord::Base
|
|||
validates_length_of :title, :maximum => 60
|
||||
validates_length_of :summary, :maximum => 255
|
||||
|
||||
acts_as_journalized :event_url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id} }
|
||||
acts_as_searchable :columns => ['title', 'summary', "#{table_name}.description"], :include => :project
|
||||
acts_as_event :url => Proc.new {|o| {:controller => 'news', :action => 'show', :id => o.id}}
|
||||
acts_as_activity_provider :find_options => {:include => [:project, :author]},
|
||||
:author_key => :author_id
|
||||
|
||||
|
||||
def visible?(user=User.current)
|
||||
!user.nil? && user.allowed_to?(:view_news, project)
|
||||
end
|
||||
|
|
|
@ -22,18 +22,15 @@ class TimeEntry < ActiveRecord::Base
|
|||
belongs_to :issue
|
||||
belongs_to :user
|
||||
belongs_to :activity, :class_name => 'TimeEntryActivity', :foreign_key => 'activity_id'
|
||||
|
||||
|
||||
attr_protected :project_id, :user_id, :tyear, :tmonth, :tweek
|
||||
|
||||
acts_as_customizable
|
||||
acts_as_event :title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
|
||||
:url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project, :issue_id => o.issue}},
|
||||
:author => :user,
|
||||
:description => :comments
|
||||
|
||||
acts_as_activity_provider :timestamp => "#{table_name}.created_on",
|
||||
:author_key => :user_id,
|
||||
:find_options => {:include => :project}
|
||||
acts_as_journalized :event_title => Proc.new {|o| "#{l_hours(o.hours)} (#{(o.issue || o.project).event_title})"},
|
||||
:event_url => Proc.new {|o| {:controller => 'timelog', :action => 'details', :project_id => o.project, :issue_id => o.issue}},
|
||||
:event_author => :user,
|
||||
:event_description => :comments,
|
||||
:activity_timestamp => "#{table_name}.created_on"
|
||||
|
||||
validates_presence_of :user_id, :activity_id, :project_id, :hours, :spent_on
|
||||
validates_numericality_of :hours, :allow_nil => true, :message => :invalid
|
||||
|
|
|
@ -36,7 +36,7 @@ Rails::Initializer.run do |config|
|
|||
|
||||
# Activate observers that should always be running
|
||||
# config.active_record.observers = :cacher, :garbage_collector
|
||||
config.active_record.observers = :message_observer, :issue_observer, :news_observer, :document_observer, :wiki_content_observer
|
||||
config.active_record.observers = :journal_observer, :message_observer, :issue_observer, :news_observer, :document_observer, :wiki_content_observer
|
||||
|
||||
# Make Active Record use UTC-base instead of local time
|
||||
# config.active_record.default_timezone = :utc
|
||||
|
|
|
@ -68,10 +68,9 @@ module Redmine
|
|||
# Returns an array of events for the given date range
|
||||
# sorted in reverse chronological order
|
||||
def events(from = nil, to = nil, options={})
|
||||
require 'ruby-debug'; debugger
|
||||
e = []
|
||||
@options[:limit] = options[:limit]
|
||||
|
||||
|
||||
@scope.each do |event_type|
|
||||
constantized_providers(event_type).each do |provider|
|
||||
e += provider.find_events(event_type, @user, from, to, @options)
|
||||
|
|
|
@ -54,7 +54,7 @@ module Redmine
|
|||
def find_events(event_type, user, from, to, options)
|
||||
provider_options = activity_provider_options[event_type]
|
||||
raise "#{self.name} can not provide #{event_type} events." if provider_options.nil?
|
||||
|
||||
|
||||
scope_options = {}
|
||||
cond = ARCondition.new
|
||||
if from && to
|
||||
|
|
Loading…
Reference in New Issue