summaryrefslogtreecommitdiffstats
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2009-04-08 19:11:30 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2009-04-08 19:11:30 +0000
commit10cbdf5d96515ecfc74f84a7475327bcca69f28b (patch)
tree4b8c1d66547d4dd7ed62efc06a702711ecaf7d8e /app/models/issue.rb
parentc90878c8173c77d229f183a1850ece49f550cce0 (diff)
downloadredmine-10cbdf5d96515ecfc74f84a7475327bcca69f28b.tar.gz
redmine-10cbdf5d96515ecfc74f84a7475327bcca69f28b.zip
Create the journal after issue save (#3140).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@2669 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb50
1 files changed, 26 insertions, 24 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index e7360d3d7..c3627ddb2 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -56,6 +56,8 @@ class Issue < ActiveRecord::Base
named_scope :open, :conditions => ["#{IssueStatus.table_name}.is_closed = ?", false], :include => :status
+ after_save :create_journal
+
# Returns true if usr or current user is allowed to view the issue
def visible?(usr=nil)
(usr || User.current).allowed_to?(:view_issues, self.project)
@@ -154,30 +156,6 @@ class Issue < ActiveRecord::Base
end
end
- def before_save
- if @current_journal
- # attributes changes
- (Issue.column_names - %w(id description lock_version created_on updated_on)).each {|c|
- @current_journal.details << JournalDetail.new(:property => 'attr',
- :prop_key => c,
- :old_value => @issue_before_change.send(c),
- :value => send(c)) unless send(c)==@issue_before_change.send(c)
- }
- # custom fields changes
- custom_values.each {|c|
- next if (@custom_values_before_change[c.custom_field_id]==c.value ||
- (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
- @current_journal.details << JournalDetail.new(:property => 'cf',
- :prop_key => c.custom_field_id,
- :old_value => @custom_values_before_change[c.custom_field_id],
- :value => c.value)
- }
- @current_journal.save
- end
- # Save the issue even if the journal is not saved (because empty)
- true
- end
-
def after_save
# Reload is needed in order to get the right status
reload
@@ -301,4 +279,28 @@ class Issue < ActiveRecord::Base
:old_value => obj.filename)
journal.save
end
+
+ # Saves the changes in a Journal
+ # Called after_save
+ def create_journal
+ if @current_journal
+ # attributes changes
+ (Issue.column_names - %w(id description lock_version created_on updated_on)).each {|c|
+ @current_journal.details << JournalDetail.new(:property => 'attr',
+ :prop_key => c,
+ :old_value => @issue_before_change.send(c),
+ :value => send(c)) unless send(c)==@issue_before_change.send(c)
+ }
+ # custom fields changes
+ custom_values.each {|c|
+ next if (@custom_values_before_change[c.custom_field_id]==c.value ||
+ (@custom_values_before_change[c.custom_field_id].blank? && c.value.blank?))
+ @current_journal.details << JournalDetail.new(:property => 'cf',
+ :prop_key => c.custom_field_id,
+ :old_value => @custom_values_before_change[c.custom_field_id],
+ :value => c.value)
+ }
+ @current_journal.save
+ end
+ end
end