Project

General

Profile

Patch #7610 » rollback-2.6.3.patch

Frederico Camara, 2015-12-17 20:10

View differences:

redmine/app/controllers/journals_controller.rb 2015-05-22 13:35:53.069405551 -0300
# 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
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
redmine/app/models/issue.rb 2015-05-21 11:53:25.612773462 -0300
end
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 :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/app/models/journal.rb 2015-05-21 11:53:25.619773701 -0300
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.reject{|j| j.rolled_back}.sort_by(&:id).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.full_messages.each {|msg| errors.add :base, msg}; false)
end
def project
journalized.respond_to?(:project) ? journalized.project : nil
end
redmine/app/models/user_preference.rb 2015-05-21 11:53:25.620773743 -0300
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
def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end
def no_self_notified=(value); self[:no_self_notified]=value; end
end
redmine/app/views/issues/_history.html.erb 2015-05-21 11:53:25.620773743 -0300
<% 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-link"><%= link_to(image_tag('cancel.png'), {:controller => 'journals', :action => 'rollback', :id => journal}, :confirm => l(:text_are_you_sure), :method => :post, :title => l(:button_rollback)) %>&nbsp;</div>
<% end %>
<%= avatar(journal.user, :size => "24") %>
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>
<%= content_tag('span', l(:field_is_private), :class => 'private') if journal.private_notes? %></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/app/views/users/_preferences.html.erb 2015-05-21 11:53:25.621773784 -0300
<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/config/locales/en.yml 2015-05-21 11:53:25.621773784 -0300
field_inherit_members: Inherit members
field_generate_password: Generate password
field_must_change_passwd: Must change password at next logon
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/config/routes.rb 2015-05-21 11:53:25.622773824 -0300
match '/journals/diff/:id', :to => 'journals#diff', :id => /\d+/, :via => :get
match '/journals/edit/:id', :to => 'journals#edit', :id => /\d+/, :via => [:get, :post]
match '/journals/rollback/:id', :to => 'journals#rollback', :id => /\d+/, :via => :post
get '/projects/:project_id/issues/gantt', :to => 'gantts#show', :as => 'project_gantt'
get '/issues/gantt', :to => 'gantts#show'
redmine/db/migrate/20140417000000_add_journals_rolled_back.rb 2014-04-17 10:33:21.238634641 -0600
class AddJournalsRolledBack < ActiveRecord::Migration
def up
add_column :journals, :rolled_back, :boolean, :default => 0
end
def down
remove_column :journals, :rolled_back
end
end
redmine/lib/redmine.rb 2015-05-21 11:53:25.623773864 -0300
map.permission :add_issue_notes, {:issues => [:edit, :update, :update_form], :journals => [:new], :attachments => :upload}
map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
map.permission :rollback_issue_notes, {:journals => [:rollback]}
map.permission :view_private_notes, {}, :read => true, :require => :member
map.permission :set_notes_private, {}, :require => :member
map.permission :move_issues, {:issues => [:bulk_edit, :bulk_update]}, :require => :loggedin
(13-13/15)