1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-29 10:24:20 +01:00

Added reservation deadline parameter

This commit is contained in:
Guilherme Chaguri 2022-11-29 17:02:01 -03:00
parent 2a4d50e7d9
commit dea9663f37
8 changed files with 31 additions and 2 deletions

View File

@ -78,6 +78,7 @@ export const bookingSettings = [
'reminder_delay', 'reminder_delay',
'visibility_yearly', 'visibility_yearly',
'visibility_others', 'visibility_others',
'reservation_deadline',
'display_name_enable', 'display_name_enable',
'book_overlapping_slots', 'book_overlapping_slots',
'slot_duration', 'slot_duration',

View File

@ -1178,7 +1178,7 @@ angular.module('application.router', ['ui.router'])
"'renew_pack_threshold', 'pack_only_for_subscription', 'overlapping_categories', 'public_registrations'," + "'renew_pack_threshold', 'pack_only_for_subscription', 'overlapping_categories', 'public_registrations'," +
"'extended_prices_in_same_day', 'recaptcha_site_key', 'recaptcha_secret_key', 'user_validation_required', " + "'extended_prices_in_same_day', 'recaptcha_site_key', 'recaptcha_secret_key', 'user_validation_required', " +
"'user_validation_required_list', 'machines_module', 'user_change_group', 'show_username_in_admin_list', " + "'user_validation_required_list', 'machines_module', 'user_change_group', 'show_username_in_admin_list', " +
"'store_module']" "'store_module', 'reservation_deadline']"
}).$promise; }).$promise;
}], }],
privacyDraftsPromise: ['Setting', function (Setting) { return Setting.get({ name: 'privacy_draft', history: true }).$promise; }], privacyDraftsPromise: ['Setting', function (Setting) { return Setting.get({ name: 'privacy_draft', history: true }).$promise; }],

View File

@ -105,6 +105,18 @@
</div> </div>
</div> </div>
<div class="section-separator"></div> <div class="section-separator"></div>
<div class="row">
<h3 class="m-l m-t-lg" translate>{{ 'app.admin.settings.reservation_deadline' }}</h3>
<number-setting name="reservation_deadline"
settings="allSettings"
label="app.admin.settings.deadline_minutes"
classes="col-md-4"
fa-icon="fas fa-clock"
min="0"
required="true">
</number-setting>
</div>
<div class="section-separator"></div>
<div class="row"> <div class="row">
<h3 class="m-l m-t-lg" translate>{{ 'app.admin.settings.default_slot_duration' }}</h3> <h3 class="m-l m-t-lg" translate>{{ 'app.admin.settings.default_slot_duration' }}</h3>
<p class="alert alert-warning m-h-md" translate>{{ 'app.admin.settings.default_slot_duration_info' }}</p> <p class="alert alert-warning m-h-md" translate>{{ 'app.admin.settings.default_slot_duration_info' }}</p>

View File

@ -42,6 +42,10 @@ class CartItem::Reservation < CartItem::BaseItem
def valid?(all_items) def valid?(all_items)
pending_subscription = all_items.find { |i| i.is_a?(CartItem::Subscription) } pending_subscription = all_items.find { |i| i.is_a?(CartItem::Subscription) }
reservation_deadline_minutes = Setting.get('reservation_deadline').to_i
reservation_deadline = reservation_deadline_minutes.minutes.since
@slots.each do |slot| @slots.each do |slot|
slot_db = Slot.find(slot[:slot_id]) slot_db = Slot.find(slot[:slot_id])
if slot_db.nil? if slot_db.nil?
@ -60,6 +64,11 @@ class CartItem::Reservation < CartItem::BaseItem
return false return false
end end
if slot_db.start_at < reservation_deadline
@errors[:slot] = 'cannot reserve a slot ' + reservation_deadline_minutes.to_s + ' minutes prior to its start'
return false
end
next if availability.plan_ids.empty? next if availability.plan_ids.empty?
next if required_subscription?(availability, pending_subscription) next if required_subscription?(availability, pending_subscription)

View File

@ -53,6 +53,7 @@ class Setting < ApplicationRecord
space_explications_alert space_explications_alert
visibility_yearly visibility_yearly
visibility_others visibility_others
reservation_deadline
display_name_enable display_name_enable
machines_sort_by machines_sort_by
accounting_journal_code accounting_journal_code

View File

