Patch #7610 » rollback-2.1.0-v2.patch
| redmine-2.1.0-modified/app/controllers/journals_controller.rb 2012-10-04 13:06:21.013138052 -0600 | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class JournalsController < ApplicationController
|
||
|
before_filter :find_journal, :only => [:edit, :diff]
|
||
|
before_filter :find_journal, :only => [:edit, :diff, :rollback]
|
||
|
before_filter :find_issue, :only => [:new]
|
||
|
before_filter :find_optional_project, :only => [:index]
|
||
|
before_filter :authorize, :only => [:new, :edit, :diff]
|
||
|
before_filter :authorize, :only => [:new, :edit, :diff, :rollback]
|
||
|
accept_rss_auth :index
|
||
|
menu_item :issues
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
private
|
||
|
def rollback
|
||
|
(render_403; return false) unless @journal.can_rollback?(User.current)
|
||
|
if @journal.rollback
|
||
|
flash[:notice] = l(:notice_successful_update)
|
||
|
else
|
||
|
# can't seem to bring in the helper method 'error_messages_for'
|
||
|
# and injecting it into show.rhtml doesn't seem to work, since
|
||
|
# the @issue loses the errors on redirect (due to issue reload)
|
||
|
flash[:error] = "<ul>" + @journal.errors.full_messages.map {|msg| "<li>" + ERB::Util.html_escape(msg) + "</li>"}.join + "</ul>"
|
||
|
end
|
||
|
respond_to do |format|
|
||
|
format.html { redirect_to :controller => 'issues', :action => 'show', :id => @journal.journalized_id }
|
||
|
format.api { render_validation_errors(@issue) }
|
||
|
end
|
||
|
end
|
||
|
private
|
||
|
def find_journal
|
||
|
@journal = Journal.find(params[:id])
|
||
| redmine-2.1.0-modified/app/models/issue.rb 2012-10-05 10:00:05.257588764 -0600 | ||
|---|---|---|
|
scope
|
||
|
end
|
||
|
# rollback the changes in a journal, the journal is destroyed on success
|
||
|
def rollback(journal)
|
||
|
# only allow rollback of journal details for the last journal
|
||
|
(errors.add_to_base(l(:notice_locking_conflict)); return) if !journal.last_valid_journal?(journals)
|
||
|
# avoid the creation of journals during rollback (see 'attachment removed')
|
||
|
@rolling_back = true
|
||
|
# roll back each change detailed by the journal
|
||
|
journal.details.each do |d|
|
||
|
case d.property
|
||
|
# issue attribute change
|
||
|
when 'attr'; send "#{d.prop_key}=", d.old_value
|
||
|
# rollback custom field change
|
||
|
when 'cf'; custom_field_values.each {|v| v.value = d.old_value if v.custom_field_id == d.prop_key.to_i}
|
||
|
# remove any added attachments (we can't recover removed attachments)
|
||
|
when 'attachment'; attachments.each {|v| attachments.delete(v) if v.id == d.prop_key.to_i}
|
||
|
end
|
||
|
end
|
||
|
# allow the creation of journals again
|
||
|
remove_instance_variable(:@rolling_back)
|
||
|
# destroy the journal once we save the issue changes
|
||
|
if save(:validate => false)
|
||
|
journal.rolled_back = true
|
||
|
journal.save
|
||
|
end
|
||
|
end
|
||
|
# Return true if the issue is closed, otherwise false
|
||
|
def closed?
|
||
|
self.status.is_closed?
|
||
| redmine-2.1.0-modified/app/models/journal.rb 2012-10-05 10:47:26.589561668 -0600 | ||
|---|---|---|
|
usr && usr.logged? && (usr.allowed_to?(:edit_issue_notes, project) || (self.user == usr && usr.allowed_to?(:edit_own_issue_notes, project)))
|
||
|
end
|
||
|
def last_valid_journal?(journals)
|
||
|
self == journals.last
|
||
|
end
|
||
|
def can_rollback?(usr = nil)
|
||
|
user ||= User.current
|
||
|
editable_by?(user) && (details.empty? || user.allowed_to?(:rollback_issue_notes, project))
|
||
|
end
|
||
|
|
||
|
def show?
|
||
|
!self.rolled_back || User.current.pref.hide_rolled_back_issue_notes == '0'
|
||
|
end
|
||
|
# rollback the changes in a journal, the journal is destroyed on success
|
||
|
def rollback
|
||
|
# we could have details to rollback, so let the issue take care of this more complicated task
|
||
|
journalized.rollback(self) ||
|
||
|
# on failure, collect the error messages from the issue on failure
|
||
|
(journalized.errors.each_full {|msg| errors.add_to_base(msg)}; false)
|
||
|
end
|
||
|
def project
|
||
|
journalized.respond_to?(:project) ? journalized.project : nil
|
||
|
end
|
||
| redmine-2.1.0-modified/app/models/user_preference.rb 2012-10-05 10:48:30.269561061 -0600 | ||
|---|---|---|
|
def warn_on_leaving_unsaved; self[:warn_on_leaving_unsaved] || '1'; end
|
||
|
def warn_on_leaving_unsaved=(value); self[:warn_on_leaving_unsaved]=value; end
|
||
|
def hide_rolled_back_issue_notes; self[:hide_rolled_back_issue_notes] || '0'; end
|
||
|
def hide_rolled_back_issue_notes=(value); self[:hide_rolled_back_issue_notes]=value; end
|
||
|
end
|
||
| redmine-2.1.0-modified/app/views/issues/_history.html.erb 2012-10-05 10:51:24.237559399 -0600 | ||
|---|---|---|
|
<% reply_links = authorize_for('issues', 'edit') -%>
|
||
|
<% for journal in journals %>
|
||
|
<% if journal.show? %>
|
||
|
<% if journal.rolled_back? %>
|
||
|
<strike>
|
||
|
<% end %>
|
||
|
<div id="change-<%= journal.id %>" class="<%= journal.css_classes %>">
|
||
|
<div id="note-<%= journal.indice %>">
|
||
|
<h4><%= link_to "##{journal.indice}", {:anchor => "note-#{journal.indice}"}, :class => "journal-link" %>
|
||
|
<% if journal.last_valid_journal?(journals) && journal.can_rollback? %>
|
||
|
<div class="journal-rollback"><%= link_to(image_tag('cancel.png'), {:controller => 'journals', :action => 'rollback', :id => journal}, :confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_rollback_journal)) %> </div>
|
||
|
<% end %>
|
||
|
<%= avatar(journal.user, :size => "24") %>
|
||
|
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></h4>
|
||
| ... | ... | |
|
</div>
|
||
|
</div>
|
||
|
<%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %>
|
||
|
<% if journal.rolled_back? %>
|
||
|
</strike>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<% heads_for_wiki_formatter if User.current.allowed_to?(:edit_issue_notes, issue.project) || User.current.allowed_to?(:edit_own_issue_notes, issue.project) %>
|
||
| redmine-2.1.0-modified/app/views/users/_preferences.html.erb 2012-10-05 10:40:22.869565707 -0600 | ||
|---|---|---|
|
<p><%= pref_fields.time_zone_select :time_zone, nil, :include_blank => true %></p>
|
||
|
<p><%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %></p>
|
||
|
<p><%= pref_fields.check_box :warn_on_leaving_unsaved %></p>
|
||
|
<p><%= pref_fields.check_box :hide_rolled_back_issue_notes %></p>
|
||
|
<% end %>
|
||
| redmine-2.1.0-modified/config/locales/en.yml 2012-10-05 10:57:21.185555995 -0600 | ||
|---|---|---|
|
field_core_fields: Standard fields
|
||
|
field_timeout: "Timeout (in seconds)"
|
||
|
field_board_parent: Parent forum
|
||
|
field_hide_rolled_back_issue_notes: "Hide rolled-back issue notes"
|
||
|
setting_app_title: Application title
|
||
|
setting_app_subtitle: Application subtitle
|
||
| ... | ... | |
|
permission_export_wiki_pages: Export wiki pages
|
||
|
permission_manage_subtasks: Manage subtasks
|
||
|
permission_manage_related_issues: Manage related issues
|
||
|
permission_rollback_issue_notes: Rollback issue notes
|
||
|
project_module_issue_tracking: Issue tracking
|
||
|
project_module_time_tracking: Time tracking
|
||
| ... | ... | |
|
button_delete_my_account: Delete my account
|
||
|
button_close: Close
|
||
|
button_reopen: Reopen
|
||
|
button_rollback: Rollback
|
||
|
status_active: active
|
||
|
status_registered: registered
|
||
| redmine-2.1.0-modified/db/migrate/20130128120000_add_journals_rolled_back.rb 2013-01-28 12:19:17.517695320 -0700 | ||
|---|---|---|
|
class AddJournalsRolledBack < ActiveRecord::Migration
|
||
|
def up
|
||
|
add_column :journals, :rolled_back, :boolean, :default => 0
|
||
|
end
|
||
|
def down
|
||
|
remove_column :journals, :rolled_back
|
||
|
end
|
||
|
end
|
||