Sha256: 2bff4b30a7d5ef554b08754848bfc92cec5645226fa17fb4841672111b4320c5

Contents?: true

Size: 1.05 KB

Versions: 27

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Decidim
  # This class gives a given User access to a given private ParticipatorySpacePrivateUser
  class ParticipatorySpacePrivateUser < ApplicationRecord
    include Decidim::DataPortability

    belongs_to :user, class_name: "Decidim::User", foreign_key: :decidim_user_id
    belongs_to :privatable_to, polymorphic: true

    validate :user_and_participatory_space_same_organization

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

    def self.export_serializer
      Decidim::DataPortabilitySerializers::DataPortabilityParticipatorySpacePrivateUserSerializer
    end

    def self.log_presenter_class_for(_log)
      Decidim::AdminLog::ParticipatorySpacePrivateUserPresenter
    end

    private

    # Private: check if the participatory space and the user have the same organization
    def user_and_participatory_space_same_organization
      return if !privatable_to || !user

      errors.add(:privatable_to, :invalid) unless user.organization == privatable_to.organization
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
decidim-core-0.25.2 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.25.1 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.25.0 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.25.0.rc4 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.25.0.rc3 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.25.0.rc2 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.25.0.rc1 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.24.3 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.6 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.24.2 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.5 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.24.1 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.24.0 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.24.0.rc2 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.4 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.24.0.rc1 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.3 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.2 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.1 app/models/decidim/participatory_space_private_user.rb
decidim-core-0.23.1.rc1 app/models/decidim/participatory_space_private_user.rb