Patch #7610 » 0001-Rollback-functionality.patch
| app/controllers/journals_controller.rb | ||
|---|---|---|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
class JournalsController < ApplicationController
|
||
|
before_action :find_journal, :only => [:edit, :update, :diff]
|
||
|
before_action :find_journal, :only => [:edit, :update, :diff, :rollback]
|
||
|
before_action :find_issue, :only => [:new]
|
||
|
before_action :find_optional_project, :only => [:index]
|
||
|
before_action :authorize, :only => [:new, :edit, :update, :diff]
|
||
|
before_action :authorize, :only => [:new, :edit, :update, :diff, :rollback]
|
||
|
accept_rss_auth :index
|
||
|
menu_item :issues
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
def rollback
|
||
|
Rails.logger.warn("FWH: #{@journal}")
|
||
|
(render_403; return false) unless @journal.can_rollback?(User.current)
|
||
|
@journal.rollback
|
||
|
respond_to do |format|
|
||
|
format.js
|
||
|
end
|
||
|
end
|
||
|
private
|
||
|
def find_journal
|
||
| app/helpers/journals_helper.rb | ||
|---|---|---|
|
# Returns the action links for an issue journal
|
||
|
def render_journal_actions(issue, journal, options={})
|
||
|
links = []
|
||
|
if journal.notes.present?
|
||
|
if journal.last_valid_journal?(issue.journals) & journal.can_rollback?
|
||
|
links << link_to(l(:button_cancel),
|
||
|
rollback_journal_path(journal),
|
||
|
:remote => true,
|
||
|
:method => 'post', :data => {:confirm => l(:text_are_you_sure)},
|
||
|
:title => l(:button_rollback),
|
||
|
:class => 'icon-only icon-cancel'
|
||
|
)
|
||
|
end
|
||
|
if journal.notes.present? & !journal.rolled_back?
|
||
|
if options[:reply_links]
|
||
|
links << link_to(l(:button_quote),
|
||
|
quoted_issue_path(issue, :journal_id => journal),
|
||
| ... | ... | |
|
links << link_to(l(:button_delete),
|
||
|
journal_path(journal, :journal => {:notes => ""}),
|
||
|
:remote => true,
|
||
|
:method => 'put', :data => {:confirm => l(:text_are_you_sure)},
|
||
|
:method => 'put', :data => {:confirm => l(:text_are_you_sure)},
|
||
|
:title => l(:button_delete),
|
||
|
:class => 'icon-only icon-del'
|
||
|
)
|
||
| app/models/issue.rb | ||
|---|---|---|
|
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?
|
||
|
status.present? && status.is_closed?
|
||
| app/models/journal.rb | ||
|---|---|---|
|
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?(user = 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
|
||
| app/models/user_preference.rb | ||
|---|---|---|
|
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
|
||
| app/views/issues/_history.html.erb | ||
|---|---|---|
|
<% for journal in journals %>
|
||
|
<div id="change-<%= journal.id %>" class="<%= journal.css_classes %>">
|
||
|
<div id="note-<%= journal.indice %>">
|
||
|
<div class="contextual">
|
||
|
<span class="journal-actions"><%= render_journal_actions(issue, journal, :reply_links => reply_links) %></span>
|
||
|
<a href="#note-<%= journal.indice %>" class="journal-link">#<%= journal.indice %></a>
|
||
|
</div>
|
||
|
<h4>
|
||
|
<%= avatar(journal.user, :size => "24") %>
|
||
|
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>
|
||
|
<%= render_private_notes_indicator(journal) %>
|
||
|
</h4>
|
||
|
<% if journal.show? %>
|
||
|
<% if journal.rolled_back? %>
|
||
|
<strike>
|
||
|
<% end %>
|
||
|
<div class="contextual">
|
||
|
<span class="journal-actions"><%= render_journal_actions(issue, journal, :reply_links => reply_links) %></span>
|
||
|
<a href="#note-<%= journal.indice %>" class="journal-link">#<%= journal.indice %></a>
|
||
|
</div>
|
||
|
<h4>
|
||
|
<%= avatar(journal.user, :size => "24") %>
|
||
|
<%= authoring journal.created_on, journal.user, :label => :label_updated_time_by %>
|
||
|
<%= render_private_notes_indicator(journal) %>
|
||
|
</h4>
|
||
|
<% if journal.details.any? %>
|
||
|
<ul class="details">
|
||
|
<% details_to_strings(journal.visible_details).each do |string| %>
|
||
|
<li><%= string %></li>
|
||
|
<% end %>
|
||
|
</ul>
|
||
|
<% if Setting.thumbnails_enabled? && (thumbnail_attachments = journal_thumbnail_attachments(journal)).any? %>
|
||
|
<div class="thumbnails">
|
||
|
<% thumbnail_attachments.each do |attachment| %>
|
||
|
<div><%= thumbnail_tag(attachment) %></div>
|
||
|
<% if journal.details.any? %>
|
||
|
<ul class="details">
|
||
|
<% details_to_strings(journal.visible_details).each do |string| %>
|
||
|
<li><%= string %></li>
|
||
|
<% end %>
|
||
|
</ul>
|
||
|
<% if Setting.thumbnails_enabled? && (thumbnail_attachments = journal_thumbnail_attachments(journal)).any? %>
|
||
|
<div class="thumbnails">
|
||
|
<% thumbnail_attachments.each do |attachment| %>
|
||
|
<div><%= thumbnail_tag(attachment) %></div>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
<%= render_notes(issue, journal, :reply_links => reply_links) unless journal.notes.blank? %>
|
||
|
<%= render_notes(issue, journal, :reply_links => reply_links) unless journal.notes.blank? %>
|
||
|
<% if journal.rolled_back? %>
|
||
|
</strike>
|
||
|
<% end %>
|
||
|
<% end %>
|
||
|
</div>
|
||
|
</div>
|
||
|
<%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %>
|
||
|
<%= call_hook(:view_issues_history_journal_bottom, { :journal => journal }) %>
|
||
|
<% 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) %>
|
||
| app/views/journals/rollback.js.erb | ||
|---|---|---|
|
$('#history').html('<h3><%=l(:label_history)%></h3><%= escape_javascript(render :partial => 'issues/history', :locals => { :issue => @journal.issue, :journals => @journal.issue.journals }) %>');
|
||
| app/views/users/_preferences.html.erb | ||
|---|---|---|
|
<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>
|
||
|
<p><%= pref_fields.select :textarea_font, textarea_font_options %></p>
|
||
|
<% end %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
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
|
||
|
field_default_status: Default status
|
||
|
field_users_visibility: Users visibility
|
||
|
field_time_entries_visibility: Time logs visibility
|
||
| ... | ... | |
|
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
|
||
|
permission_import_issues: Import issues
|
||
|
project_module_issue_tracking: Issue tracking
|
||
| ... | ... | |
|
button_delete_my_account: Delete my account
|
||
|
button_close: Close
|
||
|
button_reopen: Reopen
|
||
|
button_rollback: Rollback
|
||
|
button_import: Import
|
||
|
button_filter: Filter
|
||
|
button_actions: Actions
|
||
| config/locales/pt-BR.yml | ||
|---|---|---|
|
notice_issue_update_conflict: A tarefa foi atualizada por um outro usuário, enquanto você estava editando.
|
||
|
text_issue_conflict_resolution_cancel: Descartar todas as minhas mudanças e reexibir %{link}
|
||
|
permission_manage_related_issues: Gerenciar tarefas relacionadas
|
||
|
permission_rollback_issue_notes: Desfazer mudanças nas tarefas
|
||
|
field_auth_source_ldap_filter: Filtro LDAP
|
||
|
label_search_for_watchers: Procurar por outros observadores para adicionar
|
||
|
notice_account_deleted: Sua conta foi excluída permanentemente.
|
||
| ... | ... | |
|
label_show_closed_projects: Visualizar projetos fechados
|
||
|
button_close: Fechar
|
||
|
button_reopen: Reabrir
|
||
|
button_rollback: Desfazer
|
||
|
project_status_active: ativo
|
||
|
project_status_closed: fechado
|
||
|
project_status_archived: arquivado
|
||
| ... | ... | |
|
label_visibility_roles: para os papéis
|
||
|
label_visibility_public: para qualquer usuário
|
||
|
field_must_change_passwd: É necessário alterar sua senha na próxima vez que tentar acessar sua conta
|
||
|
field_hide_rolled_back_issue_notes: Esconder mudanças desfeitas
|
||
|
notice_new_password_must_be_different: A nova senha deve ser diferente da senha atual
|
||
|
setting_mail_handler_excluded_filenames: Exclui anexos por nome
|
||
|
text_convert_available: Conversor ImageMagick disponível (opcional)
|
||
| config/routes.rb | ||
|---|---|---|
|
resources :journals, :only => [:edit, :update] do
|
||
|
member do
|
||
|
get 'diff'
|
||
|
post 'rollback'
|
||
|
end
|
||
|
end
|
||
| db/migrate/20140417000000_add_journals_rolled_back.rb | ||
|---|---|---|
|
class AddJournalsRolledBack < ActiveRecord::Migration[4.2]
|
||
|
def up
|
||
|
add_column :journals, :rolled_back, :boolean, :default => false
|
||
|
end
|
||
|
def down
|
||
|
remove_column :journals, :rolled_back
|
||
|
end
|
||
|
end
|
||
| lib/redmine.rb | ||
|---|---|---|
|
map.permission :set_issues_private, {}
|
||
|
map.permission :set_own_issues_private, {}, :require => :loggedin
|
||
|
map.permission :add_issue_notes, {:issues => [:edit, :update], :journals => [:new], :attachments => :upload}
|
||
|
map.permission :edit_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
|
||
|
map.permission :edit_own_issue_notes, {:journals => [:edit, :update]}, :require => :loggedin
|
||
|
map.permission :edit_issue_notes, {:journals => [:edit, :update, :rollback]}, :require => :loggedin
|
||
|
map.permission :edit_own_issue_notes, {:journals => [:edit, :update, :rollback]}, :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 :delete_issues, {:issues => :destroy}, :require => :member
|
||