From 5a6365c46e1f72c43645fc52d33d2331b0f44de0 Mon Sep 17 00:00:00 2001 From: Oren Kanner Date: Tue, 26 Jun 2018 23:56:39 -0400 Subject: [PATCH] Fix broken calendar feed with archived reservations Resolves #1729 --- CHANGELOG.md | 1 + app/controllers/categories_controller.rb | 8 ++++---- app/controllers/equipment_items_controller.rb | 13 +++++++------ app/controllers/equipment_models_controller.rb | 3 ++- app/controllers/users_controller.rb | 3 ++- 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56baf2de0..9ed4bc55b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Fixed broken hourly / monthly task buttons ([#1723](https://github.com/YaleSTC/reservations/issues/1723)). * Fixed reservation checkin / checkout with procedures ([#1726](https://github.com/YaleSTC/reservations/issues/1726)). * Fixed broken procedure creation ([#1727](https://github.com/YaleSTC/reservations/issues/1727)). +* Fixed broken calendar feed with archived reservations ([#1729](https://github.com/YaleSTC/reservations/issues/1729)). ### Added * Added link to the accessibility at Yale site in the footer ([#1725](https://github.com/YaleSTC/reservations/issues/1725)). diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 02b7be732..63f31a432 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -1,9 +1,10 @@ # frozen_string_literal: true + class CategoriesController < ApplicationController load_and_authorize_resource decorates_assigned :category before_action :set_current_category, - only: [:show, :edit, :update, :destroy, :deactivate] + only: %i[show edit update destroy deactivate] include ActivationHelper include CsvExport @@ -53,8 +54,7 @@ def create end end - def edit - end + def edit; end def update if @category.update_attributes(category_params) @@ -95,7 +95,7 @@ def category_params def generate_calendar_reservations # we need uniq because it otherwise includes overdue reservations in the # date range twice - (Reservation.for_cat(@category.id).finalized + (Reservation.for_cat(@category.id).finalized.where.not(status: 'archived') .includes(:equipment_item, :equipment_model) .overlaps_with_date_range(@start_date, @end_date) + \ Reservation.for_cat(@category.id) diff --git a/app/controllers/equipment_items_controller.rb b/app/controllers/equipment_items_controller.rb index 7c28c24b5..7adee08f9 100644 --- a/app/controllers/equipment_items_controller.rb +++ b/app/controllers/equipment_items_controller.rb @@ -1,12 +1,13 @@ # frozen_string_literal: true + # rubocop:disable Metrics/ClassLength class EquipmentItemsController < ApplicationController load_and_authorize_resource decorates_assigned :equipment_item before_action :set_current_equipment_item, - only: [:show, :edit, :update, :destroy, :deactivate, - :activate] - before_action :set_equipment_model_if_possible, only: [:index, :new] + only: %i[show edit update destroy deactivate + activate] + before_action :set_equipment_model_if_possible, only: %i[index new] include ActivationHelper include CsvExport @@ -59,8 +60,7 @@ def create end end - def edit - end + def edit; end def update p = equipment_item_params @@ -122,7 +122,8 @@ def generate_calendar_reservations # we need uniq because it otherwise includes overdue reservations in the # date range twice (@equipment_item.reservations.includes(:equipment_item) - .overlaps_with_date_range(@start_date, @end_date).finalized + \ + .overlaps_with_date_range(@start_date, @end_date).finalized + .where.not(status: 'archived') + \ @equipment_item.reservations.includes(:equipment_item).overdue).uniq end diff --git a/app/controllers/equipment_models_controller.rb b/app/controllers/equipment_models_controller.rb index 4f415e95a..783175a34 100644 --- a/app/controllers/equipment_models_controller.rb +++ b/app/controllers/equipment_models_controller.rb @@ -188,7 +188,8 @@ def generate_calendar_reservations # we need uniq because it otherwise includes overdue reservations in the # date range twice (Reservation.for_eq_model(@equipment_model.id).includes(:equipment_item) - .overlaps_with_date_range(@start_date, @end_date).finalized + \ + .overlaps_with_date_range(@start_date, @end_date).finalized + .where.not(status: 'archived') + \ Reservation.for_eq_model(@equipment_model.id).includes(:equipment_item) .overdue).uniq end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 8df3636b2..a91337a76 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -268,7 +268,8 @@ def generate_calendar_reservations # we need uniq because it otherwise includes overdue reservations in the # date range twice (@user.reservations.includes(:equipment_item) - .overlaps_with_date_range(@start_date, @end_date).finalized + \ + .overlaps_with_date_range(@start_date, @end_date).finalized + .where.not(status: 'archived') + \ @user.reservations.includes(:equipment_item).overdue).uniq end