@ -9,6 +9,7 @@ class Availabilities::AvailabilitiesService
year: Setting.get('visibility_yearly').to_i.months.since, year: Setting.get('visibility_yearly').to_i.months.since,
other: Setting.get('visibility_others').to_i.months.since other: Setting.get('visibility_others').to_i.months.since
} }
@minimum_visibility = Setting.get('reservation_deadline').to_i.minutes.since
@service = Availabilities::StatusService.new(current_user&.role) @service = Availabilities::StatusService.new(current_user&.role)
@level = level @level = level
end end
@ -93,7 +94,7 @@ class Availabilities::AvailabilitiesService
end_at = @maximum_visibility[:year] if subscription_year?(user) && type != 'training' end_at = @maximum_visibility[:year] if subscription_year?(user) && type != 'training'
end_at = @maximum_visibility[:year] if show_more_trainings?(user) && type == 'training' end_at = @maximum_visibility[:year] if show_more_trainings?(user) && type == 'training'
window_end = [end_at, range_end].min window_end = [end_at, range_end].min
window_start = [range_start, DateTime.current].max window_start = [range_start, @minimum_visibility].max
availabilities.includes(:tags, :plans, :slots) availabilities.includes(:tags, :plans, :slots)
.joins(:slots) .joins(:slots)
.where('availabilities.start_at <= ? AND availabilities.end_at >= ? AND available_type = ?', window_end, window_start, type) .where('availabilities.start_at <= ? AND availabilities.end_at >= ? AND available_type = ?', window_end, window_start, type)

View File

@ -1350,6 +1350,8 @@ en:
max_visibility: "Maximum visibility (in months)" max_visibility: "Maximum visibility (in months)"
visibility_for_yearly_members: "For currently running subscriptions, at least 1 year long" visibility_for_yearly_members: "For currently running subscriptions, at least 1 year long"
visibility_for_other_members: "For all other members" visibility_for_other_members: "For all other members"
reservation_deadline: "Prevent last minute booking"
deadline_minutes: "Prior period (minutes)"
ability_for_the_users_to_move_their_reservations: "Ability for the users to move their reservations" ability_for_the_users_to_move_their_reservations: "Ability for the users to move their reservations"
reservations_shifting: "Reservations shifting" reservations_shifting: "Reservations shifting"
prior_period_hours: "Prior period (hours)" prior_period_hours: "Prior period (hours)"
@ -1405,6 +1407,7 @@ en:
default_value_is_24_hours: "If the field is leaved empty: 24 hours." default_value_is_24_hours: "If the field is leaved empty: 24 hours."
visibility_yearly: "maximum visibility for annual subscribers" visibility_yearly: "maximum visibility for annual subscribers"
visibility_others: "maximum visibility for other members" visibility_others: "maximum visibility for other members"
reservation_deadline: "reservation deadline"
display: "Display" display: "Display"
display_name_info_html: "When enabled, connected members browsing the calendar or booking a resource will see the name of the members who has already booked some slots. When disabled, only administrators and managers will view the names.<br/><strong>Warning:</strong> if you enable this feature, please write it down in your privacy policy." display_name_info_html: "When enabled, connected members browsing the calendar or booking a resource will see the name of the members who has already booked some slots. When disabled, only administrators and managers will view the names.<br/><strong>Warning:</strong> if you enable this feature, please write it down in your privacy policy."
display_reservation_user_name: "Display the full name of the user(s) who booked a slots" display_reservation_user_name: "Display the full name of the user(s) who booked a slots"

View File

@ -729,6 +729,8 @@ Setting.set('visibility_yearly', 3) unless Setting.find_by(name: 'visibility_yea
Setting.set('visibility_others', 1) unless Setting.find_by(name: 'visibility_others').try(:value) Setting.set('visibility_others', 1) unless Setting.find_by(name: 'visibility_others').try(:value)
Setting.set('reservation_deadline', 0) unless Setting.find_by(name: 'reservation_deadline').try(:value)
Setting.set('display_name_enable', false) unless Setting.find_by(name: 'display_name_enable').try(:value) Setting.set('display_name_enable', false) unless Setting.find_by(name: 'display_name_enable').try(:value)
Setting.set('machines_sort_by', 'default') unless Setting.find_by(name: 'machines_sort_by').try(:value) Setting.set('machines_sort_by', 'default') unless Setting.find_by(name: 'machines_sort_by').try(:value)