summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-07-27 17:54:09 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-07-27 17:54:09 +0000
commita774c5c48b5e596770340b6ac27ea9f0a1e1141f (patch)
tree7c0ab261c09324cbef711cba9ab3400d3c610cc2 /app
parent1721376542af256263d605a16c3981eca9e3733a (diff)
downloadredmine-a774c5c48b5e596770340b6ac27ea9f0a1e1141f.tar.gz
redmine-a774c5c48b5e596770340b6ac27ea9f0a1e1141f.zip
Activity refactoring.
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1701 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/projects_controller.rb92
-rw-r--r--app/models/attachment.rb12
-rw-r--r--app/models/changeset.rb3
-rw-r--r--app/models/document.rb3
-rw-r--r--app/models/issue.rb2
-rw-r--r--app/models/journal.rb6
-rw-r--r--app/models/message.rb4
-rw-r--r--app/models/news.rb3
-rw-r--r--app/models/wiki_content.rb11
-rw-r--r--app/views/projects/activity.rhtml4
10 files changed, 53 insertions, 87 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 3af77d1ac..ce4b24b8b 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -226,94 +226,22 @@ class ProjectsController < ApplicationController
@date_to ||= Date.today + 1
@date_from = @date_to - @days
+ @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
- @event_types = %w(issues news files documents changesets wiki_pages messages)
- if @project
- @event_types.delete('wiki_pages') unless @project.wiki
- @event_types.delete('changesets') unless @project.repository
- @event_types.delete('messages') unless @project.boards.any?
- # only show what the user is allowed to view
- @event_types = @event_types.select {|o| User.current.allowed_to?("view_#{o}".to_sym, @project)}
- @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1')
- end
- @scope = @event_types.select {|t| params["show_#{t}"]}
- # default events if none is specified in parameters
- @scope = (@event_types - %w(wiki_pages messages))if @scope.empty?
-
- @events = []
-
- if @scope.include?('issues')
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += Issue.find(:all, :include => [:project, :author, :tracker], :conditions => cond.conditions)
-
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_issues, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Journal.table_name}.journalized_type = 'Issue' AND #{Journal.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- cond.add("#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> ''")
- @events += Journal.find(:all, :include => [{:issue => :project}, :details, :user], :conditions => cond.conditions)
- end
-
- if @scope.include?('news')
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_news, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += News.find(:all, :include => [:project, :author], :conditions => cond.conditions)
- end
-
- if @scope.include?('files')
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_files, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
- :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
- "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id",
- :conditions => cond.conditions)
- end
-
- if @scope.include?('documents')
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += Document.find(:all, :include => :project, :conditions => cond.conditions)
-
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_documents, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Attachment.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*",
- :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
- "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id",
- :conditions => cond.conditions)
- end
-
- if @scope.include?('wiki_pages')
- select = "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
- "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
- "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
- "#{WikiContent.versioned_table_name}.id"
- joins = "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
- "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
- "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"
+ @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects)
+ @activity.scope_select {|t| !params["show_#{t}"].nil?}
+ @activity.default_scope! if @activity.scope.empty?
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_wiki_pages, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => cond.conditions)
- end
-
- if @scope.include?('changesets')
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_changesets, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += Changeset.find(:all, :include => {:repository => :project}, :conditions => cond.conditions)
- end
-
- if @scope.include?('messages')
- cond = ARCondition.new(Project.allowed_to_condition(User.current, :view_messages, :project => @project, :with_subprojects => @with_subprojects))
- cond.add(["#{Message.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to])
- @events += Message.find(:all, :include => [{:board => :project}, :author], :conditions => cond.conditions)
- end
-
- @events_by_day = @events.group_by(&:event_date)
+ events = @activity.events(@date_from, @date_to)
respond_to do |format|
- format.html { render :layout => false if request.xhr? }
+ format.html {
+ @events_by_day = events.group_by(&:event_date)
+ render :layout => false if request.xhr?
+ }
format.atom {
title = (@scope.size == 1) ? l("label_#{@scope.first.singularize}_plural") : l(:label_activity)
- render_feed(@events, :title => "#{@project || Setting.app_title}: #{title}")
+ render_feed(events, :title => "#{@project || Setting.app_title}: #{title}")
}
end
end
diff --git a/app/models/attachment.rb b/app/models/attachment.rb
index 8f3f530c7..95ba8491f 100644
--- a/app/models/attachment.rb
+++ b/app/models/attachment.rb
@@ -28,6 +28,18 @@ class Attachment < ActiveRecord::Base
acts_as_event :title => :filename,
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
+ acts_as_activity_provider :type => 'files',
+ :permission => :view_files,
+ :find_options => {:select => "#{Attachment.table_name}.*",
+ :joins => "LEFT JOIN #{Version.table_name} ON #{Attachment.table_name}.container_type='Version' AND #{Version.table_name}.id = #{Attachment.table_name}.container_id " +
+ "LEFT JOIN #{Project.table_name} ON #{Version.table_name}.project_id = #{Project.table_name}.id"}
+
+ acts_as_activity_provider :type => 'documents',
+ :permission => :view_documents,
+ :find_options => {:select => "#{Attachment.table_name}.*",
+ :joins => "LEFT JOIN #{Document.table_name} ON #{Attachment.table_name}.container_type='Document' AND #{Document.table_name}.id = #{Attachment.table_name}.container_id " +
+ "LEFT JOIN #{Project.table_name} ON #{Document.table_name}.project_id = #{Project.table_name}.id"}
+
cattr_accessor :storage_path
@@storage_path = "#{RAILS_ROOT}/files"
diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 41f5ed86a..0663af34e 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -30,6 +30,9 @@ class Changeset < ActiveRecord::Base
:include => {:repository => :project},
:project_key => "#{Repository.table_name}.project_id",
:date_column => 'committed_on'
+
+ acts_as_activity_provider :timestamp => "#{table_name}.committed_on",
+ :find_options => {:include => {:repository => :project}}
validates_presence_of :repository_id, :revision, :committed_on, :commit_date
validates_uniqueness_of :revision, :scope => :repository_id
diff --git a/app/models/document.rb b/app/models/document.rb
index 9e2818fc7..627a2418f 100644
--- a/app/models/document.rb
+++ b/app/models/document.rb
@@ -24,7 +24,8 @@ class Document < ActiveRecord::Base
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
end
diff --git a/app/models/issue.rb b/app/models/issue.rb
index e2405a04c..7ebe9db99 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -42,6 +42,8 @@ class Issue < ActiveRecord::Base
acts_as_event :title => Proc.new {|o| "#{o.tracker.name} ##{o.id}: #{o.subject}"},
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.id}}
+ acts_as_activity_provider :find_options => {:include => [:project, :author, :tracker]}
+
validates_presence_of :subject, :description, :priority, :project, :tracker, :author, :status
validates_length_of :subject, :maximum => 255
validates_inclusion_of :done_ratio, :in => 0..100
diff --git a/app/models/journal.rb b/app/models/journal.rb
index a427f84e3..71a51290b 100644
--- a/app/models/journal.rb
+++ b/app/models/journal.rb
@@ -31,6 +31,12 @@ class Journal < ActiveRecord::Base
:type => Proc.new {|o| (s = o.new_status) ? (s.is_closed? ? 'issue-closed' : 'issue-edit') : 'issue-note' },
:url => Proc.new {|o| {:controller => 'issues', :action => 'show', :id => o.issue.id, :anchor => "change-#{o.id}"}}
+ acts_as_activity_provider :type => 'issues',
+ :permission => :view_issues,
+ :find_options => {:include => [{:issue => :project}, :details, :user],
+ :conditions => "#{Journal.table_name}.journalized_type = 'Issue' AND" +
+ " (#{JournalDetail.table_name}.prop_key = 'status_id' OR #{Journal.table_name}.notes <> '')"}
+
def save
# Do not save an empty journal
(details.empty? && notes.blank?) ? false : super
diff --git a/app/models/message.rb b/app/models/message.rb
index 888bffcc3..80df7a33a 100644
--- a/app/models/message.rb
+++ b/app/models/message.rb
@@ -31,7 +31,9 @@ class Message < ActiveRecord::Base
: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, :anchor => "message-#{o.id}"})}
-
+
+ acts_as_activity_provider :find_options => {:include => [{:board => :project}, :author]}
+
attr_protected :locked, :sticky
validates_presence_of :subject, :content
validates_length_of :subject, :maximum => 255
diff --git a/app/models/news.rb b/app/models/news.rb
index 71e2a2d5e..4c4943b78 100644
--- a/app/models/news.rb
+++ b/app/models/news.rb
@@ -26,7 +26,8 @@ class News < ActiveRecord::Base
acts_as_searchable :columns => ['title', "#{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]}
+
# returns latest news for projects visible by user
def self.latest(user=nil, count=5)
find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
diff --git a/app/models/wiki_content.rb b/app/models/wiki_content.rb
index 724354ad6..f2ee39c4d 100644
--- a/app/models/wiki_content.rb
+++ b/app/models/wiki_content.rb
@@ -35,6 +35,17 @@ class WikiContent < ActiveRecord::Base
:type => 'wiki-page',
:url => Proc.new {|o| {:controller => 'wiki', :id => o.page.wiki.project_id, :page => o.page.title, :version => o.version}}
+ acts_as_activity_provider :type => 'wiki_pages',
+ :timestamp => "#{WikiContent.versioned_table_name}.updated_on",
+ :permission => :view_wiki_pages,
+ :find_options => {:select => "#{WikiContent.versioned_table_name}.updated_on, #{WikiContent.versioned_table_name}.comments, " +
+ "#{WikiContent.versioned_table_name}.#{WikiContent.version_column}, #{WikiPage.table_name}.title, " +
+ "#{WikiContent.versioned_table_name}.page_id, #{WikiContent.versioned_table_name}.author_id, " +
+ "#{WikiContent.versioned_table_name}.id",
+ :joins => "LEFT JOIN #{WikiPage.table_name} ON #{WikiPage.table_name}.id = #{WikiContent.versioned_table_name}.page_id " +
+ "LEFT JOIN #{Wiki.table_name} ON #{Wiki.table_name}.id = #{WikiPage.table_name}.wiki_id " +
+ "LEFT JOIN #{Project.table_name} ON #{Project.table_name}.id = #{Wiki.table_name}.project_id"}
+
def text=(plain)
case Setting.wiki_compression
when 'gzip'
diff --git a/app/views/projects/activity.rhtml b/app/views/projects/activity.rhtml
index c08cd06f9..fa25812ac 100644
--- a/app/views/projects/activity.rhtml
+++ b/app/views/projects/activity.rhtml
@@ -44,8 +44,8 @@
<% content_for :sidebar do %>
<% form_tag({}, :method => :get) do %>
<h3><%= l(:label_activity) %></h3>
-<p><% @event_types.each do |t| %>
-<label><%= check_box_tag "show_#{t}", 1, @scope.include?(t) %> <%= l("label_#{t.singularize}_plural")%></label><br />
+<p><% @activity.event_types.each do |t| %>
+<label><%= check_box_tag "show_#{t}", 1, @activity.scope.include?(t) %> <%= l("label_#{t.singularize}_plural")%></label><br />
<% end %></p>
<% if @project && @project.active_children.any? %>
<p><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label></p>