refactor the welcome controller

pull/1186/head
Martin Linkhorst 12 years ago
parent bbe460dfbc
commit b30fac4a59
  1. 20
      app/controllers/welcome_controller.rb
  2. 14
      app/models/news.rb
  3. 16
      app/models/project.rb
  4. 8
      app/models/user.rb
  5. 9
      app/views/welcome/robots.html.erb
  6. 9
      app/views/welcome/robots.text.erb

@ -13,15 +13,23 @@
#++
class WelcomeController < ApplicationController
caches_action :robots
def index
@news = News.latest User.current
@projects = Project.latest User.current
@news = current_user.latest_news
@projects = current_user.latest_projects
end
def robots
@projects = Project.all_public.active
render :layout => false, :content_type => 'text/plain'
@projects = Project.active.public
respond_to do |format|
format.text # { render :layout => false }
end
end
caches_action :robots
private
def current_user
User.current
end
end

@ -46,6 +46,20 @@ class News < ActiveRecord::Base
find(:all, :limit => count, :conditions => Project.allowed_to_condition(user, :view_news), :include => [ :author, :project ], :order => "#{News.table_name}.created_on DESC")
end
def self.latest_for(user, options = {})
limit = options.fetch(:count) { 5 }
conditions = Project.allowed_to_condition(user, :view_news)
# TODO: remove the includes from here, it's required by Project.allowed_to_condition
# News has nothing to do with it
where(conditions).limit(limit).newest_first.includes(:author, :project)
end
def self.newest_first
order 'created_on DESC'
end
def new_comment(attributes = {})
comments.build(attributes)
end

@ -79,8 +79,8 @@ class Project < ActiveRecord::Base
before_destroy :delete_all_members
scope :has_module, lambda { |mod| { :conditions => ["#{Project.table_name}.id IN (SELECT em.project_id FROM #{EnabledModule.table_name} em WHERE em.name=?)", mod.to_s] } }
scope :active, { :conditions => "#{Project.table_name}.status = #{STATUS_ACTIVE}"}
scope :all_public, { :conditions => { :is_public => true } }
scope :active, where(:status => STATUS_ACTIVE)
scope :public, where(:is_public => true)
scope :visible, lambda { { :conditions => Project.visible_by(User.current) } }
def initialize(attributes = nil, options = {})
@ -131,6 +131,18 @@ class Project < ActiveRecord::Base
find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC")
end
def self.latest_for(user, options = {})
limit = options.fetch(:count) { 5 }
conditions = visible_by(user)
where(conditions).limit(limit).newest_first
end
def self.newest_first
order 'created_on DESC'
end
# Returns a SQL :conditions string used to find all active projects for the specified user.
#
# Examples:

@ -617,6 +617,14 @@ class User < Principal
end
end
def latest_news(options = {})
News.latest_for self, options
end
def latest_projects(options = {})
Project.latest_for self, options
end
protected
# Password length validation based on setting

@ -1,9 +0,0 @@
User-agent: *
<% @projects.each do |p| -%>
Disallow: /projects/<%= p.to_param %>/repository
Disallow: /projects/<%= p.to_param %>/issues
Disallow: /projects/<%= p.to_param %>/activity
<% end -%>
Disallow: /issues/gantt
Disallow: /issues/calendar
Disallow: /activity

@ -0,0 +1,9 @@
User-agent: *
<% @projects.each do |project| -%>
Disallow: <%= project_repository_path(project) %>
Disallow: <%= project_issues_path(project) %>
Disallow: <%= project_activity_path(project) %>
<% end -%>
Disallow: <%= issues_gantt_path %>
Disallow: <%= issues_calendar_path %>
Disallow: <%= activity_path %>
Loading…
Cancel
Save