mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Setup basic Revision History page
Sets up paper_trail tracking in important models and add conference_id to versions for storing conference_id of conference related objects as metadata.This will help in querying for versions related to conferences. Fix issues with factories & event types initialization.Import paper_trail testing helpers Fix bug: Creating an event creates a useless version with event update Add revert and view changes features to revision history
This commit is contained in:
parent
60877e9593
commit
a45e537bac
49 changed files with 760 additions and 26 deletions
58
app/controllers/admin/versions_controller.rb
Normal file
58
app/controllers/admin/versions_controller.rb
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
module Admin
|
||||
class VersionsController < Admin::BaseController
|
||||
skip_authorization_check
|
||||
|
||||
def index
|
||||
authorize! :index, PaperTrail::Version.new(item_type: 'User')
|
||||
conf_ids_for_organizer = current_user.is_admin? ? Conference.pluck(:id) : Conference.with_role(:organizer, current_user).pluck(:id)
|
||||
@versions = PaperTrail::Version.where(["conference_id IN (?) OR item_type = 'User'", conf_ids_for_organizer])
|
||||
end
|
||||
|
||||
def revert_attribute
|
||||
@version = PaperTrail::Version.find(params[:id])
|
||||
authorize! :revert_attribute, @version
|
||||
|
||||
if params[:attribute] && @version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.keys.include?(params[:attribute])
|
||||
if @version.item[params[:attribute]] == @version.changeset[params[:attribute]][0]
|
||||
flash[:error] = 'The item is already in the state that you are trying to revert it back to'
|
||||
|
||||
else
|
||||
@version.item[params[:attribute]] = @version.changeset[params[:attribute]][0]
|
||||
if @version.item.save
|
||||
flash[:notice] = 'The selected change was successfully reverted'
|
||||
else
|
||||
flash[:error] = "An error prohibited this change from being reverted: #{@version.item.errors.full_messages.join('. ')}."
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
flash[:error] = 'Revert failed. Attribute missing or invalid'
|
||||
end
|
||||
|
||||
redirect_to admin_revision_history_path
|
||||
end
|
||||
|
||||
def revert_object
|
||||
@version = PaperTrail::Version.find(params[:id])
|
||||
authorize! :revert_object, @version
|
||||
|
||||
if @version.event != 'create'
|
||||
if @version.reify.save
|
||||
flash[:notice] = 'The selected change was successfully reverted'
|
||||
else
|
||||
flash[:error] = "An error prohibited this change from being reverted: #{@version.reify.errors.full_messages.join('. ')}."
|
||||
end
|
||||
|
||||
elsif @version.event == 'create' && @version.item
|
||||
# if @version represets a create event and is not currently deleted
|
||||
@version.item.destroy
|
||||
flash[:notice] = 'The selected change was successfully reverted'
|
||||
|
||||
else
|
||||
flash[:error] = 'The item is already in the state that you are trying to revert it back to'
|
||||
end
|
||||
|
||||
redirect_to admin_revision_history_path
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue