Project

General

Profile

Feature #421 » issue_extensions_issue_patch.rb

Takashi Takebayashi, 06/03/2010 01:37 PM

 
1
# Issue Extensions plugin for Redmine
2
# Copyright (C) 2010  Takashi Takebayashi
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
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
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17
require_dependency 'issue'
18

    
19
module IssueExtensionsIssuePatch
20
  def self.included base
21
    base.extend ClassMethods
22
    base.send :include, InstanceMethods
23
    base.class_eval do
24
      alias_method_chain :validate, :issue_extensions
25
    end
26
  end
27

    
28
  module ClassMethods
29
  end
30

    
31
  module InstanceMethods
32
    def validate_with_issue_extensions
33
      validate_without_issue_extensions
34
      project = Project.find read_attribute :project_id
35
      unless project.module_enabled? :issue_extensions == nil
36
        tracker = Tracker.find :first, :conditions => ["name = (?)", 'バグ']
37
        issue_status = IssueStatus.find :first, :conditions => ["name = (?)", '終了']
38
        if tracker != nil && issue_status != nil
39
          if tracker.id == read_attribute(:tracker_id) && issue_status.id == read_attribute(:status_id)
40
            custom_field = CustomField.find :first, :conditions => ["type = (?) and name = (?)", 'IssueCustomField', '修正バージョン']
41
            if custom_field != nil
42
              custom_values.each {|c|
43
                if !c.custom_field_id.blank?
44
                  if c.custom_field_id == custom_field.id
45
                    errors.add_to_base custom_field.name + " を入力してください。" if c.value.blank?
46
                  end
47
                end
48
              }
49
            end
50
          end
51
        end
52
      end
53
    end
54
  end
55
end
56
Issue.send(:include, IssueExtensionsIssuePatch)
    (1-1/1)