@@ -1,45 +1,45 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2013 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 IssueCustomField < CustomField |
|
18 | class IssueCustomField < CustomField | |
19 | has_and_belongs_to_many :projects, :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :foreign_key => "custom_field_id" |
|
19 | has_and_belongs_to_many :projects, :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :foreign_key => "custom_field_id" | |
20 | has_and_belongs_to_many :trackers, :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :foreign_key => "custom_field_id" |
|
20 | has_and_belongs_to_many :trackers, :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :foreign_key => "custom_field_id" | |
21 | has_many :issues, :through => :issue_custom_values |
|
21 | has_many :issues, :through => :issue_custom_values | |
22 |
|
22 | |||
23 | def type_name |
|
23 | def type_name | |
24 | :label_issue_plural |
|
24 | :label_issue_plural | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def visible_by?(project, user=User.current) |
|
27 | def visible_by?(project, user=User.current) | |
28 | super || (roles & user.roles_for_project(project)).present? |
|
28 | super || (roles & user.roles_for_project(project)).present? | |
29 | end |
|
29 | end | |
30 |
|
30 | |||
31 | def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil) |
|
31 | def visibility_by_project_condition(project_key=nil, user=User.current, id_column=nil) | |
32 | sql = super |
|
32 | sql = super | |
33 | id_column ||= id |
|
33 | id_column ||= id | |
34 | tracker_condition = "#{Issue.table_name}.tracker_id IN (SELECT tracker_id FROM #{table_name_prefix}custom_fields_trackers#{table_name_suffix} WHERE custom_field_id = #{id_column})" |
|
34 | tracker_condition = "#{Issue.table_name}.tracker_id IN (SELECT tracker_id FROM #{table_name_prefix}custom_fields_trackers#{table_name_suffix} WHERE custom_field_id = #{id_column})" | |
35 | project_condition = "EXISTS (SELECT 1 FROM #{CustomField.table_name} ifa WHERE ifa.is_for_all = #{connection.quoted_true} AND ifa.id = #{id_column})" + |
|
35 | project_condition = "EXISTS (SELECT 1 FROM #{CustomField.table_name} ifa WHERE ifa.is_for_all = #{ActiveRecord::Base.connection.quoted_true} AND ifa.id = #{id_column})" + | |
36 | " OR #{Issue.table_name}.project_id IN (SELECT project_id FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} WHERE custom_field_id = #{id_column})" |
|
36 | " OR #{Issue.table_name}.project_id IN (SELECT project_id FROM #{table_name_prefix}custom_fields_projects#{table_name_suffix} WHERE custom_field_id = #{id_column})" | |
37 |
|
37 | |||
38 | "((#{sql}) AND (#{tracker_condition}) AND (#{project_condition}))" |
|
38 | "((#{sql}) AND (#{tracker_condition}) AND (#{project_condition}))" | |
39 | end |
|
39 | end | |
40 |
|
40 | |||
41 | def validate_custom_field |
|
41 | def validate_custom_field | |
42 | super |
|
42 | super | |
43 | errors.add(:base, l(:label_role_plural) + ' ' + l('activerecord.errors.messages.blank')) unless visible? || roles.present? |
|
43 | errors.add(:base, l(:label_role_plural) + ' ' + l('activerecord.errors.messages.blank')) unless visible? || roles.present? | |
44 | end |
|
44 | end | |
45 | end |
|
45 | end |
General Comments 0
You need to be logged in to leave comments.
Login now