diff --git a/app/controllers/admin/versions_controller.rb b/app/controllers/admin/versions_controller.rb index 4f7b6c0e..47b4a026 100644 --- a/app/controllers/admin/versions_controller.rb +++ b/app/controllers/admin/versions_controller.rb @@ -4,7 +4,7 @@ module Admin load_and_authorize_resource class: PaperTrail::Version def index - @conf_ids_with_role = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role([:organizer, :cfp, :info_desk], current_user).pluck(:short_title) + @conferences_with_role = current_user.is_admin? ? Conference.pluck(:short_title) : Conference.with_role([:organizer, :cfp, :info_desk], current_user).pluck(:short_title) return if @conference.blank? @versions = PaperTrail::Version.where(conference_id: @conference.id).accessible_by(current_ability) diff --git a/app/helpers/paths_helper.rb b/app/helpers/paths_helper.rb index 97de8bca..df01ab2f 100644 --- a/app/helpers/paths_helper.rb +++ b/app/helpers/paths_helper.rb @@ -2,14 +2,6 @@ module PathsHelper ## # Includes functions related to links or redirects ## - def link_to_user(user_id) - user = User.find_by(id: user_id) - if user - link_to user.name, admin_user_path(id: user_id) - else - 'Someone (probably via the console)' - end - end def active_nav_li(link) if current_page?(link) diff --git a/app/helpers/versions_helper.rb b/app/helpers/versions_helper.rb index d88b6353..de571ffa 100644 --- a/app/helpers/versions_helper.rb +++ b/app/helpers/versions_helper.rb @@ -31,7 +31,7 @@ module VersionsHelper end end - # Recieves a model_name and id + # Receives a model_name and id # Returns nil if model_name is invalid # Returns object in its current state if its alive # Otherwise Returns object state just before deletion diff --git a/app/models/conference.rb b/app/models/conference.rb index 68cdc186..beb2b0bb 100644 --- a/app/models/conference.rb +++ b/app/models/conference.rb @@ -746,6 +746,10 @@ class Conference < ActiveRecord::Base self end + def to_param + short_title + end + private # Returns a different html colour for every i and consecutive colors are diff --git a/app/views/admin/versions/_object_desc_and_link.html.haml b/app/views/admin/versions/_object_desc_and_link.html.haml index 2953bf54..19a2e1cf 100644 --- a/app/views/admin/versions/_object_desc_and_link.html.haml +++ b/app/views/admin/versions/_object_desc_and_link.html.haml @@ -1,17 +1,19 @@ - conference = Conference.find_by(id: version.conference_id) -- conference_short_title = conference.try(:short_title) || current_or_last_object_state(version.item_type, version.item_id).try(:conference).try(:short_title) || '' +- conference_short_title = conference.try(:short_title) || current_or_last_object_state('Conference', version.conference_id).try(:short_title) || ' ' - case version.item_type - when 'UsersRole' - users_role = current_or_last_object_state(version.item_type, version.item_id) - = 'role' - = link_to users_role.role.name, admin_conference_role_path(conference.short_title, users_role.role.name) + - role = Role.find_by(id: users_role.role_id) if users_role + role + = link_if_alive version, role.try(:name), admin_conference_role_path(role.try(:name) || ' ', conference_short_title), conference + = version.event == 'create' ? 'to' : 'from' - = 'user' + user = link_to_user(users_role.user_id) - when 'Subscription', 'Registration' - = 'conference' + conference = link_to_conference(version.conference_id) - when 'Commercial' @@ -20,178 +22,178 @@ - case commercial.commercialable_type - when 'Event' - = 'commercial in event' + commercial in event - if commercialable && conference = link_to commercialable.title, - admin_conference_program_event_path(conference_id: conference.short_title, - id: commercialable.id) + admin_conference_program_event_path(conference, commercialable.id) - else = commercialable.title = "with ID #{commercialable.id}" - when 'Venue' - = 'commercial in venue' + commercial in venue - if commercialable && conference = link_to commercialable.name, - edit_admin_conference_venue_path(conference_id: conference_short_title, - id: commercialable.id, anchor: 'commercials-content') + edit_admin_conference_venue_path(conference_short_title, + commercialable.id, anchor: 'commercials-content') - else = commercialable.name = "with ID #{commercialable.id}" - when 'Conference' - = 'commercial in conference' + commercial in conference - if commercialable = link_to commercialable.short_title, - admin_conference_commercials_path(conference_id: commercialable.short_title) + admin_conference_commercials_path(commercialable.short_title) - else = commercialable.short_title = "with ID #{commercialable.id}" - when 'EventsRegistration', 'Comment', 'Vote', 'Event' - = 'event' + event - object = current_or_last_object_state(version.item_type, version.item_id) - event_id = object.try(:event_id) || object.try(:commentable_id) || object.id = link_to (current_or_last_object_state('Event', event_id).try(:title) || 'deleted event'), - admin_conference_program_event_path(conference_id: conference_short_title, id: event_id) + admin_conference_program_event_path(conference_short_title, event_id) - when 'Target' - = 'target' + target - target = current_or_last_object_state(version.item_type, version.item_id) - = link_if_alive version, target.to_s, admin_conference_targets_path(conference_id: conference_short_title), conference + = link_if_alive version, target.to_s, admin_conference_targets_path(conference_short_title), conference - when 'EventSchedule' - event_schedule = current_or_last_object_state(version.item_type, version.item_id) event = link_to (current_or_last_object_state('Event', event_schedule.event_id).try(:title) || 'deleted'), - admin_conference_program_event_path(conference_id: conference_short_title, id: event_schedule.event_id) + admin_conference_program_event_path(conference_short_title, event_schedule.event_id) in = link_to "Schedule #{event_schedule.schedule_id}", - admin_conference_schedule_path(conference_id: conference_short_title, id: event_schedule.schedule_id) + admin_conference_schedule_path(conference_short_title, event_schedule.schedule_id) - when 'Schedule' = link_if_alive version, "Schedule #{version.item_id}", - admin_conference_schedule_path(conference_id: conference_short_title, id: version.item_id), + admin_conference_schedule_path(conference_short_title, version.item_id), conference - when 'Conference' - = 'conference' + conference = link_to_conference(version.item_id) - when 'RegistrationPeriod' = link_if_alive version, 'registration period', - admin_conference_registration_period_path(conference_id: conference_short_title), + admin_conference_registration_period_path(conference_short_title), conference - when 'Contact' = link_if_alive version, 'contact details', - edit_admin_conference_contact_path(conference_id: conference_short_title), + edit_admin_conference_contact_path(conference_short_title), conference - when 'Program' = link_if_alive version, 'program', - admin_conference_program_path(conference_id: conference_short_title), + admin_conference_program_path(conference_short_title), conference - when 'Cfp' - = 'cfp for' + cfp for - cfp = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, cfp.cfp_type, - admin_conference_program_cfp_path(conference_id: conference_short_title, id: version.item_id), + admin_conference_program_cfp_path(conference_short_title, version.item_id), conference - when 'Track' - = 'track' + track - track = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, track.name, - admin_conference_program_track_path(conference_id: conference_short_title, id: track.try(:short_name)), + admin_conference_program_track_path(conference_short_title, track.try(:short_name)), conference - when 'EventType' - = 'event type' + event type - event_type = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, event_type.title, - admin_conference_program_event_types_path(conference_id: conference_short_title), + admin_conference_program_event_types_path(conference_short_title), conference - when 'Role' - = 'role' + role - role = current_or_last_object_state(version.item_type, version.item_id) - = link_if_alive version, role.name, - admin_conference_role_path(conference_id: conference_short_title, id: role.name), + - role_name = role.try(:name) || PaperTrail::Version.where(item_type: 'Role', item_id: version.item_id).last.changeset[:name].second + = link_if_alive version, role_name, + admin_conference_role_path(conference_short_title, role_name), conference - when 'Venue' - = 'venue' + venue - venue = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, venue.name, - admin_conference_venue_path(conference_id: conference_short_title), + admin_conference_venue_path(conference_short_title), conference - when 'Lodging' - = 'lodging' + lodging - lodging = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, lodging.name, - admin_conference_lodgings_path(conference_id: conference_short_title), + admin_conference_lodgings_path(conference_short_title), conference - when 'Room' - = 'room' + room - room = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, room.name, - admin_conference_venue_rooms_path(conference_id: conference_short_title), + admin_conference_venue_rooms_path(conference_short_title), conference - when 'Sponsor' - = 'sponsor' + sponsor - sponsor = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, sponsor.name, - admin_conference_sponsors_path(conference_id: conference_short_title), + admin_conference_sponsors_path(conference_short_title), conference - when 'SponsorshipLevel' - = 'sponsorship level' + sponsorship level - sponsorship_level = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, sponsorship_level.title, - admin_conference_sponsorship_levels_path(conference_id: conference_short_title), + admin_conference_sponsorship_levels_path(conference_short_title), conference - when 'Ticket' - = 'ticket' + ticket - ticket = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, ticket.title, - admin_conference_ticket_path(conference_id: conference_short_title, id: version.item_id), + admin_conference_ticket_path(conference_short_title, version.item_id), conference - when 'Campaign' - = 'campaign' + campaign - campaign = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, campaign.name, - admin_conference_campaigns_path(conference_id: conference_short_title), + admin_conference_campaigns_path(conference_short_title), conference - when 'DifficultyLevel' - = 'difficulty level' + difficulty level - difficulty_level = current_or_last_object_state(version.item_type, version.item_id) = link_if_alive version, difficulty_level.title, - admin_conference_program_difficulty_level_path(conference_id: conference_short_title, id: version.item_id), + admin_conference_program_difficulty_level_path(conference_short_title, version.item_id), conference - when 'Splashpage' = link_if_alive version, 'splashpage', - admin_conference_splashpage_path(conference_id: conference_short_title), + admin_conference_splashpage_path(conference_short_title), conference - when 'EmailSettings' = link_if_alive version, 'email settings', - admin_conference_emails_path(conference_id: conference_short_title), + admin_conference_emails_path(conference_short_title), conference - when 'User' - if version.event == 'update' - = 'user' + user = link_to_user(version.item_id) - unless %w(Conference Subscription Registration User).include?(version.item_type) - = 'in conference' + in conference = link_to_conference(version.conference_id) diff --git a/app/views/admin/versions/index.html.haml b/app/views/admin/versions/index.html.haml index 3a5113b1..963e0a57 100644 --- a/app/views/admin/versions/index.html.haml +++ b/app/views/admin/versions/index.html.haml @@ -8,7 +8,7 @@ %span.caret %ul.dropdown-menu %li= link_to 'All Conferences & Users', admin_revision_history_path - - @conf_ids_with_role.each do |conference_short_title| + - @conferences_with_role.each do |conference_short_title| %li= link_to conference_short_title, admin_conference_revision_history_path(conference_id: conference_short_title) %h1 Revision History