\r
validates_presence_of :title, :description\r
\r
- # returns last created news\r
- def self.latest\r
- find(:all, :limit => 5, :include => [ :author, :project ], :order => "news.created_on DESC") \r
+ # returns latest news for projects visible by user\r
+ def self.latest(user=nil, count=5)\r
+ find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "news.created_on DESC") \r
end
end
validates_associated :repository\r
validates_format_of :name, :with => /^[\w\s\'\-]*$/i\r
\r
- # returns 5 last created projects\r
- def self.latest\r
- find(:all, :limit => 5, :order => "created_on DESC") \r
+ # returns latest created projects\r
+ # non public projects will be returned only if user is a member of those\r
+ def self.latest(user=nil, count=5)\r
+ find(:all, :limit => count, :conditions => visible_by(user), :order => "projects.created_on DESC") \r
end \r
\r
+ def self.visible_by(user=nil)\r
+ if user && !user.memberships.empty?\r
+ return ["projects.is_public = ? or projects.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true]\r
+ else\r
+ return ["projects.is_public = ?", true]\r
+ end\r
+ end\r
+ \r
# Returns an array of all custom fields enabled for project issues\r
# (explictly associated custom fields and custom fields enabled for all projects)\r
def custom_fields_for_issues(tracker)\r