From c80f37f3ff09bf97856e8e6c89e5641763f66285 Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Tue, 9 Aug 2016 12:22:43 +0530 Subject: [PATCH 1/5] Change look of event history page similar to changelog --- app/controllers/admin/versions_controller.rb | 4 +- app/views/admin/events/show.html.haml | 45 +++++++++---------- .../admin/versions/_changelog_actions.haml | 15 +++++++ app/views/admin/versions/index.html.haml | 16 +------ 4 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 app/views/admin/versions/_changelog_actions.haml diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb index d103e874..07108d38 100644 --- a/app/controllers/admin/versions_controller.rb +++ b/app/controllers/admin/versions_controller.rb @@ -29,7 +29,7 @@ module Admin flash[:error] = 'Revert failed. Attribute missing or invalid' end - redirect_to admin_revision_history_path + redirect_back_or_to admin_revision_history_path end def revert_object @@ -52,7 +52,7 @@ module Admin 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 + redirect_back_or_to admin_revision_history_path end end end diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 9372ecbf..4b22eb2c 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -9,29 +9,28 @@ = render 'proposal' #history-content.tab-pane .col-md-12 - %table.table + %table.table.table-striped.table-bordered.table-hover.datatable %thead - %th - %b Who - %th - %b Timestamp - %th - %b Modification Type - %th - %b Changes + %th ID + %th Description + %th Actions %tbody - - @event.versions.each do |version| - %tr - %td - - unless version.whodunnit.nil? - = User.find(version.whodunnit).name - - else - No user (probably via the console) - %td - = version.created_at - %td - = version.event - %td - - version.changeset.each_key do |key| - = "#{key}: #{version.changeset[key][0]} -> #{version.changeset[key][1]}" + - @event.versions.each do |version| + %tr + %td + = version.id + %td + %p + = change_creator_link(version.whodunnit) + = event_change_description(version) + = "event #{@event.title}" + + %small.text-muted + = distance_of_time_in_words(Time.now,version.created_at) + ' ago' + %br + = "(#{version.created_at.strftime('%B %-d, %Y %H:%M')})" + %br + = render partial: 'admin/versions/object_changes', locals: { version: version } + %td + = render partial: 'admin/versions/changelog_actions', locals: { version: version } \ No newline at end of file diff --git a/app/views/admin/versions/_changelog_actions.haml b/app/views/admin/versions/_changelog_actions.haml new file mode 100644 index 00000000..07480650 --- /dev/null +++ b/app/views/admin/versions/_changelog_actions.haml @@ -0,0 +1,15 @@ +.btn-group{role: 'group'} + %a.btn.btn-success.btn-sm.show-changeset{id: version.id} View Changes + - if can? :revert_object, version + %button.btn.btn-default.dropdown-toggle.btn-sm.btn-primary{'data-toggle' => 'dropdown', type: 'button'} + Revert + %span.caret + %ul.dropdown-menu + %li= link_to 'All Changes', admin_revision_history_revert_object_path(id: version.id), data: { confirm: 'Are you sure you want to revert this change?' } + + - if can? :revert_attribute, version + %li.divider{role: 'separator'} + - version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.each do |attribute, values| + %li= link_to attribute, admin_revision_history_revert_attribute_path(id: version.id, attribute: attribute), data: { confirm: "Are you sure you want to revert #{attribute}?" } + - else + %button.btn.btn-sm.btn-primary.disabled Revert \ No newline at end of file diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index af604820..c5a90b58 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -60,18 +60,4 @@ = render partial: 'object_changes', locals: { version: version } %td.col-md-2 - .btn-group{role: 'group'} - %a.btn.btn-success.btn-sm.show-changeset{id: version.id} View Changes - - if can? :revert_object, version - %button.btn.btn-default.dropdown-toggle.btn-sm.btn-primary{'data-toggle' => 'dropdown', type: 'button'} - Revert - %span.caret - %ul.dropdown-menu - %li= link_to 'All Changes', admin_revision_history_revert_object_path(id: version.id), data: { confirm: 'Are you sure you want to revert this change?' } - - - if can? :revert_attribute, version - %li.divider{role: 'separator'} - - version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.each do |attribute, values| - %li= link_to attribute, admin_revision_history_revert_attribute_path(id: version.id, attribute: attribute), data: { confirm: "Are you sure you want to revert #{attribute}?" } - - else - %button.btn.btn-sm.btn-primary.disabled Revert + = render partial: 'changelog_actions', locals: { version: version } From 0a3466ca7c34b15e8a99b669814cbe6d7774960e Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Tue, 9 Aug 2016 13:03:06 +0530 Subject: [PATCH 2/5] Move shared version partials to views/shared --- app/views/admin/events/show.html.haml | 4 ++-- app/views/admin/versions/index.html.haml | 4 ++-- app/views/{admin/versions => shared}/_changelog_actions.haml | 2 +- .../{admin/versions => shared}/_object_changes.html.haml | 0 4 files changed, 5 insertions(+), 5 deletions(-) rename app/views/{admin/versions => shared}/_changelog_actions.haml (94%) rename app/views/{admin/versions => shared}/_object_changes.html.haml (100%) diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 4b22eb2c..44232a7d 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -31,6 +31,6 @@ = "(#{version.created_at.strftime('%B %-d, %Y %H:%M')})" %br - = render partial: 'admin/versions/object_changes', locals: { version: version } + = render partial: 'shared/object_changes', locals: { version: version } %td - = render partial: 'admin/versions/changelog_actions', locals: { version: version } \ No newline at end of file + = render partial: 'shared/changelog_actions', locals: { version: version } diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index c5a90b58..fd2022ba 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -57,7 +57,7 @@ = "(#{version.created_at.strftime('%B %-d, %Y %H:%M')})" %br - = render partial: 'object_changes', locals: { version: version } + = render partial: 'shared/object_changes', locals: { version: version } %td.col-md-2 - = render partial: 'changelog_actions', locals: { version: version } + = render partial: 'shared/changelog_actions', locals: { version: version } diff --git a/app/views/admin/versions/_changelog_actions.haml b/app/views/shared/_changelog_actions.haml similarity index 94% rename from app/views/admin/versions/_changelog_actions.haml rename to app/views/shared/_changelog_actions.haml index 07480650..600cb215 100644 --- a/app/views/admin/versions/_changelog_actions.haml +++ b/app/views/shared/_changelog_actions.haml @@ -12,4 +12,4 @@ - version.changeset.reject{ |_, values| values[0].blank? && values[1].blank? }.each do |attribute, values| %li= link_to attribute, admin_revision_history_revert_attribute_path(id: version.id, attribute: attribute), data: { confirm: "Are you sure you want to revert #{attribute}?" } - else - %button.btn.btn-sm.btn-primary.disabled Revert \ No newline at end of file + %button.btn.btn-sm.btn-primary.disabled Revert diff --git a/app/views/admin/versions/_object_changes.html.haml b/app/views/shared/_object_changes.html.haml similarity index 100% rename from app/views/admin/versions/_object_changes.html.haml rename to app/views/shared/_object_changes.html.haml From da1c8fc6919c5a2da6c41bca5f22e30481df1960 Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Wed, 10 Aug 2016 20:42:18 +0530 Subject: [PATCH 3/5] Allow cfp team members to revert changes to events through event#history-content --- app/models/ability.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/models/ability.rb b/app/models/ability.rb index 8891aabf..837f20a3 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -210,6 +210,10 @@ class Ability role.resource_type == 'Conference' && role.name == 'cfp' && (Conference.with_role(:cfp, user).pluck(:id).include? role.resource_id) end + + can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version| + version.item_type == 'Event' && (conf_ids_for_cfp.include? version.conference_id) + end end def signed_in_with_info_desk_role(user) From e2659ae907cf6aa7f52f978266a99e08bec1814e Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Sat, 13 Aug 2016 23:45:46 +0530 Subject: [PATCH 4/5] Show changes to event commercials in event changelog --- app/controllers/admin/events_controller.rb | 1 + app/helpers/application_helper.rb | 10 ++++++++++ app/models/ability.rb | 2 +- app/views/admin/events/show.html.haml | 14 +++++++++++--- app/views/admin/versions/index.html.haml | 7 +------ 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 37633e22..67559f3c 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -86,6 +86,7 @@ module Admin @comment_count = @event.comment_threads.count @ratings = @event.votes.includes(:user) @difficulty_levels = @program.difficulty_levels + @versions = @event.versions | PaperTrail::Version.where(item_type: 'Commercial', item_id: @event.commercials.pluck(:id)) end def edit diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 09f69484..a0466d6a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -491,4 +491,14 @@ module ApplicationHelper end end end + + def general_change_description(version) + if version.event == 'create' + 'created new' + elsif version.event == 'update' + "updated #{updated_attributes(version)} of" + else + 'deleted' + end + end end diff --git a/app/models/ability.rb b/app/models/ability.rb index 837f20a3..96ca5b59 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -212,7 +212,7 @@ class Ability end can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version| - version.item_type == 'Event' && (conf_ids_for_cfp.include? version.conference_id) + %w(Event Commercial).include?(version.item_type) && (conf_ids_for_cfp.include? version.conference_id) end end diff --git a/app/views/admin/events/show.html.haml b/app/views/admin/events/show.html.haml index 44232a7d..02dd85c7 100644 --- a/app/views/admin/events/show.html.haml +++ b/app/views/admin/events/show.html.haml @@ -15,15 +15,23 @@ %th Description %th Actions %tbody - - @event.versions.each do |version| + - @versions.each do |version| %tr %td = version.id %td %p = change_creator_link(version.whodunnit) - = event_change_description(version) - = "event #{@event.title}" + + - if version.item_type == 'Event' + = event_change_description(version) + = "event #{@event.title}" + + - else + = general_change_description(version) + = link_to 'commercial', + edit_admin_conference_program_event_path(conference_id: @conference.short_title, + id: @event.id, anchor: 'commercials-content') %small.text-muted = distance_of_time_in_words(Time.now,version.created_at) + ' ago' diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index fd2022ba..2929b497 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -42,12 +42,7 @@ = user_change_description(version) - else - - if version.event == 'create' - = 'created new' - - elsif version.event == 'update' - = "updated #{updated_attributes(version)} of" - - else - = 'deleted' + = general_change_description(version) = render partial: 'object_desc_and_link', locals: { version: version } From a02060b665de5728727080b684626e7d6c9e8add Mon Sep 17 00:00:00 2001 From: Nishanth Vijayan Date: Tue, 16 Aug 2016 18:56:54 +0530 Subject: [PATCH 5/5] cfp team users should have access to event commercials only --- app/controllers/admin/events_controller.rb | 4 +++- app/models/ability.rb | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/events_controller.rb b/app/controllers/admin/events_controller.rb index 67559f3c..1e0d1447 100644 --- a/app/controllers/admin/events_controller.rb +++ b/app/controllers/admin/events_controller.rb @@ -86,7 +86,9 @@ module Admin @comment_count = @event.comment_threads.count @ratings = @event.votes.includes(:user) @difficulty_levels = @program.difficulty_levels - @versions = @event.versions | PaperTrail::Version.where(item_type: 'Commercial', item_id: @event.commercials.pluck(:id)) + @versions = @event.versions | + PaperTrail::Version.where(item_type: 'Commercial').where_object(commercialable_id: @event.id, commercialable_type: 'Event') | + PaperTrail::Version.where(item_type: 'Commercial').where_object_changes(commercialable_id: @event.id, commercialable_type: 'Event') end def edit diff --git a/app/models/ability.rb b/app/models/ability.rb index 96ca5b59..c2cbfa8e 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -211,8 +211,10 @@ class Ability (Conference.with_role(:cfp, user).pluck(:id).include? role.resource_id) end + can [:index, :revert_object, :revert_attribute], PaperTrail::Version, item_type: 'Event', conference_id: conf_ids_for_cfp can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version| - %w(Event Commercial).include?(version.item_type) && (conf_ids_for_cfp.include? version.conference_id) + version.item_type == 'Commercial' && conf_ids_for_cfp.include?(version.conference_id) && + (version.object.to_s.include?('Event') || version.object_changes.to_s.include?('Event')) end end