@@ -1,276 +1,276 | |||||
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 | # Project statuses |
|
19 | # Project statuses | |
20 | STATUS_ACTIVE = 1 |
|
20 | STATUS_ACTIVE = 1 | |
21 | STATUS_ARCHIVED = 9 |
|
21 | STATUS_ARCHIVED = 9 | |
22 |
|
22 | |||
23 | has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" |
|
23 | has_many :members, :include => :user, :conditions => "#{User.table_name}.status=#{User::STATUS_ACTIVE}" | |
24 | has_many :users, :through => :members |
|
24 | has_many :users, :through => :members | |
25 | has_many :enabled_modules, :dependent => :delete_all |
|
25 | has_many :enabled_modules, :dependent => :delete_all | |
26 | has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" |
|
26 | has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position" | |
27 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] |
|
27 | has_many :issues, :dependent => :destroy, :order => "#{Issue.table_name}.created_on DESC", :include => [:status, :tracker] | |
28 | has_many :issue_changes, :through => :issues, :source => :journals |
|
28 | has_many :issue_changes, :through => :issues, :source => :journals | |
29 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" |
|
29 | has_many :versions, :dependent => :destroy, :order => "#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC" | |
30 | has_many :time_entries, :dependent => :delete_all |
|
30 | has_many :time_entries, :dependent => :delete_all | |
31 | has_many :queries, :dependent => :delete_all |
|
31 | has_many :queries, :dependent => :delete_all | |
32 | has_many :documents, :dependent => :destroy |
|
32 | has_many :documents, :dependent => :destroy | |
33 | has_many :news, :dependent => :delete_all, :include => :author |
|
33 | has_many :news, :dependent => :delete_all, :include => :author | |
34 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" |
|
34 | has_many :issue_categories, :dependent => :delete_all, :order => "#{IssueCategory.table_name}.name" | |
35 | has_many :boards, :dependent => :destroy, :order => "position ASC" |
|
35 | has_many :boards, :dependent => :destroy, :order => "position ASC" | |
36 | has_one :repository, :dependent => :destroy |
|
36 | has_one :repository, :dependent => :destroy | |
37 | has_many :changesets, :through => :repository |
|
37 | has_many :changesets, :through => :repository | |
38 | has_one :wiki, :dependent => :destroy |
|
38 | has_one :wiki, :dependent => :destroy | |
39 | # Custom field for the project issues |
|
39 | # Custom field for the project issues | |
40 | has_and_belongs_to_many :issue_custom_fields, |
|
40 | has_and_belongs_to_many :issue_custom_fields, | |
41 | :class_name => 'IssueCustomField', |
|
41 | :class_name => 'IssueCustomField', | |
42 | :order => "#{CustomField.table_name}.position", |
|
42 | :order => "#{CustomField.table_name}.position", | |
43 | :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", |
|
43 | :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", | |
44 | :association_foreign_key => 'custom_field_id' |
|
44 | :association_foreign_key => 'custom_field_id' | |
45 |
|
45 | |||
46 | acts_as_tree :order => "name", :counter_cache => true |
|
46 | acts_as_tree :order => "name", :counter_cache => true | |
47 | acts_as_attachable :view_permission => :view_files, |
|
47 | acts_as_attachable :view_permission => :view_files, | |
48 | :delete_permission => :manage_files |
|
48 | :delete_permission => :manage_files | |
49 |
|
49 | |||
50 | acts_as_customizable |
|
50 | acts_as_customizable | |
51 | acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil |
|
51 | acts_as_searchable :columns => ['name', 'description'], :project_key => 'id', :permission => nil | |
52 | acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"}, |
|
52 | acts_as_event :title => Proc.new {|o| "#{l(:label_project)}: #{o.name}"}, | |
53 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}, |
|
53 | :url => Proc.new {|o| {:controller => 'projects', :action => 'show', :id => o.id}}, | |
54 | :author => nil |
|
54 | :author => nil | |
55 |
|
55 | |||
56 | attr_protected :status, :enabled_module_names |
|
56 | attr_protected :status, :enabled_module_names | |
57 |
|
57 | |||
58 | validates_presence_of :name, :identifier |
|
58 | validates_presence_of :name, :identifier | |
59 | validates_uniqueness_of :name, :identifier |
|
59 | validates_uniqueness_of :name, :identifier | |
60 | validates_associated :repository, :wiki |
|
60 | validates_associated :repository, :wiki | |
61 | validates_length_of :name, :maximum => 30 |
|
61 | validates_length_of :name, :maximum => 30 | |
62 | validates_length_of :homepage, :maximum => 255 |
|
62 | validates_length_of :homepage, :maximum => 255 | |
63 |
validates_length_of :identifier, :in => |
|
63 | validates_length_of :identifier, :in => 2..20 | |
64 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ |
|
64 | validates_format_of :identifier, :with => /^[a-z0-9\-]*$/ | |
65 |
|
65 | |||
66 | before_destroy :delete_all_members |
|
66 | before_destroy :delete_all_members | |
67 |
|
67 | |||
68 | named_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] } } |
|
68 | named_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] } } | |
69 |
|
69 | |||
70 | def identifier=(identifier) |
|
70 | def identifier=(identifier) | |
71 | super unless identifier_frozen? |
|
71 | super unless identifier_frozen? | |
72 | end |
|
72 | end | |
73 |
|
73 | |||
74 | def identifier_frozen? |
|
74 | def identifier_frozen? | |
75 | errors[:identifier].nil? && !(new_record? || identifier.blank?) |
|
75 | errors[:identifier].nil? && !(new_record? || identifier.blank?) | |
76 | end |
|
76 | end | |
77 |
|
77 | |||
78 | def issues_with_subprojects(include_subprojects=false) |
|
78 | def issues_with_subprojects(include_subprojects=false) | |
79 | conditions = nil |
|
79 | conditions = nil | |
80 | if include_subprojects |
|
80 | if include_subprojects | |
81 | ids = [id] + child_ids |
|
81 | ids = [id] + child_ids | |
82 | conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"] |
|
82 | conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"] | |
83 | end |
|
83 | end | |
84 | conditions ||= ["#{Project.table_name}.id = ?", id] |
|
84 | conditions ||= ["#{Project.table_name}.id = ?", id] | |
85 | # Quick and dirty fix for Rails 2 compatibility |
|
85 | # Quick and dirty fix for Rails 2 compatibility | |
86 | Issue.send(:with_scope, :find => { :conditions => conditions }) do |
|
86 | Issue.send(:with_scope, :find => { :conditions => conditions }) do | |
87 | Version.send(:with_scope, :find => { :conditions => conditions }) do |
|
87 | Version.send(:with_scope, :find => { :conditions => conditions }) do | |
88 | yield |
|
88 | yield | |
89 | end |
|
89 | end | |
90 | end |
|
90 | end | |
91 | end |
|
91 | end | |
92 |
|
92 | |||
93 | # returns latest created projects |
|
93 | # returns latest created projects | |
94 | # non public projects will be returned only if user is a member of those |
|
94 | # non public projects will be returned only if user is a member of those | |
95 | def self.latest(user=nil, count=5) |
|
95 | def self.latest(user=nil, count=5) | |
96 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") |
|
96 | find(:all, :limit => count, :conditions => visible_by(user), :order => "created_on DESC") | |
97 | end |
|
97 | end | |
98 |
|
98 | |||
99 | def self.visible_by(user=nil) |
|
99 | def self.visible_by(user=nil) | |
100 | user ||= User.current |
|
100 | user ||= User.current | |
101 | if user && user.admin? |
|
101 | if user && user.admin? | |
102 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" |
|
102 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" | |
103 | elsif user && user.memberships.any? |
|
103 | elsif user && user.memberships.any? | |
104 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))" |
|
104 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND (#{Project.table_name}.is_public = #{connection.quoted_true} or #{Project.table_name}.id IN (#{user.memberships.collect{|m| m.project_id}.join(',')}))" | |
105 | else |
|
105 | else | |
106 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}" |
|
106 | return "#{Project.table_name}.status=#{Project::STATUS_ACTIVE} AND #{Project.table_name}.is_public = #{connection.quoted_true}" | |
107 | end |
|
107 | end | |
108 | end |
|
108 | end | |
109 |
|
109 | |||
110 | def self.allowed_to_condition(user, permission, options={}) |
|
110 | def self.allowed_to_condition(user, permission, options={}) | |
111 | statements = [] |
|
111 | statements = [] | |
112 | base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" |
|
112 | base_statement = "#{Project.table_name}.status=#{Project::STATUS_ACTIVE}" | |
113 | if perm = Redmine::AccessControl.permission(permission) |
|
113 | if perm = Redmine::AccessControl.permission(permission) | |
114 | unless perm.project_module.nil? |
|
114 | unless perm.project_module.nil? | |
115 | # If the permission belongs to a project module, make sure the module is enabled |
|
115 | # If the permission belongs to a project module, make sure the module is enabled | |
116 | base_statement << " AND EXISTS (SELECT em.id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}' AND em.project_id=#{Project.table_name}.id)" |
|
116 | base_statement << " AND EXISTS (SELECT em.id FROM #{EnabledModule.table_name} em WHERE em.name='#{perm.project_module}' AND em.project_id=#{Project.table_name}.id)" | |
117 | end |
|
117 | end | |
118 | end |
|
118 | end | |
119 | if options[:project] |
|
119 | if options[:project] | |
120 | project_statement = "#{Project.table_name}.id = #{options[:project].id}" |
|
120 | project_statement = "#{Project.table_name}.id = #{options[:project].id}" | |
121 | project_statement << " OR #{Project.table_name}.parent_id = #{options[:project].id}" if options[:with_subprojects] |
|
121 | project_statement << " OR #{Project.table_name}.parent_id = #{options[:project].id}" if options[:with_subprojects] | |
122 | base_statement = "(#{project_statement}) AND (#{base_statement})" |
|
122 | base_statement = "(#{project_statement}) AND (#{base_statement})" | |
123 | end |
|
123 | end | |
124 | if user.admin? |
|
124 | if user.admin? | |
125 | # no restriction |
|
125 | # no restriction | |
126 | else |
|
126 | else | |
127 | statements << "1=0" |
|
127 | statements << "1=0" | |
128 | if user.logged? |
|
128 | if user.logged? | |
129 | statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission) |
|
129 | statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" if Role.non_member.allowed_to?(permission) | |
130 | allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id} |
|
130 | allowed_project_ids = user.memberships.select {|m| m.role.allowed_to?(permission)}.collect {|m| m.project_id} | |
131 | statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any? |
|
131 | statements << "#{Project.table_name}.id IN (#{allowed_project_ids.join(',')})" if allowed_project_ids.any? | |
132 | elsif Role.anonymous.allowed_to?(permission) |
|
132 | elsif Role.anonymous.allowed_to?(permission) | |
133 | # anonymous user allowed on public project |
|
133 | # anonymous user allowed on public project | |
134 | statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" |
|
134 | statements << "#{Project.table_name}.is_public = #{connection.quoted_true}" | |
135 | else |
|
135 | else | |
136 | # anonymous user is not authorized |
|
136 | # anonymous user is not authorized | |
137 | end |
|
137 | end | |
138 | end |
|
138 | end | |
139 | statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))" |
|
139 | statements.empty? ? base_statement : "((#{base_statement}) AND (#{statements.join(' OR ')}))" | |
140 | end |
|
140 | end | |
141 |
|
141 | |||
142 | def project_condition(with_subprojects) |
|
142 | def project_condition(with_subprojects) | |
143 | cond = "#{Project.table_name}.id = #{id}" |
|
143 | cond = "#{Project.table_name}.id = #{id}" | |
144 | cond = "(#{cond} OR #{Project.table_name}.parent_id = #{id})" if with_subprojects |
|
144 | cond = "(#{cond} OR #{Project.table_name}.parent_id = #{id})" if with_subprojects | |
145 | cond |
|
145 | cond | |
146 | end |
|
146 | end | |
147 |
|
147 | |||
148 | def self.find(*args) |
|
148 | def self.find(*args) | |
149 | if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/) |
|
149 | if args.first && args.first.is_a?(String) && !args.first.match(/^\d*$/) | |
150 | project = find_by_identifier(*args) |
|
150 | project = find_by_identifier(*args) | |
151 | raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil? |
|
151 | raise ActiveRecord::RecordNotFound, "Couldn't find Project with identifier=#{args.first}" if project.nil? | |
152 | project |
|
152 | project | |
153 | else |
|
153 | else | |
154 | super |
|
154 | super | |
155 | end |
|
155 | end | |
156 | end |
|
156 | end | |
157 |
|
157 | |||
158 | def to_param |
|
158 | def to_param | |
159 | # id is used for projects with a numeric identifier (compatibility) |
|
159 | # id is used for projects with a numeric identifier (compatibility) | |
160 | @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier) |
|
160 | @to_param ||= (identifier.to_s =~ %r{^\d*$} ? id : identifier) | |
161 | end |
|
161 | end | |
162 |
|
162 | |||
163 | def active? |
|
163 | def active? | |
164 | self.status == STATUS_ACTIVE |
|
164 | self.status == STATUS_ACTIVE | |
165 | end |
|
165 | end | |
166 |
|
166 | |||
167 | def archive |
|
167 | def archive | |
168 | # Archive subprojects if any |
|
168 | # Archive subprojects if any | |
169 | children.each do |subproject| |
|
169 | children.each do |subproject| | |
170 | subproject.archive |
|
170 | subproject.archive | |
171 | end |
|
171 | end | |
172 | update_attribute :status, STATUS_ARCHIVED |
|
172 | update_attribute :status, STATUS_ARCHIVED | |
173 | end |
|
173 | end | |
174 |
|
174 | |||
175 | def unarchive |
|
175 | def unarchive | |
176 | return false if parent && !parent.active? |
|
176 | return false if parent && !parent.active? | |
177 | update_attribute :status, STATUS_ACTIVE |
|
177 | update_attribute :status, STATUS_ACTIVE | |
178 | end |
|
178 | end | |
179 |
|
179 | |||
180 | def active_children |
|
180 | def active_children | |
181 | children.select {|child| child.active?} |
|
181 | children.select {|child| child.active?} | |
182 | end |
|
182 | end | |
183 |
|
183 | |||
184 | # Returns an array of the trackers used by the project and its sub projects |
|
184 | # Returns an array of the trackers used by the project and its sub projects | |
185 | def rolled_up_trackers |
|
185 | def rolled_up_trackers | |
186 | @rolled_up_trackers ||= |
|
186 | @rolled_up_trackers ||= | |
187 | Tracker.find(:all, :include => :projects, |
|
187 | Tracker.find(:all, :include => :projects, | |
188 | :select => "DISTINCT #{Tracker.table_name}.*", |
|
188 | :select => "DISTINCT #{Tracker.table_name}.*", | |
189 | :conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id], |
|
189 | :conditions => ["#{Project.table_name}.id = ? OR #{Project.table_name}.parent_id = ?", id, id], | |
190 | :order => "#{Tracker.table_name}.position") |
|
190 | :order => "#{Tracker.table_name}.position") | |
191 | end |
|
191 | end | |
192 |
|
192 | |||
193 | # Deletes all project's members |
|
193 | # Deletes all project's members | |
194 | def delete_all_members |
|
194 | def delete_all_members | |
195 | Member.delete_all(['project_id = ?', id]) |
|
195 | Member.delete_all(['project_id = ?', id]) | |
196 | end |
|
196 | end | |
197 |
|
197 | |||
198 | # Users issues can be assigned to |
|
198 | # Users issues can be assigned to | |
199 | def assignable_users |
|
199 | def assignable_users | |
200 | members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort |
|
200 | members.select {|m| m.role.assignable?}.collect {|m| m.user}.sort | |
201 | end |
|
201 | end | |
202 |
|
202 | |||
203 | # Returns the mail adresses of users that should be always notified on project events |
|
203 | # Returns the mail adresses of users that should be always notified on project events | |
204 | def recipients |
|
204 | def recipients | |
205 | members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail} |
|
205 | members.select {|m| m.mail_notification? || m.user.mail_notification?}.collect {|m| m.user.mail} | |
206 | end |
|
206 | end | |
207 |
|
207 | |||
208 | # Returns an array of all custom fields enabled for project issues |
|
208 | # Returns an array of all custom fields enabled for project issues | |
209 | # (explictly associated custom fields and custom fields enabled for all projects) |
|
209 | # (explictly associated custom fields and custom fields enabled for all projects) | |
210 | def all_issue_custom_fields |
|
210 | def all_issue_custom_fields | |
211 | @all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort |
|
211 | @all_issue_custom_fields ||= (IssueCustomField.for_all + issue_custom_fields).uniq.sort | |
212 | end |
|
212 | end | |
213 |
|
213 | |||
214 | def project |
|
214 | def project | |
215 | self |
|
215 | self | |
216 | end |
|
216 | end | |
217 |
|
217 | |||
218 | def <=>(project) |
|
218 | def <=>(project) | |
219 | name.downcase <=> project.name.downcase |
|
219 | name.downcase <=> project.name.downcase | |
220 | end |
|
220 | end | |
221 |
|
221 | |||
222 | def to_s |
|
222 | def to_s | |
223 | name |
|
223 | name | |
224 | end |
|
224 | end | |
225 |
|
225 | |||
226 | # Returns a short description of the projects (first lines) |
|
226 | # Returns a short description of the projects (first lines) | |
227 | def short_description(length = 255) |
|
227 | def short_description(length = 255) | |
228 | description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description |
|
228 | description.gsub(/^(.{#{length}}[^\n]*).*$/m, '\1').strip if description | |
229 | end |
|
229 | end | |
230 |
|
230 | |||
231 | def allows_to?(action) |
|
231 | def allows_to?(action) | |
232 | if action.is_a? Hash |
|
232 | if action.is_a? Hash | |
233 | allowed_actions.include? "#{action[:controller]}/#{action[:action]}" |
|
233 | allowed_actions.include? "#{action[:controller]}/#{action[:action]}" | |
234 | else |
|
234 | else | |
235 | allowed_permissions.include? action |
|
235 | allowed_permissions.include? action | |
236 | end |
|
236 | end | |
237 | end |
|
237 | end | |
238 |
|
238 | |||
239 | def module_enabled?(module_name) |
|
239 | def module_enabled?(module_name) | |
240 | module_name = module_name.to_s |
|
240 | module_name = module_name.to_s | |
241 | enabled_modules.detect {|m| m.name == module_name} |
|
241 | enabled_modules.detect {|m| m.name == module_name} | |
242 | end |
|
242 | end | |
243 |
|
243 | |||
244 | def enabled_module_names=(module_names) |
|
244 | def enabled_module_names=(module_names) | |
245 | enabled_modules.clear |
|
245 | enabled_modules.clear | |
246 | module_names = [] unless module_names && module_names.is_a?(Array) |
|
246 | module_names = [] unless module_names && module_names.is_a?(Array) | |
247 | module_names.each do |name| |
|
247 | module_names.each do |name| | |
248 | enabled_modules << EnabledModule.new(:name => name.to_s) |
|
248 | enabled_modules << EnabledModule.new(:name => name.to_s) | |
249 | end |
|
249 | end | |
250 | end |
|
250 | end | |
251 |
|
251 | |||
252 | # Returns an auto-generated project identifier based on the last identifier used |
|
252 | # Returns an auto-generated project identifier based on the last identifier used | |
253 | def self.next_identifier |
|
253 | def self.next_identifier | |
254 | p = Project.find(:first, :order => 'created_on DESC') |
|
254 | p = Project.find(:first, :order => 'created_on DESC') | |
255 | p.nil? ? nil : p.identifier.to_s.succ |
|
255 | p.nil? ? nil : p.identifier.to_s.succ | |
256 | end |
|
256 | end | |
257 |
|
257 | |||
258 | protected |
|
258 | protected | |
259 | def validate |
|
259 | def validate | |
260 | errors.add(parent_id, " must be a root project") if parent and parent.parent |
|
260 | errors.add(parent_id, " must be a root project") if parent and parent.parent | |
261 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 |
|
261 | errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 | |
262 | errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/) |
|
262 | errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/) | |
263 | end |
|
263 | end | |
264 |
|
264 | |||
265 | private |
|
265 | private | |
266 | def allowed_permissions |
|
266 | def allowed_permissions | |
267 | @allowed_permissions ||= begin |
|
267 | @allowed_permissions ||= begin | |
268 | module_names = enabled_modules.collect {|m| m.name} |
|
268 | module_names = enabled_modules.collect {|m| m.name} | |
269 | Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} |
|
269 | Redmine::AccessControl.modules_permissions(module_names).collect {|p| p.name} | |
270 | end |
|
270 | end | |
271 | end |
|
271 | end | |
272 |
|
272 | |||
273 | def allowed_actions |
|
273 | def allowed_actions | |
274 | @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten |
|
274 | @actions_allowed ||= allowed_permissions.inject([]) { |actions, permission| actions += Redmine::AccessControl.allowed_actions(permission) }.flatten | |
275 | end |
|
275 | end | |
276 | end |
|
276 | end |
@@ -1,49 +1,49 | |||||
1 | <%= error_messages_for 'project' %> |
|
1 | <%= error_messages_for 'project' %> | |
2 |
|
2 | |||
3 | <div class="box"> |
|
3 | <div class="box"> | |
4 | <!--[form:project]--> |
|
4 | <!--[form:project]--> | |
5 | <p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p> |
|
5 | <p><%= f.text_field :name, :required => true %><br /><em><%= l(:text_caracters_maximum, 30) %></em></p> | |
6 |
|
6 | |||
7 | <% if User.current.admin? and !@root_projects.empty? %> |
|
7 | <% if User.current.admin? and !@root_projects.empty? %> | |
8 | <p><%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %></p> |
|
8 | <p><%= f.select :parent_id, (@root_projects.collect {|p| [p.name, p.id]}), { :include_blank => true } %></p> | |
9 | <% end %> |
|
9 | <% end %> | |
10 |
|
10 | |||
11 | <p><%= f.text_area :description, :rows => 5, :class => 'wiki-edit' %></p> |
|
11 | <p><%= f.text_area :description, :rows => 5, :class => 'wiki-edit' %></p> | |
12 | <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %> |
|
12 | <p><%= f.text_field :identifier, :required => true, :disabled => @project.identifier_frozen? %> | |
13 | <% unless @project.identifier_frozen? %> |
|
13 | <% unless @project.identifier_frozen? %> | |
14 |
<br /><em><%= l(:text_length_between, |
|
14 | <br /><em><%= l(:text_length_between, 2, 20) %> <%= l(:text_project_identifier_info) %></em> | |
15 | <% end %></p> |
|
15 | <% end %></p> | |
16 | <p><%= f.text_field :homepage, :size => 60 %></p> |
|
16 | <p><%= f.text_field :homepage, :size => 60 %></p> | |
17 | <p><%= f.check_box :is_public %></p> |
|
17 | <p><%= f.check_box :is_public %></p> | |
18 | <%= wikitoolbar_for 'project_description' %> |
|
18 | <%= wikitoolbar_for 'project_description' %> | |
19 |
|
19 | |||
20 | <% @project.custom_field_values.each do |value| %> |
|
20 | <% @project.custom_field_values.each do |value| %> | |
21 | <p><%= custom_field_tag_with_label :project, value %></p> |
|
21 | <p><%= custom_field_tag_with_label :project, value %></p> | |
22 | <% end %> |
|
22 | <% end %> | |
23 | <%= call_hook(:view_projects_form, :project => @project, :form => f) %> |
|
23 | <%= call_hook(:view_projects_form, :project => @project, :form => f) %> | |
24 | </div> |
|
24 | </div> | |
25 |
|
25 | |||
26 | <% unless @trackers.empty? %> |
|
26 | <% unless @trackers.empty? %> | |
27 | <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend> |
|
27 | <fieldset class="box"><legend><%=l(:label_tracker_plural)%></legend> | |
28 | <% @trackers.each do |tracker| %> |
|
28 | <% @trackers.each do |tracker| %> | |
29 | <label class="floating"> |
|
29 | <label class="floating"> | |
30 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> |
|
30 | <%= check_box_tag 'project[tracker_ids][]', tracker.id, @project.trackers.include?(tracker) %> | |
31 | <%= tracker %> |
|
31 | <%= tracker %> | |
32 | </label> |
|
32 | </label> | |
33 | <% end %> |
|
33 | <% end %> | |
34 | <%= hidden_field_tag 'project[tracker_ids][]', '' %> |
|
34 | <%= hidden_field_tag 'project[tracker_ids][]', '' %> | |
35 | </fieldset> |
|
35 | </fieldset> | |
36 | <% end %> |
|
36 | <% end %> | |
37 |
|
37 | |||
38 | <% unless @issue_custom_fields.empty? %> |
|
38 | <% unless @issue_custom_fields.empty? %> | |
39 | <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend> |
|
39 | <fieldset class="box"><legend><%=l(:label_custom_field_plural)%></legend> | |
40 | <% @issue_custom_fields.each do |custom_field| %> |
|
40 | <% @issue_custom_fields.each do |custom_field| %> | |
41 | <label class="floating"> |
|
41 | <label class="floating"> | |
42 | <%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %> |
|
42 | <%= check_box_tag 'project[issue_custom_field_ids][]', custom_field.id, (@project.all_issue_custom_fields.include? custom_field), (custom_field.is_for_all? ? {:disabled => "disabled"} : {}) %> | |
43 | <%= custom_field.name %> |
|
43 | <%= custom_field.name %> | |
44 | </label> |
|
44 | </label> | |
45 | <% end %> |
|
45 | <% end %> | |
46 | <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> |
|
46 | <%= hidden_field_tag 'project[issue_custom_field_ids][]', '' %> | |
47 | </fieldset> |
|
47 | </fieldset> | |
48 | <% end %> |
|
48 | <% end %> | |
49 | <!--[eoform:project]--> |
|
49 | <!--[eoform:project]--> |
General Comments 0
You need to be logged in to leave comments.
Login now