Patch #7610 » rollback-1.1.0.patch
| redmine-1.1.0-rollback/app/controllers/issues_controller.rb 2011-02-11 10:54:47.912319200 -0700 | ||
|---|---|---|
| 19 | 19 |
menu_item :new_issue, :only => [:new, :create] |
| 20 | 20 |
default_search_scope :issues |
| 21 | 21 |
|
| 22 |
before_filter :find_issue, :only => [:show, :edit, :update] |
|
| 22 |
before_filter :find_issue, :only => [:show, :edit, :update, :rollback]
|
|
| 23 | 23 |
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :move, :perform_move, :destroy] |
| 24 | 24 |
before_filter :check_project_uniqueness, :only => [:move, :perform_move] |
| 25 | 25 |
before_filter :find_project, :only => [:new, :create] |
| ... | ... | |
| 27 | 27 |
before_filter :find_optional_project, :only => [:index] |
| 28 | 28 |
before_filter :check_for_default_issue_status, :only => [:new, :create] |
| 29 | 29 |
before_filter :build_new_issue_from_params, :only => [:new, :create] |
| 30 |
accept_key_auth :index, :show, :create, :update, :destroy |
|
| 30 |
accept_key_auth :index, :show, :create, :update, :destroy, :rollback
|
|
| 31 | 31 |
|
| 32 | 32 |
rescue_from Query::StatementInvalid, :with => :query_statement_invalid |
| 33 | 33 |
|
| ... | ... | |
| 56 | 56 |
verify :method => [:post, :delete], |
| 57 | 57 |
:only => :destroy, |
| 58 | 58 |
:render => { :nothing => true, :status => :method_not_allowed }
|
| 59 |
|
|
| 59 |
|
|
| 60 | 60 |
verify :method => :post, :only => :create, :render => {:nothing => true, :status => :method_not_allowed }
|
| 61 | 61 |
verify :method => :post, :only => :bulk_update, :render => {:nothing => true, :status => :method_not_allowed }
|
| 62 | 62 |
verify :method => :put, :only => :update, :render => {:nothing => true, :status => :method_not_allowed }
|
| 63 |
verify :method => :post, :only => :rollback, :render => { :nothing => true, :status => :method_not_allowed }
|
|
| 63 | 64 |
|
| 64 | 65 |
def index |
| 65 | 66 |
retrieve_query |
| ... | ... | |
| 214 | 215 |
redirect_back_or_default({:controller => 'issues', :action => 'index', :project_id => @project})
|
| 215 | 216 |
end |
| 216 | 217 |
|
| 218 |
def rollback |
|
| 219 |
if @issue.rollback |
|
| 220 |
flash[:notice] = l(:notice_successful_update) |
|
| 221 |
else |
|
| 222 |
# can't seem to bring in the helper method 'error_messages_for' |
|
| 223 |
# and injecting it into show.rhtml doesn't seem to work, since |
|
| 224 |
# the @issue loses the errors on redirect (due to issue reload) |
|
| 225 |
flash[:error] = "<ul>" + @issue.errors.full_messages.map {|msg| "<li>" + ERB::Util.html_escape(msg) + "</li>"}.join + "</ul>"
|
|
| 226 |
end |
|
| 227 |
respond_to do |format| |
|
| 228 |
format.html { redirect_back_or_default({:action => 'show', :id => @issue}) }
|
|
| 229 |
format.api { render_validation_errors(@issue) }
|
|
| 230 |
end |
|
| 231 |
end |
|
| 232 |
|
|
| 217 | 233 |
def destroy |
| 218 | 234 |
@hours = TimeEntry.sum(:hours, :conditions => ['issue_id IN (?)', @issues]).to_f |
| 219 | 235 |
if @hours > 0 |
| redmine-1.1.0-rollback/app/models/issue.rb 2011-02-11 10:54:47.927944400 -0700 | ||
|---|---|---|
| 358 | 358 |
@current_journal |
| 359 | 359 |
end |
| 360 | 360 |
|
| 361 |
# rolls back the last journal entry |
|
| 362 |
def rollback |
|
| 363 |
journal = journals.find(:last, :include => [:details], :order => "#{Journal.table_name}.created_on ASC")
|
|
| 364 |
transaction do |
|
| 365 |
old_parent = nil |
|
| 366 |
journal.details.each do |d| |
|
| 367 |
if d.property == 'attr' |
|
| 368 |
if d.prop_key == 'parent_id' |
|
| 369 |
@parent_issue = Issue.find_by_id(d.old_value) |
|
| 370 |
else |
|
| 371 |
send("#{d.prop_key}=", d.old_value)
|
|
| 372 |
end |
|
| 373 |
elsif d.property == 'cf' |
|
| 374 |
custom_field_values.each {|v| v.value = d.old_value if v.custom_field_id == d.prop_key.to_i}
|
|
| 375 |
elsif d.property == 'attachment' |
|
| 376 |
if d.old_value == nil |
|
| 377 |
@rolling_back = true # avoid journal entries created in 'attachment_removed' |
|
| 378 |
attachments.each {|v| attachments.delete(v) if v.id == d.prop_key.to_i}
|
|
| 379 |
remove_instance_variable(:@rolling_back) |
|
| 380 |
end |
|
| 381 |
end |
|
| 382 |
end |
|
| 383 |
journal.destroy if save(false) |
|
| 384 |
end |
|
| 385 |
end |
|
| 386 |
|
|
| 361 | 387 |
# Return true if the issue is closed, otherwise false |
| 362 | 388 |
def closed? |
| 363 | 389 |
self.status.is_closed? |
| ... | ... | |
| 785 | 811 |
|
| 786 | 812 |
# Callback on attachment deletion |
| 787 | 813 |
def attachment_removed(obj) |
| 788 |
journal = init_journal(User.current) |
|
| 789 |
journal.details << JournalDetail.new(:property => 'attachment', |
|
| 790 |
:prop_key => obj.id, |
|
| 791 |
:old_value => obj.filename) |
|
| 792 |
journal.save |
|
| 814 |
if !@rolling_back |
|
| 815 |
journal = init_journal(User.current) |
|
| 816 |
journal.details << JournalDetail.new(:property => 'attachment', |
|
| 817 |
:prop_key => obj.id, |
|
| 818 |
:old_value => obj.filename) |
|
| 819 |
journal.save |
|
| 820 |
end |
|
| 793 | 821 |
end |
| 794 | 822 |
|
| 795 | 823 |
# Default assignment based on category |
| ... | ... | |
| 850 | 878 |
init_journal @current_journal.user, @current_journal.notes |
| 851 | 879 |
end |
| 852 | 880 |
end |
| 853 |
|
|
| 881 |
|
|
| 854 | 882 |
# Query generator for selecting groups of issue counts for a project |
| 855 | 883 |
# based on specific criteria |
| 856 | 884 |
# |
| redmine-1.1.0-rollback/app/views/issues/_history.rhtml 2011-02-11 10:54:47.943569600 -0700 | ||
|---|---|---|
| 2 | 2 |
<% for journal in journals %> |
| 3 | 3 |
<div id="change-<%= journal.id %>" class="<%= journal.css_classes %>"> |
| 4 | 4 |
<h4><div class="journal-link"><%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %></div>
|
| 5 |
<% if journal == journals.last && authorize_for('issues', 'rollback') %>
|
|
| 6 |
<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)) %> </div>
|
|
| 7 |
<% end %> |
|
| 5 | 8 |
<%= avatar(journal.user, :size => "24") %> |
| 6 | 9 |
<%= content_tag('a', '', :name => "note-#{journal.indice}")%>
|
| 7 | 10 |
<%= 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 | ||
|---|---|---|
| 378 | 378 |
permission_add_issue_notes: Add notes |
| 379 | 379 |
permission_edit_issue_notes: Edit notes |
| 380 | 380 |
permission_edit_own_issue_notes: Edit own notes |
| 381 |
permission_rollback_issues: Rollback issues |
|
| 381 | 382 |
permission_move_issues: Move issues |
| 382 | 383 |
permission_delete_issues: Delete issues |
| 383 | 384 |
permission_manage_public_queries: Manage public queries |
| ... | ... | |
| 793 | 794 |
label_project_copy_notifications: Send email notifications during the project copy |
| 794 | 795 |
label_principal_search: "Search for user or group:" |
| 795 | 796 |
label_user_search: "Search for user:" |
| 797 |
label_rollback: Rollback |
|
| 796 | 798 |
|
| 797 | 799 |
button_login: Login |
| 798 | 800 |
button_submit: Submit |
| redmine-1.1.0-rollback/lib/redmine.rb 2011-02-11 10:56:01.350759200 -0700 | ||
|---|---|---|
| 72 | 72 |
map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new]}
|
| 73 | 73 |
map.permission :edit_issue_notes, {:journals => :edit}, :require => :loggedin
|
| 74 | 74 |
map.permission :edit_own_issue_notes, {:journals => :edit}, :require => :loggedin
|
| 75 |
map.permission :rollback_issues, {:issues => [:rollback]}
|
|
| 75 | 76 |
map.permission :move_issues, {:issue_moves => [:new, :create]}, :require => :loggedin
|
| 76 | 77 |
map.permission :delete_issues, {:issues => :destroy}, :require => :member
|
| 77 | 78 |
# Queries |
| redmine-1.1.0-rollback/public/stylesheets/application.css 2011-02-11 10:54:47.990445200 -0700 | ||
|---|---|---|
| 938 | 938 |
float: right; |
| 939 | 939 |
} |
| 940 | 940 |
|
| 941 |
.journal-rollback {
|
|
| 942 |
float: right; |
|
| 943 |
} |
|
| 944 |
|
|
| 941 | 945 |
h2 img { vertical-align:middle; }
|
| 942 | 946 |
|
| 943 | 947 |
.hascontextmenu { cursor: context-menu; }
|