spree_cm_commissioner 2.14.4 → 2.14.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.env.example +7 -1
  3. data/Gemfile.lock +1 -1
  4. data/app/controllers/concerns/spree_cm_commissioner/content_cachable.rb +59 -3
  5. data/app/controllers/concerns/spree_cm_commissioner/waiting_room_authorization.rb +41 -8
  6. data/app/controllers/spree/admin/api_caches_controller.rb +23 -8
  7. data/app/controllers/spree/admin/homepage_section_controller.rb +63 -5
  8. data/app/controllers/spree/admin/homepage_section_relatable_controller.rb +24 -0
  9. data/app/controllers/spree/api/v2/organizer/invite_guests_controller.rb +2 -2
  10. data/app/controllers/spree/api/v2/resource_controller_decorator.rb +8 -0
  11. data/app/controllers/spree/api/v2/storefront/draft_orders_controller.rb +6 -2
  12. data/app/controllers/spree/api/v2/storefront/homepage_sections_controller.rb +1 -0
  13. data/app/controllers/spree/api/v2/storefront/invite_guests_controller.rb +2 -2
  14. data/app/controllers/spree/api/v2/storefront/preview_sections_controller.rb +1 -0
  15. data/app/controllers/spree/api/v2/storefront/queue_draft_orders_controller.rb +6 -2
  16. data/app/controllers/spree/api/v2/storefront/trip_search_controller.rb +18 -13
  17. data/app/controllers/spree/api/v2/storefront/user_contacts_controller.rb +2 -0
  18. data/app/controllers/spree/api/v2/tenant/draft_orders_controller.rb +6 -2
  19. data/app/controllers/spree/api/v2/tenant/homepage_sections_controller.rb +1 -0
  20. data/app/controllers/spree/api/v2/tenant/preview_sections_controller.rb +1 -0
  21. data/app/controllers/spree/api/v2/tenant/trip_search_controller.rb +18 -13
  22. data/app/factory/spree_cm_commissioner/order_telegram_message_factory.rb +5 -1
  23. data/app/helpers/spree_cm_commissioner/admin/homepage_segment_helper.rb +28 -0
  24. data/app/interactors/spree_cm_commissioner/account_recover.rb +23 -2
  25. data/app/interactors/spree_cm_commissioner/firebase_id_token_provider.rb +6 -2
  26. data/app/interactors/spree_cm_commissioner/telegram_chats_auto_finder.rb +26 -2
  27. data/app/interactors/spree_cm_commissioner/telegram_chats_finder.rb +1 -1
  28. data/app/interactors/spree_cm_commissioner/user_telegram_oauth_authenticator.rb +2 -11
  29. data/app/models/active_storage/variation_decorator.rb +18 -0
  30. data/app/models/concerns/spree_cm_commissioner/event_metadata.rb +4 -0
  31. data/app/models/concerns/spree_cm_commissioner/order_holdable.rb +3 -2
  32. data/app/models/concerns/spree_cm_commissioner/order_state_machine.rb +18 -13
  33. data/app/models/spree_cm_commissioner/homepage_section.rb +33 -0
  34. data/app/models/spree_cm_commissioner/homepage_section_app_background.rb +13 -0
  35. data/app/models/spree_cm_commissioner/homepage_section_web_background.rb +13 -0
  36. data/app/models/spree_cm_commissioner/maintenance_tasks/cache_invalidation.rb +95 -11
  37. data/app/models/spree_cm_commissioner/pin_code.rb +2 -1
  38. data/app/models/spree_cm_commissioner/pin_code_event_telegram.rb +31 -0
  39. data/app/models/spree_cm_commissioner/product_decorator.rb +7 -0
  40. data/app/models/spree_cm_commissioner/service_calendar.rb +2 -2
  41. data/app/models/spree_cm_commissioner/taxon_decorator.rb +7 -0
  42. data/app/models/spree_cm_commissioner/vendor_decorator.rb +6 -0
  43. data/app/overrides/spree/admin/taxons/_form/enforce_waiting_room_session.html.erb.deface +10 -0
  44. data/app/queries/spree_cm_commissioner/trip_query.rb +20 -2
  45. data/app/serializers/spree/v2/storefront/homepage_section_serializer.rb +4 -1
  46. data/app/serializers/spree/v2/tenant/homepage_section_serializer.rb +3 -1
  47. data/app/services/spree_cm_commissioner/api_caches/fetch_details.rb +128 -0
  48. data/app/services/spree_cm_commissioner/api_caches/invalidate.rb +31 -14
  49. data/app/services/spree_cm_commissioner/api_caches/invalidate_all.rb +16 -19
  50. data/app/services/spree_cm_commissioner/api_caches/request_clear.rb +71 -0
  51. data/app/services/spree_cm_commissioner/guests/claim_invite_guest_service.rb +5 -3
  52. data/app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_service_calendars.rb +3 -0
  53. data/app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_trip_stop.rb +21 -4
  54. data/app/services/spree_cm_commissioner/integrations/book_me_bus_v1/polling/sync_trips.rb +30 -4
  55. data/app/services/spree_cm_commissioner/inventory_items/bulk_generate_permanent_items.rb +15 -4
  56. data/app/services/spree_cm_commissioner/line_items/validate_purchase_limits.rb +56 -5
  57. data/app/services/spree_cm_commissioner/telegram/verify_oauth_id_token.rb +10 -0
  58. data/app/services/spree_cm_commissioner/telegram_alerts/send_telegram_order_alerts.rb +49 -0
  59. data/app/views/spree/admin/api_caches/_dialog.html.erb +47 -0
  60. data/app/views/spree/admin/api_caches/show.html.erb +88 -0
  61. data/app/views/spree/admin/homepage_section/_form.html.erb +44 -0
  62. data/app/views/spree/admin/homepage_section/edit.html.erb +16 -1
  63. data/app/views/spree/admin/shared/_api_cache_button.html.erb +5 -2
  64. data/config/initializers/spree_permitted_attributes.rb +1 -0
  65. data/config/locales/dry_validations.en.yml +4 -0
  66. data/config/locales/en.yml +50 -0
  67. data/config/locales/km.yml +50 -0
  68. data/config/routes.rb +8 -4
  69. data/db/migrate/20261021000001_add_section_type_to_cm_homepage_sections.rb +6 -0
  70. data/lib/spree_cm_commissioner/version.rb +1 -1
  71. metadata +13 -3
  72. data/app/jobs/spree_cm_commissioner/invalidate_cache_request_job.rb +0 -10
