mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-02-17 11:54:22 +01:00
disable add plan with reserve slot in the past
This commit is contained in:
parent
0143c3d495
commit
3c26c6d4bd
@ -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'));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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?"
|
||||
|
@ -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?"
|
||||
|
@ -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 ?"
|
||||
|
@ -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?"
|
||||
|
Loading…
x
Reference in New Issue
Block a user