Sha256: 0ff1e2229e6e8127dbe338d9fa7a580ae0c2fc7ec2f1492e5526e9eae3077fb9

Contents?: true

Size: 773 Bytes

Versions: 49

Compression:

Stored size: 773 Bytes

Contents

# frozen_string_literal: true

module Decidim
  class Coauthorship < ApplicationRecord
    include Decidim::Authorable

    belongs_to :coauthorable, polymorphic: true, counter_cache: true

    validates :coauthorable, presence: true

    after_commit :author_is_follower, on: [:create]

    def identity
      user_group || author
    end

    private

    # As it is used to validate by comparing to author.organization
    # @returns The Organization for the Coauthorable
    def organization
      coauthorable&.organization
    end

    def author_is_follower
      return unless author.is_a?(Decidim::User)
      return unless coauthorable.is_a?(Decidim::Followable)

      Decidim::Follow.find_or_create_by!(followable: coauthorable, user: author)
    end
  end
end

Version data entries

49 entries across 49 versions & 1 rubygems

Version Path
decidim-core-0.26.10 app/models/decidim/coauthorship.rb
decidim-core-0.26.9 app/models/decidim/coauthorship.rb
decidim-core-0.26.8 app/models/decidim/coauthorship.rb
decidim-core-0.26.7 app/models/decidim/coauthorship.rb
decidim-core-0.26.5 app/models/decidim/coauthorship.rb
decidim-core-0.26.4 app/models/decidim/coauthorship.rb
decidim-core-0.26.3 app/models/decidim/coauthorship.rb
decidim-core-0.26.2 app/models/decidim/coauthorship.rb
decidim-core-0.26.1 app/models/decidim/coauthorship.rb
decidim-core-0.26.0 app/models/decidim/coauthorship.rb
decidim-core-0.26.0.rc2 app/models/decidim/coauthorship.rb
decidim-core-0.26.0.rc1 app/models/decidim/coauthorship.rb
decidim-core-0.25.2 app/models/decidim/coauthorship.rb
decidim-core-0.25.1 app/models/decidim/coauthorship.rb
decidim-core-0.25.0 app/models/decidim/coauthorship.rb
decidim-core-0.25.0.rc4 app/models/decidim/coauthorship.rb
decidim-core-0.25.0.rc3 app/models/decidim/coauthorship.rb
decidim-core-0.25.0.rc2 app/models/decidim/coauthorship.rb
decidim-core-0.25.0.rc1 app/models/decidim/coauthorship.rb
decidim-core-0.24.3 app/models/decidim/coauthorship.rb