Sha256: f976e328e39f92d14606143dad9513d7ce7e1587282494a6891d342abc1ac5f8

Contents?: true

Size: 1.22 KB

Versions: 12

Compression:

Stored size: 1.22 KB

Contents

# frozen_string_literal: true

module Decidim
  module Meetings
    # The data store for a Registration in the Decidim::Meetings component.
    class Registration < Meetings::ApplicationRecord
      include Decidim::DataPortability

      belongs_to :meeting, foreign_key: "decidim_meeting_id", class_name: "Decidim::Meetings::Meeting"
      belongs_to :user, foreign_key: "decidim_user_id", class_name: "Decidim::User"

      validates :user, uniqueness: { scope: :meeting }
      validates :code, uniqueness: { allow_blank: true, scope: :meeting }
      validates :code, presence: true, on: :create

      before_validation :generate_code, on: :create

      def self.user_collection(user)
        where(decidim_user_id: user.id)
      end

      def self.export_serializer
        Decidim::Meetings::DataPortabilityRegistrationSerializer
      end

      private

      def generate_code
        self[:code] ||= calculate_registration_code
      end

      # Calculates a unique code for the model using the class
      # provided by the configuration and scoped to the meeting.
      #
      # Returns a String.
      def calculate_registration_code
        Decidim::Meetings::Registrations.code_generator.generate(self)
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-meetings-0.17.2 app/models/decidim/meetings/registration.rb
decidim-meetings-0.17.1 app/models/decidim/meetings/registration.rb
decidim-meetings-0.16.1 app/models/decidim/meetings/registration.rb
decidim-meetings-0.17.0 app/models/decidim/meetings/registration.rb
decidim-meetings-0.16.0 app/models/decidim/meetings/registration.rb
decidim-meetings-0.15.2 app/models/decidim/meetings/registration.rb
decidim-meetings-0.15.1 app/models/decidim/meetings/registration.rb
decidim-meetings-0.15.0 app/models/decidim/meetings/registration.rb
decidim-meetings-0.14.4 app/models/decidim/meetings/registration.rb
decidim-meetings-0.14.3 app/models/decidim/meetings/registration.rb
decidim-meetings-0.14.2 app/models/decidim/meetings/registration.rb
decidim-meetings-0.14.1 app/models/decidim/meetings/registration.rb