Sha256: ff6a20bc9a998420c67c27bcead1a0ea246201f7683a82bb5e62c0f171634f59

Contents?: true

Size: 1.05 KB

Versions: 18

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  # A concern with the features needed when you want a model to be able to create
  # private users
  module HasPrivateUsers
    extend ActiveSupport::Concern

    included do
      has_many :participatory_space_private_users, class_name: "Decidim::ParticipatorySpacePrivateUser", as: :privatable_to, dependent: :destroy
      has_many :users, through: :participatory_space_private_users, class_name: "Decidim::User", foreign_key: "private_user_to_id"

      scope :visible_for, lambda { |user|
                            joins("LEFT JOIN decidim_participatory_space_private_users ON
                            decidim_participatory_space_private_users.privatable_to_id = #{table_name}.id")
                              .where("(private_space = ? and decidim_participatory_space_private_users.decidim_user_id = ?) or private_space = ? ", true, user, false).distinct
                          }

      def self.public_spaces
        super.where(private_space: false)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
decidim-core-0.17.2 lib/decidim/has_private_users.rb
decidim-core-0.17.1 lib/decidim/has_private_users.rb
decidim-core-0.16.1 lib/decidim/has_private_users.rb
decidim-core-0.17.0 lib/decidim/has_private_users.rb
decidim-core-0.16.0 lib/decidim/has_private_users.rb
decidim-core-0.15.2 lib/decidim/has_private_users.rb
decidim-core-0.15.1 lib/decidim/has_private_users.rb
decidim-core-0.15.0 lib/decidim/has_private_users.rb
decidim-core-0.14.4 lib/decidim/has_private_users.rb
decidim-core-0.14.3 lib/decidim/has_private_users.rb
decidim-core-0.14.2 lib/decidim/has_private_users.rb
decidim-core-0.14.1 lib/decidim/has_private_users.rb
decidim-core-0.13.1 lib/decidim/has_private_users.rb
decidim-core-0.12.2 lib/decidim/has_private_users.rb
decidim-core-0.13.0 lib/decidim/has_private_users.rb
decidim-core-0.12.1 lib/decidim/has_private_users.rb
decidim-core-0.13.0.pre1 lib/decidim/has_private_users.rb
decidim-core-0.12.0 lib/decidim/has_private_users.rb