Sha256: f99a6b5be81a7dcafcf8c249fcd63729a698b1bf74834239ccdbd1bb8a1c132b

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

module Decidim
  module Admin
    # A class used to find the ParticipatoryProcesses that the given user can
    # manage.
    class ManageableParticipatoryProcessesForUser < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # user - a User that needs to find which processes can manage
      def self.for(user)
        new(user).query
      end

      # Initializes the class.
      #
      # user - a User that needs to find which processes can manage
      def initialize(user)
        @user = user
      end

      # Finds the ParticipatoryProcesses that the given user can manage.
      #
      # Returns an ActiveRecord::Relation.
      def query
        return user.organization.participatory_processes if user.role?(:admin) || user.role?(:collaborator)

        ParticipatoryProcess.where(id: process_ids)
      end

      private

      attr_reader :user

      def process_ids
        ParticipatoryProcessUserRole
          .where(user: user, role: :admin)
          .pluck(:decidim_participatory_process_id)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
decidim-admin-0.4.0 app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-0.4.0 decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-admin-0.3.2 app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-0.3.2 decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-admin-0.3.1 app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-0.3.1 decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-admin-0.3.0 app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-0.3.0 decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-admin-0.2.0 app/queries/decidim/admin/manageable_participatory_processes_for_user.rb
decidim-0.2.0 decidim-admin/app/queries/decidim/admin/manageable_participatory_processes_for_user.rb