@@ -1,25 +1,25 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class WelcomeController < ApplicationController |
|
18 | 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 |
@@ -1,29 +1,29 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class News < ActiveRecord::Base |
|
18 | class News < ActiveRecord::Base | |
19 | belongs_to :project |
|
19 | belongs_to :project | |
20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' |
|
20 | belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' | |
21 | has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" |
|
21 | has_many :comments, :as => :commented, :dependent => :delete_all, :order => "created_on" | |
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 |
@@ -1,61 +1,70 | |||||
1 | # redMine - project management software |
|
1 | # redMine - project management software | |
2 | # Copyright (C) 2006 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | class Project < ActiveRecord::Base |
|
18 | class Project < ActiveRecord::Base | |
19 | has_many :versions, :dependent => :destroy, :order => "versions.effective_date DESC, versions.name DESC" |
|
19 | has_many :versions, :dependent => :destroy, :order => "versions.effective_date DESC, versions.name DESC" | |
20 | has_many :members, :dependent => :delete_all, :include => :user, :conditions => "users.status=#{User::STATUS_ACTIVE}" |
|
20 | has_many :members, :dependent => :delete_all, :include => :user, :conditions => "users.status=#{User::STATUS_ACTIVE}" | |
21 | has_many :users, :through => :members |
|
21 | has_many :users, :through => :members | |
22 | has_many :custom_values, :dependent => :delete_all, :as => :customized |
|
22 | has_many :custom_values, :dependent => :delete_all, :as => :customized | |
23 | has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker] |
|
23 | has_many :issues, :dependent => :destroy, :order => "issues.created_on DESC", :include => [:status, :tracker] | |
24 | has_many :queries, :dependent => :delete_all |
|
24 | has_many :queries, :dependent => :delete_all | |
25 | has_many :documents, :dependent => :destroy |
|
25 | has_many :documents, :dependent => :destroy | |
26 | has_many :news, :dependent => :delete_all, :include => :author |
|
26 | has_many :news, :dependent => :delete_all, :include => :author | |
27 | has_many :issue_categories, :dependent => :delete_all, :order => "issue_categories.name" |
|
27 | has_many :issue_categories, :dependent => :delete_all, :order => "issue_categories.name" | |
28 | has_one :repository, :dependent => :destroy |
|
28 | has_one :repository, :dependent => :destroy | |
29 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_projects', :association_foreign_key => 'custom_field_id' |
|
29 | has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => 'custom_fields_projects', :association_foreign_key => 'custom_field_id' | |
30 | acts_as_tree :order => "name", :counter_cache => true |
|
30 | acts_as_tree :order => "name", :counter_cache => true | |
31 |
|
31 | |||
32 | validates_presence_of :name, :description |
|
32 | validates_presence_of :name, :description | |
33 | validates_uniqueness_of :name |
|
33 | validates_uniqueness_of :name | |
34 | validates_associated :custom_values, :on => :update |
|
34 | validates_associated :custom_values, :on => :update | |
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) | |
46 | tracker.custom_fields.find(:all, :include => :projects, |
|
55 | tracker.custom_fields.find(:all, :include => :projects, | |
47 | :conditions => ["is_for_all=? or project_id=?", true, self.id]) |
|
56 | :conditions => ["is_for_all=? or project_id=?", true, self.id]) | |
48 | #(CustomField.for_all + custom_fields).uniq |
|
57 | #(CustomField.for_all + custom_fields).uniq | |
49 | end |
|
58 | end | |
50 |
|
59 | |||
51 | def all_custom_fields |
|
60 | def all_custom_fields | |
52 | @all_custom_fields ||= IssueCustomField.find(:all, :include => :projects, |
|
61 | @all_custom_fields ||= IssueCustomField.find(:all, :include => :projects, | |
53 | :conditions => ["is_for_all=? or project_id=?", true, self.id]) |
|
62 | :conditions => ["is_for_all=? or project_id=?", true, self.id]) | |
54 | end |
|
63 | end | |
55 |
|
64 | |||
56 | protected |
|
65 | protected | |
57 | def validate |
|
66 | def validate | |
58 | errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
67 | errors.add(parent_id, " must be a root project") if parent and parent.parent | |
59 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and projects_count > 0 |
|
68 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and projects_count > 0 | |
60 | end |
|
69 | end | |
61 | end |
|
70 | end |
General Comments 0
You need to be logged in to leave comments.
Login now