Project

General

Profile

Patch #7610 » rollback-1.1.0.patch

Brian Lindahl, 2011-02-11 20:37

View differences:

redmine-1.1.0-rollback/app/controllers/issues_controller.rb 2011-02-11 10:54:47.912319200 -0700
menu_item :new_issue, :only => [:new, :create]
default_search_scope :issues
before_filter :find_issue, :only => [:show, :edit, :update]
before_filter :find_issue, :only => [:show, :edit, :update, :rollback]
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy]
before_filter :check_project_uniqueness, :only => [:move, :perform_move]
before_filter :find_project, :only => [:new, :create]
......
before_filter :find_optional_project, :only => [:index]
before_filter :check_for_default_issue_status, :only => [:new, :create]
before_filter :build_new_issue_from_params, :only => [:new, :create]
accept_key_auth :index, :show, :create, :update, :destroy
accept_key_auth :index, :show, :create, :update, :destroy, :rollback
rescue_from Query::StatementInvalid, :with => :query_statement_invalid
......
verify :method => [:post, :delete],
:only => :destroy,
:render => { :nothing => true, :status => :method_not_allowed }
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
verify :method => :post, :only => :rollback, :render => { :nothing => true, :status => :method_not_allowed }
def index
retrieve_query
......
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
end
def rollback
if @issue.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>" + @issue.errors.full_messages.map {|msg| "<li>" + ERB::Util.html_escape(msg) + "</li>"}.join + "</ul>"
end
respond_to do |format|
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
format.api { render_validation_errors(@issue) }
end
end
def destroy
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f
if @hours > 0
redmine-1.1.0-rollback/app/models/issue.rb 2011-02-11 10:54:47.927944400 -0700
@current_journal
end
# rolls back the last journal entry
def rollback
journal = journals.find(:last, :include => [:details], :order => "#{Journal.table_name}.created_on ASC")
transaction do
old_parent = nil
journal.details.each do |d|
if d.property == 'attr'
if d.prop_key == 'parent_id'
@parent_issue = Issue.find_by_id(d.old_value)
else
send("#{d.prop_key}=", d.old_value)
end
elsif d.property == 'cf'
custom_field_values.each {|v| v.value = d.old_value if v.custom_field_id == d.prop_key.to_i}
elsif d.property == 'attachment'
if d.old_value == nil
@rolling_back = true # avoid journal entries created in 'attachment_removed'
attachments.each {|v| attachments.delete(v) if v.id == d.prop_key.to_i}
remove_instance_variable(:@rolling_back)
end
end
end
journal.destroy if save(false)
end
end
# Return true if the issue is closed, otherwise false
def closed?
self.status.is_closed?
......
# Callback on attachment deletion
def attachment_removed(obj)
journal = init_journal(User.current)
journal.details << JournalDetail.new(:property => 'attachment',
:prop_key => obj.id,
:old_value => obj.filename)
journal.save
if !@rolling_back
journal = init_journal(User.current)
journal.details << JournalDetail.new(:property => 'attachment',
:prop_key => obj.id,
:old_value => obj.filename)
journal.save
end
end
# Default assignment based on category
......
init_journal @current_journal.user, @current_journal.notes
end
end
# Query generator for selecting groups of issue counts for a project
# based on specific criteria
#
redmine-1.1.0-rollback/app/views/issues/_history.rhtml 2011-02-11 10:54:47.943569600 -0700
<% for journal in journals %>
<div id="change-<%= journal.id %>" class="<%= journal.css_classes %>">
<h4><div class="journal-link"><%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %></div>
<% if journal == journals.last && authorize_for('issues', 'rollback') %>
<div class="journal-rollback"><%= link_to_if_authorized(image_tag('cancel.png'), {:controller => 'issues', :action => 'rollback', :id => @issue}, :confirm => l(:text_are_you_sure), :method => :post, :title => l(:label_rollback)) %>&nbsp;</div>
<% end %>
<%= avatar(journal.user, :size => "24") %>
<%= content_tag('a', '', :name => "note-#{journal.indice}")%>
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %></h4>
redmine-1.1.0-rollback/config/locales/en.yml 2011-02-11 10:57:04.132812800 -0700
permission_add_issue_notes: Add notes
permission_edit_issue_notes: Edit notes
permission_edit_own_issue_notes: Edit own notes
permission_rollback_issues: Rollback issues
permission_move_issues: Move issues
permission_delete_issues: Delete issues
permission_manage_public_queries: Manage public queries
......
label_project_copy_notifications: Send email notifications during the project copy
label_principal_search: "Search for user or group:"
label_user_search: "Search for user:"
label_rollback: Rollback
button_login: Login
button_submit: Submit
redmine-1.1.0-rollback/lib/redmine.rb 2011-02-11 10:56:01.350759200 -0700
map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
map.permission :rollback_issues, {:issues => [:rollback]}
map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
map.permission :delete_issues, {:issues => :destroy}, :require => :member
# Queries
redmine-1.1.0-rollback/public/stylesheets/application.css 2011-02-11 10:54:47.990445200 -0700
float: right;
}
.journal-rollback {
float: right;
}
h2 img { vertical-align:middle; }
.hascontextmenu { cursor: context-menu; }
(1-1/15)