diff --git a/app/assets/javascripts/directives/cart.js.erb b/app/assets/javascripts/directives/cart.js.erb index 70e258be0..cf9bb5d87 100644 --- a/app/assets/javascripts/directives/cart.js.erb +++ b/app/assets/javascripts/directives/cart.js.erb @@ -112,12 +112,19 @@ Application.Directives.directive('cart', [ '$rootScope', '$uibModal', 'dialogs', * Switch the user's view from the reservation agenda to the plan subscription */ $scope.showPlans = function () { - // first, we ensure that a user was selected (admin) or logged (member) - if (Object.keys($scope.user).length > 0) { + // first, we ensure that a user was selected (admin) or logged (member) + const isSelectedUser = Object.keys($scope.user).length > 0; + // all slots are in future + const areFutureSlots = _.every($scope.events.reserved, function(s) { + return s.start.isAfter(); + }); + if (isSelectedUser && areFutureSlots) { return $scope.modePlans = true; - } else { + } else if (!isSelectedUser){ // otherwise we alert, this error musn't occur when the current user hasn't the admin role return growl.error(_t('app.shared.cart.please_select_a_member_first')); + } else if (!areFutureSlots){ + return growl.error(_t('app.shared.cart.unable_to_select_plant_if_slots_in_the_past')); } }; diff --git a/app/services/availabilities/availabilities_service.rb b/app/services/availabilities/availabilities_service.rb index c5ca16a12..fbf9fbae2 100644 --- a/app/services/availabilities/availabilities_service.rb +++ b/app/services/availabilities/availabilities_service.rb @@ -69,7 +69,7 @@ class Availabilities::AvailabilitiesService # first, we get the already-made reservations reservations = user.reservations.where("reservable_type = 'Training'") reservations = reservations.where('reservable_id = :id', id: training_id.to_i) if training_id.is_number? - reservations = reservations.joins(:slots).where('slots.start_at > ?', DateTime.current) + reservations = reservations.joins(:slots).where('slots.start_at > ?', @current_user.admin? ? 1.month.ago : DateTime.current) # visible availabilities depends on multiple parameters availabilities = training_availabilities(training_id, user) @@ -123,10 +123,10 @@ class Availabilities::AvailabilitiesService end # who made the request? - # 1) an admin (he can see all future availabilities) + # 1) an admin (he can see all avaialbilities of 1 month ago and future) if @current_user.admin? availabilities.includes(:tags, :slots, trainings: [:machines]) - .where('availabilities.start_at > ?', DateTime.current) + .where('availabilities.start_at > ?', 1.month.ago) .where(lock: false) # 2) an user (he cannot see availabilities further than 1 (or 3) months) else diff --git a/config/locales/app.shared.en.yml b/config/locales/app.shared.en.yml index a9c14c9f3..f94b078ad 100644 --- a/config/locales/app.shared.en.yml +++ b/config/locales/app.shared.en.yml @@ -429,6 +429,7 @@ en: your_booking_slot_was_successfully_moved_from_: "Your booking slot was successfully moved from" to_date: "to" # context: date. eg: 'from 01/01 to 01/05' please_select_a_member_first: 'Please select a member first' + unable_to_select_plant_if_slots_in_the_past: 'Unable to select a plan if have selected slots in the past' unable_to_change_the_reservation: "Unable to change the reservation" confirmation_required: "Confirmation required" do_you_really_want_to_cancel_this_reservation: "Do you really want to cancel this reservation?" diff --git a/config/locales/app.shared.es.yml b/config/locales/app.shared.es.yml index 8cf32e350..e0e8efc11 100644 --- a/config/locales/app.shared.es.yml +++ b/config/locales/app.shared.es.yml @@ -429,6 +429,7 @@ es: your_booking_slot_was_successfully_moved_from_: "Tu reserva de espacio ha sido reemplazada con éxito" to_date: "a" # context: date. eg: 'from 01/01 to 01/05' please_select_a_member_first: "Por favor, selecciona un miembro de la lista" + unable_to_select_plant_if_slots_in_the_past: 'No se puede seleccionar un plan si ha seleccionado espacios en el pasado' unable_to_change_the_reservation: "Imposible cambiar reserva" confirmation_required: "Confirmación requerida" do_you_really_want_to_cancel_this_reservation: "¿Está seguro de querer cancelar la reserva?" diff --git a/config/locales/app.shared.fr.yml b/config/locales/app.shared.fr.yml index 4689e7cd5..e855eff16 100644 --- a/config/locales/app.shared.fr.yml +++ b/config/locales/app.shared.fr.yml @@ -429,6 +429,7 @@ fr: your_booking_slot_was_successfully_moved_from_: "Votre créneau de réservation a bien été déplacé du" to_date: "au" # context: date. eg: 'from 01/01 to 01/05' please_select_a_member_first: "Veuillez tout d'abord sélectionner un membre" + unable_to_select_plant_if_slots_in_the_past: "Impossible de selectionner un abonnement s'il y a des créneaux passés" unable_to_change_the_reservation: "Impossible de modifier la réservation" confirmation_required: "Confirmation requise" do_you_really_want_to_cancel_this_reservation: "Êtes-vous sur de vouloir annuler cette réservation ?" diff --git a/config/locales/app.shared.pt.yml b/config/locales/app.shared.pt.yml index 0c0fbff49..cd539c818 100755 --- a/config/locales/app.shared.pt.yml +++ b/config/locales/app.shared.pt.yml @@ -429,6 +429,7 @@ pt: your_booking_slot_was_successfully_moved_from_: "Seu slot de reserva foi movido com sucesso para" to_date: "até" # context: date. eg: 'from 01/01 to 01/05' please_select_a_member_first: "Por favor selecione o membro primeiramente" + unable_to_select_plant_if_slots_in_the_past: 'Não foi possível selecionar um plano se houver slots selecionados no passado' unable_to_change_the_reservation: "Não permitido alterar esta reserva" confirmation_required: "Confirmação é obrigatória" do_you_really_want_to_cancel_this_reservation: "Você realmente quer cancelar essa reserva?"