@@ -19,7 +19,7 class WelcomeController < ApplicationController | |||||
19 | layout 'base' |
|
19 | layout 'base' | |
20 |
|
20 | |||
21 | def index |
|
21 | def index | |
22 | @news = News.latest |
|
22 | @news = News.latest logged_in_user | |
23 | @projects = Project.latest |
|
23 | @projects = Project.latest logged_in_user | |
24 | end |
|
24 | end | |
25 | end |
|
25 | end |
@@ -22,8 +22,8 class News < ActiveRecord::Base | |||||
22 |
|
22 | |||
23 | validates_presence_of :title, :description |
|
23 | validates_presence_of :title, :description | |
24 |
|
24 | |||
25 | # returns last created news |
|
25 | # returns latest news for projects visible by user | |
26 | def self.latest |
|
26 | def self.latest(user=nil, count=5) | |
27 |
find(:all, :limit => |
|
27 | find(:all, :limit => count, :conditions => Project.visible_by(user), :include => [ :author, :project ], :order => "news.created_on DESC") | |
28 | end |
|
28 | end | |
29 | end |
|
29 | end |
@@ -35,11 +35,20 class Project < ActiveRecord::Base | |||||
35 | validates_associated :repository |
|
35 | validates_associated :repository | |
36 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i |
|
36 | validates_format_of :name, :with => /^[\w\s\'\-]*$/i | |
37 |
|
37 | |||
38 |
# returns |
|
38 | # returns latest created projects | |
39 | def self.latest |
|
39 | # non public projects will be returned only if user is a member of those | |
40 | find(:all, :limit => 5, :order => "created_on DESC") |
|
40 | def self.latest(user=nil, count=5) | |
|
41 | find(:all, :limit => count, :conditions => visible_by(user), :order => "projects.created_on DESC") | |||
41 | end |
|
42 | end | |
42 |
|
43 | |||
|
44 | def self.visible_by(user=nil) | |||
|
45 | if user && !user.memberships.empty? | |||
|
46 | return ["projects.is_public = ? or projects.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')})", true] | |||
|
47 | else | |||
|
48 | return ["projects.is_public = ?", true] | |||
|
49 | end | |||
|
50 | end | |||
|
51 | ||||
43 | # Returns an array of all custom fields enabled for project issues |
|
52 | # Returns an array of all custom fields enabled for project issues | |
44 | # (explictly associated custom fields and custom fields enabled for all projects) |
|
53 | # (explictly associated custom fields and custom fields enabled for all projects) | |
45 | def custom_fields_for_issues(tracker) |
|
54 | def custom_fields_for_issues(tracker) |
General Comments 0
You need to be logged in to leave comments.
Login now