spree_cm_commissioner 2.8.2.pre.pre.6 → 2.8.2.pre.pre.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d27d1bbb2542f8c7f2ab1b23e228b657018a3d3444303382ddf5ab812735a409
4
- data.tar.gz: bbeb67c0cc2f372ae6fc10b3dc117c8406fcb1a04c49f450db512e733fecd327
3
+ metadata.gz: 5ef384b13b8b23bbd46aa3c9f8f99e8b7b88e9cd78bcf31e44f74534f60b9a8c
4
+ data.tar.gz: 27796cce088d3db3a9ff09332236705ae3430d4f4065b2d3fdede50016987c41
5
5
  SHA512:
6
- metadata.gz: 9bbdffa2c63368a6f60736a726909780585eeffaaedcf8937500112e3bad8528a6c64b1738be07e3b50e20a9c41ed097de44d2488c0b1dd795cd59513e38d330
7
- data.tar.gz: 8c3b7541de536b0156868f5f383d54397817f8cba0455778dec2d6600396529e1c54c4888c3c5834044488322088d9d21d2e4b8b80f6f6dd68e9a1bee6bf7bc7
6
+ metadata.gz: 7a565f861ce630f95e7422771a5e2188084ad4f52fe7f62c62d229b63904a1a03496429aa728a02eef5eb21f26a733899dde2d320cd575c0156fa99892900648
7
+ data.tar.gz: bfcd0620eb133c51d7ca6f9c55b72aff078955b7d27dbd96a5f08c9090cc4ea04812e6eb0df086b377789f80405eae142d4e2ffa44a0187cc76dd74f1a1c2999
data/Gemfile.lock CHANGED
@@ -34,7 +34,7 @@ GIT
34
34
  PATH
35
35
  remote: .
36
36
  specs:
37
- spree_cm_commissioner (2.8.2.pre.pre.6)
37
+ spree_cm_commissioner (2.8.2.pre.pre.8)
38
38
  activerecord-multi-tenant
39
39
  activerecord_json_validator (~> 2.1, >= 2.1.3)
40
40
  aws-sdk-cloudfront
@@ -6,6 +6,7 @@ module SpreeCmCommissioner
6
6
  belongs_to :vendor, class_name: 'Spree::Vendor', optional: false
7
7
  belongs_to :show, class_name: 'SpreeCmCommissioner::Show', optional: false
8
8
  belongs_to :episode, class_name: 'Spree::Product', optional: false
9
+ belongs_to :parent, class_name: 'SpreeCmCommissioner::VotingSession', optional: true
9
10
 
10
11
  has_one :season, through: :episode, class_name: 'SpreeCmCommissioner::Show', source: :season
11
12
 
@@ -30,10 +31,13 @@ module SpreeCmCommissioner
30
31
  validates :session_key, presence: true, uniqueness: true
31
32
  validates :name, :opens_at, :closes_at, :status, presence: true
32
33
  validate :closes_after_opens
34
+ validate :closes_at_not_after_parent
33
35
  validate :validate_live_stream_url, if: :live_stream_url_changed?
34
36
 
35
37
  before_validation :generate_session_key, on: :create
36
38
  before_save :update_live_stream_thumbnail
39
+ after_create :copy_contestants_from_parent, if: -> { pre_vote? && parent.present? }
40
+ after_update :copy_contestants_from_parent, if: -> { pre_vote? && saved_change_to_parent_id? && parent.present? }
37
41
  after_update :schedule_counter_reconciliation, if: -> { saved_change_to_status?(from: 'enabled', to: 'closed') }
38
42
  # Scopes
39
43
  # Uses the database clock (CURRENT_TIMESTAMP) for consistency and to avoid application server clock drift.
@@ -210,12 +214,28 @@ module SpreeCmCommissioner
210
214
  self.session_key ||= "#{episode.slug}-#{Time.current.to_i}-#{SecureRandom.hex(8)}"
211
215
  end
212
216
 
217
+ def copy_contestants_from_parent
218
+ parent.voting_contestants.find_each do |vc|
219
+ voting_contestants.find_or_create_by!(show_contestant: vc.show_contestant) do |new_vc|
220
+ new_vc.show_id = show_id
221
+ end
222
+ end
223
+ end
224
+
213
225
  def closes_after_opens
214
226
  return unless opens_at && closes_at
215
227
 
216
228
  errors.add(:closes_at, 'must be after opens_at') if closes_at <= opens_at
217
229
  end
218
230
 
231
+ def closes_at_not_after_parent
232
+ return unless parent && closes_at && parent.closes_at
233
+
234
+ return unless closes_at > parent.closes_at
235
+
236
+ errors.add(:closes_at, 'cannot be after parent session closes_at')
237
+ end
238
+
219
239
  def parse_json_config(value)
220
240
  return {} if value.nil? || value == ''
221
241
  return value if value.is_a?(Hash)
@@ -2,8 +2,8 @@ module Spree
2
2
  module V2
3
3
  module Tenant
4
4
  class VotingSessionSerializer < BaseSerializer
5
- attributes :opens_at, :closes_at, :status, :session_type, :name, :public_metadata,
6
- :live_stream_enabled, :live_stream_thumbnail, :live_stream_title, :live_stream_description,
5
+ attributes :opens_at, :closes_at, :status, :session_type, :live_stream_enabled,
6
+ :live_stream_thumbnail, :live_stream_title, :live_stream_description,
7
7
  :position
8
8
 
9
9
  attribute :live_stream_url, &:embedded_live_stream_url
@@ -1,8 +1,9 @@
1
1
  class AddCombiningParentToCmVotingSessions < ActiveRecord::Migration[7.0]
2
2
  def change
3
- add_reference :cm_voting_sessions, :combining_parent,
3
+ add_reference :cm_voting_sessions, :parent,
4
4
  foreign_key: { to_table: :cm_voting_sessions },
5
5
  null: true,
6
- index: true
6
+ index: true,
7
+ if_not_exists: true
7
8
  end
8
9
  end
@@ -1,5 +1,5 @@
1
1
  module SpreeCmCommissioner
2
- VERSION = '2.8.2.pre.pre.6'.freeze
2
+ VERSION = '2.8.2.pre.pre.8'.freeze
3
3
 
4
4
  module_function
5
5
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_cm_commissioner
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.2.pre.pre.6
4
+ version: 2.8.2.pre.pre.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - You