Sha256: b8bffa6cda156f0bfb05e2438e732866880f45c50e7ea75e7316de1347898f9d

Contents?: true

Size: 852 Bytes

Versions: 17

Compression:

Stored size: 852 Bytes

Contents

# frozen_string_literal: true

module Decidim
  # Store user's social identities
  class Identity < ApplicationRecord
    include Decidim::DataPortability

    belongs_to :user, foreign_key: :decidim_user_id, class_name: "Decidim::User"
    belongs_to :organization, foreign_key: :decidim_organization_id, class_name: "Decidim::Organization"

    validates :provider, presence: true
    validates :uid, presence: true, uniqueness: { scope: [:provider, :organization] }

    validate :same_organization

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

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

    private

    def same_organization
      return if organization == user&.organization
      errors.add(:organization, :invalid)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
decidim-core-0.18.1 app/models/decidim/identity.rb
decidim-core-0.17.2 app/models/decidim/identity.rb
decidim-core-0.18.0 app/models/decidim/identity.rb
decidim-core-0.17.1 app/models/decidim/identity.rb
decidim-core-0.16.1 app/models/decidim/identity.rb
decidim-core-0.17.0 app/models/decidim/identity.rb
decidim-core-0.16.0 app/models/decidim/identity.rb
decidim-core-0.15.2 app/models/decidim/identity.rb
decidim-core-0.15.1 app/models/decidim/identity.rb
decidim-core-0.15.0 app/models/decidim/identity.rb
decidim-core-0.14.4 app/models/decidim/identity.rb
decidim-core-0.14.3 app/models/decidim/identity.rb
decidim-core-0.14.2 app/models/decidim/identity.rb
decidim-core-0.14.1 app/models/decidim/identity.rb
decidim-core-0.13.1 app/models/decidim/identity.rb
decidim-core-0.13.0 app/models/decidim/identity.rb
decidim-core-0.13.0.pre1 app/models/decidim/identity.rb