@@ -1,6 +1,7 @@
1
1
  # Per-product purchase caps, one independent check per scope. The order cap looks at a single
2
- # order; account/ip/device aggregate over the buyer's completed orders, so a customer can't
3
- # bypass a cap by splitting the purchase across carts.
2
+ # order; account/ip/device aggregate over the buyer's completed orders and their other carts
3
+ # still under an unexpired hold, so a customer can't bypass a cap by splitting the purchase
4
+ # across carts - including carts opened while an earlier one is still unpaid.
4
5
  #
5
6
  # A cap of nil or 0 is off. A scope with no value on the order (guest order, no IP, no device
6
7
  # id) has nothing to count the buyer against, so its cap does not apply.
@@ -16,6 +17,32 @@ module SpreeCmCommissioner
16
17
 
17
18
  COUNTED_STATES = %w[complete resumed].freeze
18
19
 
20
+ # An unpaid cart counts until its hold expires. Without a hold (a product without inventory
21
+ # holds) it counts while still in checkout - not sent back to `cart`, not archived - for one
22
+ # hold duration after its last update; entering checkout or paying bumps updated_at. A
23
+ # released hold clears hold_expires_at and sends the cart back to `cart`, so it stops
24
+ # counting at once. A `cart` order can't be paid without re-entering `address`, which runs
25
+ # this check again (OrderStateMachine#ensure_within_purchase_limits).
26
+ # Spree's metadata serializer stores public_metadata as a JSON string inside the jsonb
27
+ # column, so `->>` on it is always NULL; `#>> '{}'` unwraps it (or an object) back to jsonb.
28
+ COUNTED_ORDERS_SQL = <<~SQL.squish.freeze
29
+ (spree_orders.completed_at IS NOT NULL AND spree_orders.state IN (:states))
30
+ OR (
31
+ spree_orders.completed_at IS NULL
32
+ AND COALESCE(
33
+ ((spree_orders.public_metadata #>> '{}')::jsonb->>'hold_expires_at')::timestamptz,
34
+ CASE WHEN spree_orders.state <> 'cart' AND spree_orders.archived_at IS NULL
35
+ THEN spree_orders.updated_at + make_interval(secs => :hold_seconds) END
36
+ ) > :now
37
+ )
38
+ SQL
39
+
40
+ AGGREGATE_SCOPES = {
41
+ account: %i[max_quantity_per_account user_id],
42
+ device: %i[max_quantity_per_device device_id],
43
+ ip: %i[max_quantity_per_ip last_ip_address]
44
+ }.freeze
45
+
19
46
  def call(line_item:)
20
47
  @line_item = line_item
21
48
  @product = line_item.product
@@ -23,6 +50,8 @@ module SpreeCmCommissioner
23
50
 
24
51
  return success(nil) if @product.blank?
25
52
 
53
+ lock_buyer!
54
+
26
55
  check_order_limit!
27
56
  check_account_limit!
28
57
  check_ip_limit!
@@ -35,6 +64,22 @@ module SpreeCmCommissioner
35
64
 
36
65
  private
37
66
 
67
+ # Two carts for the same buyer saved at the same moment can't see each other's uncommitted
68
+ # rows, so both would pass. A transaction-level lock per capped identity makes the second
69
+ # wait until the first commits - in DraftOrders::Create that is after the hold sets
70
+ # hold_expires_at, so the second then counts it. Only capped identities are locked, so
71
+ # unrelated buyers never wait; outside a transaction (a bare valid?) the lock is released
72
+ # at once, which is harmless.
73
+ def lock_buyer!
74
+ AGGREGATE_SCOPES.each do |scope, (cap_attribute, identity_column)|
75
+ identity = @order&.public_send(identity_column)
76
+ next unless @product.public_send(cap_attribute).to_i.positive? && identity.present?
77
+
78
+ key = Zlib.crc32("spree_cm_commissioner:purchase_limit:#{scope}:#{identity}")
79
+ Spree::Order.connection.execute("SELECT pg_advisory_xact_lock(#{key})")
80
+ end
81
+ end
82
+
38
83
  def check_order_limit!
39
84
  limit = @product.max_quantity_per_order.to_i
40
85
  return unless limit.positive?
@@ -102,18 +147,24 @@ module SpreeCmCommissioner
102
147
  end
103
148
  end
104
149
 
105
- # What the buyer already holds for this product, outside the order being validated.
150
+ # What the buyer already holds for this product, outside the order being validated:
151
+ # completed orders, plus unpaid carts still inside their hold (OrderHolds::Hold, kept
152
+ # alive through payment by OrderHolds::LockForPayment), see COUNTED_ORDERS_SQL. An
153
+ # abandoned cart stops counting on its own, so no cleanup is needed.
106
154
  # product_id is not a column on spree_line_items - it is `delegate :product_id, to:
107
155
  # :variant` - so the product filter joins through spree_variants, indexed on product_id.
108
156
  def purchased_by(scope)
109
157
  Spree::LineItem.joins(:order, :variant)
110
- .where(spree_orders: { state: COUNTED_STATES })
111
158
  .where(spree_orders: scope)
112
159
  .where(spree_variants: { product_id: @product.id })
113
- .where.not(spree_orders: { completed_at: nil })
114
160
  .where.not(spree_orders: { id: @line_item.order_id })
161
+ .where(COUNTED_ORDERS_SQL, states: COUNTED_STATES, now: Time.current, hold_seconds: hold_seconds)
115
162
  .sum(:quantity)
116
163
  end
164
+
165
+ def hold_seconds
166
+ SpreeCmCommissioner::OrderHolds::Hold::HOLD_DURATION.to_i
167
+ end
117
168
  end
118
169
  end
119
170
  end
@@ -20,6 +20,16 @@ module SpreeCmCommissioner
20
20
 
21
21
  VerificationError = Class.new(StandardError)
22
22
 
23
+ # Each tenant runs its own Telegram bot, so the audience an id_token must
24
+ # carry is looked up on the tenant directly - a missing tenant returns nil
25
+ # (fails as not configured) instead of silently authenticating against
26
+ # someone else's bot. No tenant means the storefront's default store bot.
27
+ def self.client_id_for(tenant_id)
28
+ return Spree::Store.default.preferred_telegram_oauth_client_id if tenant_id.blank?
29
+
30
+ SpreeCmCommissioner::Tenant.find_by(id: tenant_id)&.preferred_telegram_oauth_client_id
31
+ end
32
+
23
33
  def call(id_token:, client_id:)
24
34
  return failure(nil, 'telegram_id_token_missing') if id_token.blank?
25
35
  return failure(nil, 'telegram_oauth_client_id_not_configured') if client_id.blank?
@@ -0,0 +1,49 @@
1
+ module SpreeCmCommissioner
2
+ module TelegramAlerts
3
+ # Order-complete alert. Each line item goes to its event's own group
4
+ # (Taxon#telegram_alert_chat_id) if set, otherwise to its vendor's group.
5
+ class SendTelegramOrderAlerts
6
+ prepend Spree::ServiceModule::Base
7
+
8
+ # e.g. one order has a Concert ticket and a Run ticket:
9
+ # Concert has its own group -> Concert group gets the Concert ticket
10
+ # Run has no group -> falls back to the vendor's Telegram group, which gets the Run ticket
11
+ def call(order:)
12
+ return success(nil) unless order.telegram_alert_enabled?
13
+
14
+ line_items = order.line_items.includes(:vendor, :event).select { |item| alertable?(order, item) }
15
+
16
+ # One entry per chat, listing the tickets that chat's message shows:
17
+ # [vendor, '-100999'] => [concert_ticket] # Concert's own group
18
+ # [vendor, '-100111'] => [run_ticket] # vendor's group
19
+ groups = line_items.group_by { |item| [item.vendor, chat_id_for(item)] }
20
+
21
+ groups.each do |(vendor, chat_id), items|
22
+ send_alert(order, vendor, chat_id, items)
23
+ end
24
+
25
+ success(nil)
26
+ end
27
+
28
+ private
29
+
30
+ def alertable?(order, item)
31
+ item.vendor.present? &&
32
+ chat_id_for(item).present? &&
33
+ item.vendor.alerts_telegram_for_channel?(order.channel_key)
34
+ end
35
+
36
+ def chat_id_for(item)
37
+ item.event&.telegram_alert_chat_id || item.vendor&.preferred_telegram_chat_id
38
+ end
39
+
40
+ # `line_items:` limits the message to this chat's items; without it the factory lists every
41
+ # item of the vendor.
42
+ def send_alert(order, vendor, chat_id, line_items)
43
+ factory = OrderTelegramMessageFactory.new(title: order.vendor_alert_title(vendor), order: order, vendor: vendor, line_items: line_items)
44
+
45
+ TelegramNotificationSenderJob.perform_later(chat_id: chat_id.to_s, message: factory.message, parse_mode: factory.parse_mode)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,47 @@
1
+ <%# One per page, rendered by shared/_api_cache_button, whose link loads spree/admin/api_caches/show
2
+ into its frame, which opens it. A native <dialog> because this admin's bundle has no Bootstrap
3
+ modal plugin ($.fn.modal); Bootstrap's modal-content classes still give it the admin's look.
4
+ text-left because it renders inside the right-aligned page actions. %>
5
+ <dialog class="text-left api-cache-dialog" aria-labelledby="api_cache_dialog_title" onclick="if (event.target === this) this.close();">
6
+ <%= turbo_frame_tag 'api_cache_dialog', target: '_top', class: 'border-0 modal-content' %>
7
+ </dialog>
8
+
9
+ <style>
10
+ .api-cache-dialog { width: min(40rem, calc(100vw - 2rem)); max-height: 85vh; padding: 0; border: 0; border-radius: 0.3rem; font-size: 0.875rem; font-weight: 400; white-space: normal; }
11
+ .api-cache-dialog::backdrop { background: rgb(0 0 0 / 0.5); }
12
+ .api-cache-dialog .modal-body { max-height: 65vh; overflow-y: auto; }
13
+ .api-cache-dialog code { word-break: break-all; }
14
+ </style>
15
+
16
+ <%# The dashboard's api_cache_dialog_controller.js, without Stimulus: opens the dialog once its
17
+ frame has loaded, and reloads it while show marks a clear as still in progress. %>
18
+ <script>
19
+ if (!window.apiCacheDialogListening) {
20
+ window.apiCacheDialogListening = true;
21
+
22
+ document.addEventListener('turbo:frame-load', function (event) {
23
+ var frame = event.target;
24
+ if (frame.id !== 'api_cache_dialog') return;
25
+
26
+ var dialog = frame.closest('dialog');
27
+ // A reload that finishes after the dialog was closed must not reopen it.
28
+ if (!frame.dataset.reloading && !dialog.open) dialog.showModal();
29
+ delete frame.dataset.reloading;
30
+
31
+ clearTimeout(window.apiCacheDialogReloadTimer);
32
+ if (!frame.querySelector('[data-api-cache-busy]')) return;
33
+
34
+ window.apiCacheDialogReloadTimer = setTimeout(function () {
35
+ if (!dialog.open) return;
36
+
37
+ frame.dataset.reloading = 'true';
38
+ frame.reload();
39
+ }, 5000);
40
+ });
41
+
42
+ document.addEventListener('turbo:before-cache', function () {
43
+ var dialog = document.querySelector('.api-cache-dialog');
44
+ if (dialog && dialog.open) dialog.close();
45
+ });
46
+ }
47
+ </script>
@@ -0,0 +1,88 @@
1
+ <%# Fills _dialog's frame; the dashboard's shared_console/api_caches/show shows the same data in its
2
+ own style. %>
3
+ <% scope = 'spree_cm_commissioner.api_caches.details' %>
4
+ <% badge_classes = { queued: 'badge-info', sent: 'badge-success', skipped: 'badge-secondary', failed: 'badge-danger' } %>
5
+ <% alert_classes = { queued: 'alert-info', pending: 'alert-info', edited: 'alert-warning', sent: 'alert-success', up_to_date: 'alert-success' } %>
6
+ <% heading = 'text-uppercase text-muted small font-weight-bold' %>
7
+ <% state = @details[:state] %>
8
+
9
+ <%= turbo_frame_tag 'api_cache_dialog' do %>
10
+ <div class="modal-header">
11
+ <h5 id="api_cache_dialog_title" class="modal-title"><%= I18n.t('title', scope: scope) %></h5>
12
+ <button type="button" class="close" aria-label="<%= I18n.t('close', scope: scope) %>" onclick="this.closest('dialog').close();">
13
+ <span aria-hidden="true">&times;</span>
14
+ </button>
15
+ </div>
16
+
17
+ <div class="modal-body">
18
+ <div class="alert <%= alert_classes[state] %> mb-2">
19
+ <% case state %>
20
+ <% when :pending %>
21
+ <% if @details[:sends_by].future? %>
22
+ <%= t('headline.pending_html', scope: scope, time: l(@details[:sends_by], format: '%H:%M')) %>
23
+ <% else %>
24
+ <%= I18n.t('headline.pending_due', scope: scope) %>
25
+ <% end %>
26
+ <% when :edited %>
27
+ <%= I18n.t('headline.edited', scope: scope, ago: time_ago_in_words(@details[:edited_at])) %>
28
+ <% when :sent %>
29
+ <%= t('headline.sent_html', scope: scope, time: l(@details[:sent_at], format: '%H:%M')) %>
30
+ <% else %>
31
+ <%= I18n.t("headline.#{state}", scope: scope) %>
32
+ <% end %>
33
+ </div>
34
+ <% if @details[:failure].present? %>
35
+ <p class="small text-danger mb-2"><%= I18n.t('failure', scope: scope, error: @details[:failure]) %></p>
36
+ <% end %>
37
+ <% if %i[up_to_date edited].include?(state) %>
38
+ <p class="small text-muted"><%= t('hint_html', scope: scope, duration: distance_of_time_in_words(@details[:refresh_seconds])) %></p>
39
+ <% end %>
40
+
41
+ <h6 class="<%= heading %> mt-4"><%= I18n.t('history', scope: scope) %></h6>
42
+ <% if @details[:history].any? %>
43
+ <table class="table table-sm mb-0">
44
+ <thead>
45
+ <tr>
46
+ <th><%= I18n.t('when', scope: scope) %></th>
47
+ <th><%= I18n.t('by', scope: scope) %></th>
48
+ <th><%= I18n.t('status', scope: scope) %></th>
49
+ </tr>
50
+ </thead>
51
+ <tbody>
52
+ <% @details[:history].each do |entry| %>
53
+ <tr>
54
+ <td title="<%= l(entry[:at], format: :long) %>"><%= I18n.t('ago', scope: scope, time: time_ago_in_words(entry[:at])) %></td>
55
+ <td><%= entry[:by] %></td>
56
+ <td>
57
+ <span class="badge <%= badge_classes[entry[:status]] %>"><%= I18n.t("statuses.#{entry[:status]}", scope: scope) %></span>
58
+ <% if entry[:error].present? %>
59
+ <div class="small text-danger mt-1"><%= entry[:error] %></div>
60
+ <% end %>
61
+ </td>
62
+ </tr>
63
+ <% end %>
64
+ </tbody>
65
+ </table>
66
+ <% else %>
67
+ <p class="text-muted mb-0"><%= I18n.t('never_cleared', scope: scope) %></p>
68
+ <% end %>
69
+
70
+ <h6 class="<%= heading %> mt-4"><%= I18n.t('paths', scope: scope, count: @details[:patterns].size) %></h6>
71
+ <% @details[:patterns].each do |pattern| %>
72
+ <div><code><%= pattern %></code></div>
73
+ <% end %>
74
+ </div>
75
+
76
+ <div class="modal-footer">
77
+ <button type="button" class="btn btn-light" onclick="this.closest('dialog').close();"><%= I18n.t('cancel', scope: scope) %></button>
78
+ <%# Every other state clears on its own, so the button only stands out when a clear failed. %>
79
+ <%= button_to I18n.t(@details[:busy] ? 'clearing' : 'clear_now', scope: scope),
80
+ clear_admin_api_cache_path(model: params[:model], id: params[:id], tenant_id: params[:tenant_id]),
81
+ disabled: @details[:busy], class: @details[:failure].present? ? 'btn btn-primary' : 'btn btn-outline-primary' %>
82
+ </div>
83
+
84
+ <% if @details[:busy] %>
85
+ <%# Reloads the dialog until the clear has been sent. %>
86
+ <div hidden data-api-cache-busy></div>
87
+ <% end %>
88
+ <% end %>
@@ -8,6 +8,32 @@
8
8
  <%= f.label :title %>
9
9
  <%= f.text_field :title, class: 'form-control' %>
10
10
  <% end %>
11
+ <%= f.field_container :section_type do %>
12
+ <%= f.label :section_type, Spree.t(:section_type) %>
13
+ <%= f.select :section_type,
14
+ SpreeCmCommissioner::HomepageSection.section_types.keys.map { |key| [Spree.t("section_types.#{key}"), key] },
15
+ {}, class: 'fullwidth select2' %>
16
+ <% end %>
17
+ <div id="homepage_section_trending_fields">
18
+ <%= f.field_container :font do %>
19
+ <%= f.label :font, Spree.t(:font) %>
20
+ <%= f.text_field :font, class: 'form-control' %>
21
+ <% end %>
22
+ <%= render 'shared/asset_field',
23
+ field: :app_background,
24
+ label: Spree.t(:app_background),
25
+ asset: f.object.app_background,
26
+ remove_url: (f.object.app_background.present? ? remove_app_background_admin_homepage_feed_homepage_section_url(f.object) : nil),
27
+ form: f,
28
+ classes: ['col-md-12'] %>
29
+ <%= render 'shared/asset_field',
30
+ field: :web_background,
31
+ label: Spree.t(:web_background),
32
+ asset: f.object.web_background,
33
+ remove_url: (f.object.web_background.present? ? remove_web_background_admin_homepage_feed_homepage_section_url(f.object) : nil),
34
+ form: f,
35
+ classes: ['col-md-12'] %>
36
+ </div>
11
37
  <%= f.field_container :segment do %>
12
38
  <%= f.label :segment, class: 'd-flex align-items-center' %>
13
39
  <div class="d-flex flex-wrap">
@@ -59,3 +85,21 @@
59
85
  </div>
60
86
  </div>
61
87
  </div>
88
+ <script>
89
+ $(document).ready(function () {
90
+ const sectionTypeSelector = "#spree_cm_commissioner_homepage_section_section_type"
91
+ const trendingFieldsSelector = "#homepage_section_trending_fields"
92
+
93
+ // initialize
94
+ toggleTrendingFields();
95
+
96
+ $(sectionTypeSelector).on("change", function () {
97
+ toggleTrendingFields();
98
+ });
99
+
100
+ function toggleTrendingFields() {
101
+ var selectedType = $(sectionTypeSelector).val();
102
+ $(trendingFieldsSelector).toggle(selectedType === "trending");
103
+ }
104
+ });
105
+ </script>
@@ -18,8 +18,15 @@
18
18
  <div class="col-12">
19
19
  <div class="d-flex justify-content-between mb-3">
20
20
  <p class="font-weight-bold">Section Relatable</p>
21
- <%= button_link_to Spree.t(:new_homepage_section_relatable), new_admin_homepage_feed_homepage_section_relatable_path(homepage_section_id: @object.id), { class: "btn btn-outline-primary", icon: 'add.svg', id: 'admin_new_homepage_section_relatable' } %>
21
+ <div>
22
+ <% if @homepage_section_relatables.any? { |relatable| relatable.relatable.is_a?(Spree::Taxon) && relatable.relatable.from_date.present? } %>
23
+ <%= button_to Spree.t(:sort_by_start_date), sort_by_start_date_admin_homepage_feed_homepage_section_relatable_index_url(homepage_section_id: @object.id),
24
+ method: :post, class: 'btn btn-outline-secondary', form: { data: { confirm: Spree.t(:sort_by_start_date_confirm) } }, id: 'admin_sort_homepage_section_relatable_by_start_date' %>
25
+ <% end %>
26
+ <%= button_link_to Spree.t(:new_homepage_section_relatable), new_admin_homepage_feed_homepage_section_relatable_path(homepage_section_id: @object.id), { class: "btn btn-outline-primary", icon: 'add.svg', id: 'admin_new_homepage_section_relatable' } %>
27
+ </div>
22
28
  </div>
29
+ <% has_taxon_relatable = @homepage_section_relatables.any? { |relatable| relatable.relatable.is_a?(Spree::Taxon) } %>
23
30
  <% if @homepage_section_relatables.any? %>
24
31
  <div class="table-responsive">
25
32
  <table class="table sortable" data-hook="homepage_sections_table" data-sortable-link="<%= update_positions_admin_homepage_feed_homepage_section_relatable_index_url %>" >
@@ -29,6 +36,9 @@
29
36
  <%= Spree.t(:title) %>
30
37
  </th>
31
38
  <th scope="col"><%= Spree.t(:relatable_type) %></th>
39
+ <% if has_taxon_relatable %>
40
+ <th scope="col"><%= Spree.t(:event_date) %></th>
41
+ <% end %>
32
42
  <th scope="col"><%= Spree.t(:created_at) %></th>
33
43
  <th scope="col"><%= Spree.t(:active) %></th>
34
44
  <th scope="col"></th>
@@ -58,6 +68,11 @@
58
68
  <td>
59
69
  <%= section_relatable.relatable_type&.demodulize %>
60
70
  </td>
71
+ <% if has_taxon_relatable %>
72
+ <td>
73
+ <%= homepage_section_relatable_event_dates(section_relatable) || content_tag(:span, '—', class: 'text-muted') %>
74
+ </td>
75
+ <% end %>
61
76
  <td>
62
77
  <%= pretty_time(section_relatable.created_at) %>
63
78
  </td>
@@ -1,5 +1,8 @@
1
1
  <%# locals: model (an ApiCaches::Invalidate::SUPPORTED_MODELS key), id (one record), tenant_id (with
2
- no id, clears every record of model on that tenant's API; neither clears the BookMe+ storefront). %>
2
+ no id, clears every record of model on that tenant's API; neither clears the BookMe+ storefront).
3
+ Opens the dialog, which shows the record's recent clears and holds the button that clears. %>
3
4
  <% id ||= nil %>
4
5
  <% tenant_id ||= nil %>
5
- <%= button_link_to Spree.t(:clear_cache), clear_admin_api_caches_path(model: model, id: id, tenant_id: tenant_id), method: :post, class: 'btn btn-outline-primary' %>
6
+ <%= link_to Spree.t(:clear_cache), admin_api_cache_path(model: model, id: id, tenant_id: tenant_id),
7
+ class: 'btn btn-outline-primary', data: { turbo_frame: 'api_cache_dialog' } %>
8
+ <%= render 'spree/admin/api_caches/dialog' %>
@@ -57,6 +57,7 @@ module Spree
57
57
  group_check_in_enabled
58
58
  individual_check_in_enabled
59
59
  allow_manual_search_for_operator
60
+ enforce_waiting_room_session
60
61
  show_badge_status
61
62
  purchasable_on
62
63
  available_on
@@ -2,6 +2,10 @@ en:
2
2
  dry_validation:
3
3
  errors:
4
4
  rules:
5
+ date:
6
+ must_be_in_future: Date must be today or in the future
7
+ origin_id:
8
+ must_be_different: Origin and destination must be different
5
9
  from_date:
6
10
  must_be_in_future: Start date must be today or in future
7
11
  must_be_later_than_start_date: 'End Date must be later than or equal Start Date'
@@ -195,6 +195,7 @@ en:
195
195
  errors:
196
196
  messages:
197
197
  must_be_positive_integer: "must be a positive whole number"
198
+ invalid_section_type: "Section type was not recognized, so it was left unchanged."
198
199
 
199
200
  purchase_limit:
200
201
  device_cap_requires_app_only: "Device limit requires the ticket to be app-only."
@@ -287,6 +288,14 @@ en:
287
288
  tenant: "Tenant"
288
289
  segment: "Segment"
289
290
  homepages: "Homepages"
291
+ section_type: "Section Type"
292
+ font: "Font"
293
+ app_background: "App Background"
294
+ web_background: "Web Background"
295
+ section_types:
296
+ default: "Default"
297
+ trending: "Trending"
298
+ big_banner: "Big Banner"
290
299
  purchase_limits:
291
300
  title: "Purchase Limits"
292
301
  hint: "Caps on how many units one buyer can purchase, checked independently per scope. Leave blank to disable. Caps never reset and lowering one does not claw back past purchases."
@@ -372,7 +381,12 @@ en:
372
381
  csv_interrupted: "The CSV file is interrupted. Please generate again."
373
382
  csv_unknown_status: "Something went wrong. Please try again."
374
383
  new_homepage_banner: "Add New Banner"
384
+ event_date: "Event Date"
385
+ sort_by_start_date: "Sort By Start Date"
386
+ sort_by_start_date_confirm: "This will reorder the relatables by their event start date, overriding the current manual order. Continue?"
375
387
  invalid_session_token: "Invalid session token"
388
+ enforce_waiting_room_session: "Enforce waiting room on order"
389
+ enforce_waiting_room_session_hint: "Orders for this event are rejected unless the buyer holds an active waiting-room session. Buyers using a private sale link are exempt. The website has no waiting room yet, so web orders for this event are rejected too."
376
390
  intel_phone_number: "Intel Phone Number"
377
391
  phone_number: "Phone Number"
378
392
  contact: "Contact"
@@ -1290,6 +1304,42 @@ en:
1290
1304
  return_before_outbound: "Return date must be after the outbound trip date"
1291
1305
  trip_not_available: "Trip is not available for redemption"
1292
1306
  spree_cm_commissioner:
1307
+ api_caches:
1308
+ another_clear_in_progress: "Another clear is still waiting to be sent. Try again in a minute."
1309
+ cooldown: "Cleared recently. You can clear it again at %{time}."
1310
+ details:
1311
+ title: "Clear cache"
1312
+ close: "Close"
1313
+ cancel: "Cancel"
1314
+ clear_now: "Clear cache"
1315
+ clearing: "Clearing…"
1316
+ headline:
1317
+ queued: "Clearing… waiting to be sent."
1318
+ pending_html: "A change is waiting to clear on its own by about <strong>%{time}</strong>. Clear only if it can't wait that long."
1319
+ pending_due: "A change is waiting to clear on its own any minute now."
1320
+ edited: "Edited %{ago} ago."
1321
+ sent_html: "Sent at <strong>%{time}</strong>. The app shows the latest version within a minute or two."
1322
+ up_to_date: "Up to date."
1323
+ hint_html: "Edits show in the app on their own within <strong>%{duration}</strong>. Clear only if it can't wait that long."
1324
+ cooldown_html: "Cleared recently. You can clear it again at <strong>%{time}</strong>; anything edited since then shows on its own by that time anyway."
1325
+ failure: "The last clear didn't go through: %{error}"
1326
+ history: "Recent clears"
1327
+ never_cleared: "Not cleared yet."
1328
+ when: "When"
1329
+ by: "By"
1330
+ status: "Status"
1331
+ ago: "%{time} ago"
1332
+ automatic: "Automatic"
1333
+ unknown_user: "Unknown user"
1334
+ admin_only: "Admin only"
1335
+ paths:
1336
+ one: "Path"
1337
+ other: "Paths (%{count})"
1338
+ statuses:
1339
+ queued: "Queued"
1340
+ sent: "Sent"
1341
+ skipped: "Skipped"
1342
+ failed: "Failed"
1293
1343
  draft_order:
1294
1344
  line_items_missing: "Line items are missing"
1295
1345
  inventory_item:
@@ -161,6 +161,7 @@ km:
161
161
  errors:
162
162
  messages:
163
163
  must_be_positive_integer: "ត្រូវតែជាចំនួនគត់វិជ្ជមាន"
164
+ invalid_section_type: "ប្រភេទផ្នែកមិនត្រឹមត្រូវទេ ដូច្នេះវានៅដូចដើម។"
164
165
 
165
166
  purchase_limit:
166
167
  device_cap_requires_app_only: "ដែនកំណត់តាមឧបករណ៍ត្រូវការឱ្យសំបុត្រមានតែក្នុងកម្មវិធីប៉ុណ្ណោះ។"
@@ -245,6 +246,14 @@ km:
245
246
  tenant: "អង្គភាព"
246
247
  segment: "ផ្នែក"
247
248
  homepages: "ទំព័រដើម"
249
+ section_type: "ប្រភេទផ្នែក"
250
+ font: "ពុម្ពអក្សរ"
251
+ app_background: "ផ្ទៃខាងក្រោយកម្មវិធី"
252
+ web_background: "ផ្ទៃខាងក្រោយវិបសាយ"
253
+ section_types:
254
+ default: "លំនាំដើម"
255
+ trending: "កំពុងពេញនិយម"
256
+ big_banner: "បដាធំ"
248
257
  purchase_limits:
249
258
  title: "ដែនកំណត់ការទិញ"
250
259
  hint: "ដែនកំណត់ចំនួនដែលអ្នកទិញម្នាក់អាចទិញបាន ដោយពិនិត្យដោយឡែកតាមប្រភេទនីមួយៗ។ ទុកទទេដើម្បីបិទ។ ដែនកំណត់មិនកំណត់ឡើងវិញទេ ហើយការបន្ថយវាមិនប៉ះពាល់ការទិញកន្លងមកឡើយ។"
@@ -325,7 +334,12 @@ km:
325
334
  csv_interrupted: "The CSV file is interrupted. Please generate again."
326
335
  csv_unknown_status: "Something went wrong. Please try again."
327
336
  new_homepage_banner: "បន្ថែមផ្ទាំងរូបភាពថ្មី"
337
+ event_date: "កាលបរិច្ឆេទព្រឹត្តិការណ៍"
338
+ sort_by_start_date: "តម្រៀបតាមកាលបរិច្ឆេទចាប់ផ្តើម"
339
+ sort_by_start_date_confirm: "សកម្មភាពនេះនឹងរៀបចំលំដាប់ធាតុដែលទាក់ទងឡើងវិញ តាមកាលបរិច្ឆេទចាប់ផ្តើមព្រឹត្តិការណ៍ ដោយបដិសេធលំដាប់ដែលបានកំណត់ដោយដៃពីមុន។ តើបន្តទេ?"
328
340
  invalid_session_token: "Invalid session token"
341
+ enforce_waiting_room_session: "តម្រូវឱ្យឆ្លងកាត់បន្ទប់រង់ចាំមុនពេលបញ្ជាទិញ"
342
+ enforce_waiting_room_session_hint: "ការបញ្ជាទិញសម្រាប់ព្រឹត្តិការណ៍នេះនឹងត្រូវបដិសេធ លុះត្រាតែអ្នកទិញមានវគ្គបន្ទប់រង់ចាំដែលនៅសកម្ម។ អ្នកទិញតាមតំណលក់ឯកជនមិនស្ថិតក្រោមលក្ខខណ្ឌនេះទេ។ គេហទំព័រមិនទាន់មានបន្ទប់រង់ចាំនៅឡើយ ដូច្នេះការបញ្ជាទិញតាមគេហទំព័រសម្រាប់ព្រឹត្តិការណ៍នេះក៏នឹងត្រូវបដិសេធដែរ។"
329
343
  intel_phone_number: "លេខទូរសព្ទ"
330
344
  phone_number: "លេខទូរសព្ទ"
331
345
  new_customer: "អតិថិជនថ្មី"
@@ -867,6 +881,42 @@ km:
867
881
  service_unavailable: "សេវាកម្មផ្ទៀងផ្ទាត់បច្ចុប្បន្នមិនអាចប្រើបានទេ។ សូមព្យាយាមម្តងទៀតក្នុងពេលឆាប់ៗនេះ។"
868
882
 
869
883
  spree_cm_commissioner:
884
+ api_caches:
885
+ another_clear_in_progress: "ការសម្អាតមួយផ្សេងទៀតកំពុងរង់ចាំផ្ញើ។ សូមព្យាយាមម្តងទៀតក្នុងរយៈពេលមួយនាទី។"
886
+ cooldown: "ទើបតែបានសម្អាត។ អ្នកអាចសម្អាតម្តងទៀតនៅម៉ោង %{time}។"
887
+ details:
888
+ title: "សម្អាតឃ្លាំងទិន្នន័យ"
889
+ close: "បិទ"
890
+ cancel: "បោះបង់"
891
+ clear_now: "សម្អាតឃ្លាំងទិន្នន័យ"
892
+ clearing: "កំពុងសម្អាត…"
893
+ headline:
894
+ queued: "កំពុងសម្អាត… កំពុងរង់ចាំផ្ញើ។"
895
+ pending_html: "ការផ្លាស់ប្តូរមួយកំពុងរង់ចាំសម្អាតដោយស្វ័យប្រវត្តិ ប្រហែលម៉ោង <strong>%{time}</strong>។ សម្អាតតែពេលដែលមិនអាចរង់ចាំបាន។"
896
+ pending_due: "ការផ្លាស់ប្តូរមួយនឹងសម្អាតដោយស្វ័យប្រវត្តិក្នុងពេលឆាប់ៗនេះ។"
897
+ edited: "បានកែប្រែ %{ago} មុន។"
898
+ sent_html: "បានផ្ញើនៅម៉ោង <strong>%{time}</strong>។ កម្មវិធីនឹងបង្ហាញកំណែចុងក្រោយក្នុងរយៈពេលមួយ ឬពីរនាទី។"
899
+ up_to_date: "ទាន់សម័យ។"
900
+ hint_html: "ការកែប្រែនឹងបង្ហាញក្នុងកម្មវិធីដោយស្វ័យប្រវត្តិក្នុងរយៈពេល <strong>%{duration}</strong>។ សម្អាតតែពេលដែលមិនអាចរង់ចាំបាន។"
901
+ cooldown_html: "ទើបតែបានសម្អាត។ អ្នកអាចសម្អាតម្តងទៀតនៅម៉ោង <strong>%{time}</strong>។ អ្វីដែលបានកែប្រែចាប់តាំងពីពេលនោះ នឹងបង្ហាញដោយស្វ័យប្រវត្តិមុនពេលនោះដដែល។"
902
+ failure: "ការសម្អាតចុងក្រោយមិនបានសម្រេច៖ %{error}"
903
+ history: "ការសម្អាតថ្មីៗ"
904
+ never_cleared: "មិនទាន់បានសម្អាតនៅឡើយ។"
905
+ when: "ពេលវេលា"
906
+ by: "ដោយ"
907
+ status: "ស្ថានភាព"
908
+ ago: "%{time} មុន"
909
+ automatic: "ស្វ័យប្រវត្តិ"
910
+ unknown_user: "អ្នកប្រើមិនស្គាល់"
911
+ admin_only: "សម្រាប់អ្នកគ្រប់គ្រងប៉ុណ្ណោះ"
912
+ paths:
913
+ one: "ផ្លូវ"
914
+ other: "ផ្លូវ (%{count})"
915
+ statuses:
916
+ queued: "កំពុងរង់ចាំ"
917
+ sent: "បានផ្ញើ"
918
+ skipped: "បានរំលង"
919
+ failed: "បរាជ័យ"
870
920
  draft_order:
871
921
  line_items_missing: "គ្មានទំនិញនៅក្នុងកន្ត្រកទេ"
872
922
  inventory_item:
data/config/routes.rb CHANGED
@@ -20,10 +20,8 @@ Spree::Core::Engine.add_routes do
20
20
  end
21
21
 
22
22
  namespace :admin do
23
- resources :api_caches, only: [] do
24
- collection do
25
- post :clear
26
- end
23
+ resource :api_cache, only: :show do
24
+ post :clear
27
25
  end
28
26
 
29
27
  get '/system', to: redirect('/admin/system/waiting_room')
@@ -375,12 +373,18 @@ Spree::Core::Engine.add_routes do
375
373
  collection do
376
374
  post :update_positions
377
375
  end
376
+
377
+ member do
378
+ delete :remove_app_background
379
+ delete :remove_web_background
380
+ end
378
381
  end
379
382
 
380
383
  resources :homepage_section_relatable do
381
384
  collection do
382
385
  get :options
383
386
  post :update_positions
387
+ post :sort_by_start_date
384
388
  end
385
389
  end
386
390
  end
@@ -0,0 +1,6 @@
1
+ class AddSectionTypeToCmHomepageSections < ActiveRecord::Migration[7.0]
2
+ def change
3
+ add_column :cm_homepage_sections, :section_type, :integer, default: 0, null: false
4
+ add_column :cm_homepage_sections, :font, :string
5
+ end
6
+ end
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.14.4'.freeze
2
+ VERSION = '2.14.6'.freeze
3
3
 
4
4
  module_function
5
5