Sha256: e77bb45b261c60e39c9122bb8d496a91f0c93b9d99ebf2b5b936662b6f2a02c5

Contents?: true

Size: 728 Bytes

Versions: 12

Compression:

Stored size: 728 Bytes

Contents

# frozen_string_literal: true

module Decidim
  class Coauthorship < ApplicationRecord
    include Decidim::Authorable

    belongs_to :coauthorable, polymorphic: true, counter_cache: 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

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/models/decidim/coauthorship.rb
decidim-core-0.27.8 app/models/decidim/coauthorship.rb
decidim-core-0.27.7 app/models/decidim/coauthorship.rb
decidim-core-0.27.6 app/models/decidim/coauthorship.rb
decidim-core-0.27.5 app/models/decidim/coauthorship.rb
decidim-core-0.27.4 app/models/decidim/coauthorship.rb
decidim-core-0.27.3 app/models/decidim/coauthorship.rb
decidim-core-0.27.2 app/models/decidim/coauthorship.rb
decidim-core-0.27.1 app/models/decidim/coauthorship.rb
decidim-core-0.27.0 app/models/decidim/coauthorship.rb
decidim-core-0.27.0.rc2 app/models/decidim/coauthorship.rb
decidim-core-0.27.0.rc1 app/models/decidim/coauthorship.rb