summaryrefslogtreecommitdiffstats
path: root/app/controllers/projects_controller.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers/projects_controller.rb')
-rw-r--r--app/controllers/projects_controller.rb115
1 files changed, 53 insertions, 62 deletions
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index 0613f9e40..2f5e24e28 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -22,6 +22,7 @@ class ProjectsController < ApplicationController
before_filter :find_project, :except => [ :index, :list, :add ]
before_filter :authorize, :except => [ :index, :list, :add, :archive, :unarchive, :destroy ]
before_filter :require_admin, :only => [ :add, :archive, :unarchive, :destroy ]
+ accept_key_auth :activity, :calendar
cache_sweeper :project_sweeper, :only => [ :add, :edit, :archive, :unarchive, :destroy ]
cache_sweeper :issue_sweeper, :only => [ :add_issue ]
@@ -97,8 +98,7 @@ class ProjectsController < ApplicationController
@trackers = Tracker.find(:all, :order => 'position')
@open_issues_by_tracker = Issue.count(:group => :tracker, :joins => "INNER JOIN #{IssueStatus.table_name} ON #{IssueStatus.table_name}.id = #{Issue.table_name}.status_id", :conditions => ["project_id=? and #{IssueStatus.table_name}.is_closed=?", @project.id, false])
@total_issues_by_tracker = Issue.count(:group => :tracker, :conditions => ["project_id=?", @project.id])
-
- @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
+ @key = User.current.rss_key
end
def settings
@@ -224,7 +224,7 @@ class ProjectsController < ApplicationController
Attachment.create(:container => @document, :file => a, :author => logged_in_user) unless a.size == 0
} if params[:attachments] and params[:attachments].is_a? Array
flash[:notice] = l(:notice_successful_create)
- Mailer.deliver_document_add(@document) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
+ Mailer.deliver_document_add(@document) #if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :action => 'list_documents', :id => @project
end
end
@@ -268,7 +268,7 @@ class ProjectsController < ApplicationController
if @issue.save
@attachments.each(&:save)
flash[:notice] = l(:notice_successful_create)
- Mailer.deliver_issue_add(@issue) if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
+ Mailer.deliver_issue_add(@issue) #if Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :action => 'list_issues', :id => @project
end
end
@@ -383,7 +383,7 @@ class ProjectsController < ApplicationController
redirect_to :action => 'list_issues', :id => @project and return unless @issues
@projects = []
# find projects to which the user is allowed to move the issue
- @logged_in_user.memberships.each {|m| @projects << m.project if Permission.allowed_to_role("projects/move_issues", m.role)}
+ User.current.memberships.each {|m| @projects << m.project if m.role.allowed_to?(:controller => 'projects', :action => 'move_issues')}
# issue can be moved to any tracker
@trackers = Tracker.find(:all)
if request.post? and params[:new_project_id] and params[:new_tracker_id]
@@ -424,7 +424,11 @@ class ProjectsController < ApplicationController
# Show news list of @project
def list_news
@news_pages, @news = paginate :news, :per_page => 10, :conditions => ["project_id=?", @project.id], :include => :author, :order => "#{News.table_name}.created_on DESC"
- render :action => "list_news", :layout => false if request.xhr?
+
+ respond_to do |format|
+ format.html { render :layout => false if request.xhr? }
+ format.atom { render_feed(@news, :title => "#{@project.name}: #{l(:label_news_plural)}") }
+ end
end
def add_file
@@ -437,7 +441,7 @@ class ProjectsController < ApplicationController
a = Attachment.create(:container => @version, :file => file, :author => logged_in_user)
@attachments << a unless a.new_record?
} if params[:attachments] and params[:attachments].is_a? Array
- Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
+ Mailer.deliver_attachments_add(@attachments) if !@attachments.empty? #and Permission.find_by_controller_and_action(params[:controller], params[:action]).mail_enabled?
redirect_to :controller => 'projects', :action => 'list_files', :id => @project
end
@versions = @project.versions.sort
@@ -471,80 +475,67 @@ class ProjectsController < ApplicationController
@year ||= Date.today.year
@month ||= Date.today.month
- @date_from = Date.civil(@year, @month, 1)
- @date_to = @date_from >> 1
+ case params[:format]
+ when 'rss'
+ # 30 last days
+ @date_from = Date.today - 30
+ @date_to = Date.today + 1
+ else
+ # current month
+ @date_from = Date.civil(@year, @month, 1)
+ @date_to = @date_from >> 1
+ end
- @events_by_day = Hash.new { |h,k| h[k] = [] }
+ @event_types = %w(issues news attachments documents wiki_edits revisions)
+ @event_types.delete('wiki_edits') unless @project.wiki
+ @event_types.delete('changesets') unless @project.repository
- unless params[:show_issues] == "0"
- @project.issues.find(:all, :include => [:author], :conditions => ["#{Issue.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i|
- @events_by_day[i.created_on.to_date] << i
- }
- @project.issue_changes.find(:all, :include => :details, :conditions => ["(#{Journal.table_name}.created_on BETWEEN ? AND ?) AND (#{JournalDetail.table_name}.prop_key = 'status_id')", @date_from, @date_to] ).each { |i|
- @events_by_day[i.created_on.to_date] << i
- }
- @show_issues = 1
+ @scope = @event_types.select {|t| params["show_#{t}"]}
+ # default events if none is specified in parameters
+ @scope = (@event_types - %w(wiki_edits))if @scope.empty?
+
+ @events = []
+
+ if @scope.include?('issues')
+ @events += @project.issues.find(:all, :include => [:author, :tracker], :conditions => ["#{Issue.table_name}.created_on>=? and #{Issue.table_name}.created_on<=?", @date_from, @date_to] )
end
- unless params[:show_news] == "0"
- @project.news.find(:all, :conditions => ["#{News.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to], :include => :author ).each { |i|
- @events_by_day[i.created_on.to_date] << i
- }
- @show_news = 1
+ if @scope.include?('news')
+ @events += @project.news.find(:all, :conditions => ["#{News.table_name}.created_on>=? and #{News.table_name}.created_on<=?", @date_from, @date_to], :include => :author )
end
- unless params[:show_files] == "0"
- Attachment.find(:all, :select => "#{Attachment.table_name}.*",
- :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id",
- :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to],
- :include => :author ).each { |i|
- @events_by_day[i.created_on.to_date] << i
- }
- @show_files = 1
+ if @scope.include?('attachments')
+ @events += Attachment.find(:all, :select => "#{Attachment.table_name}.*", :joins => "LEFT JOIN #{Version.table_name} ON #{Version.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Version' and #{Version.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
end
- unless params[:show_documents] == "0"
- @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on BETWEEN ? AND ?", @date_from, @date_to] ).each { |i|
- @events_by_day[i.created_on.to_date] << i
- }
- Attachment.find(:all, :select => "attachments.*",
- :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id",
- :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on BETWEEN ? AND ? ", @project.id, @date_from, @date_to],
- :include => :author ).each { |i|
- @events_by_day[i.created_on.to_date] << i
- }
- @show_documents = 1
+ if @scope.include?('documents')
+ @events += @project.documents.find(:all, :conditions => ["#{Document.table_name}.created_on>=? and #{Document.table_name}.created_on<=?", @date_from, @date_to] )
+ @events += Attachment.find(:all, :select => "attachments.*", :joins => "LEFT JOIN #{Document.table_name} ON #{Document.table_name}.id = #{Attachment.table_name}.container_id", :conditions => ["#{Attachment.table_name}.container_type='Document' and #{Document.table_name}.project_id=? and #{Attachment.table_name}.created_on>=? and #{Attachment.table_name}.created_on<=?", @project.id, @date_from, @date_to], :include => :author )
end
- unless @project.wiki.nil? || params[:show_wiki_edits] == "0"
+ if @scope.include?('wiki_edits') && @project.wiki
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}.#{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 "
conditions = ["#{Wiki.table_name}.project_id = ? AND #{WikiContent.versioned_table_name}.updated_on BETWEEN ? AND ?",
@project.id, @date_from, @date_to]
- WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions).each { |i|
- # We provide this alias so all events can be treated in the same manner
- def i.created_on
- self.updated_on
- end
- @events_by_day[i.created_on.to_date] << i
- }
- @show_wiki_edits = 1
+ @events += WikiContent.versioned_class.find(:all, :select => select, :joins => joins, :conditions => conditions)
end
- unless @project.repository.nil? || params[:show_changesets] == "0"
- @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to]).each { |i|
- def i.created_on
- self.committed_on
- end
- @events_by_day[i.created_on.to_date] << i
- }
- @show_changesets = 1
+ if @scope.include?('revisions') && @project.repository
+ @events += @project.repository.changesets.find(:all, :conditions => ["#{Changeset.table_name}.committed_on BETWEEN ? AND ?", @date_from, @date_to])
end
- render :layout => false if request.xhr?
+ @events_by_day = @events.group_by(&:event_date)
+
+ respond_to do |format|
+ format.html { render :layout => false if request.xhr? }
+ format.atom { render_feed(@events, :title => "#{@project.name}: #{l(:label_activity)}") }
+ end
end
def calendar
@@ -630,7 +621,7 @@ class ProjectsController < ApplicationController
def feeds
@queries = @project.queries.find :all, :conditions => ["is_public=? or user_id=?", true, (logged_in_user ? logged_in_user.id : 0)]
- @key = logged_in_user.get_or_create_rss_key.value if logged_in_user
+ @key = User.current.rss_key
end
private