Sha256: fa2d72054f7682555fa94a1f5e98ee8ee772132b5060dae93cc9fbf9c8d3a3e3

Contents?: true

Size: 1.56 KB

Versions: 48

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Decidim
  module Conferences
    # A class used to find the Conferences that the given user has
    # the specific role privilege.
    class ConferencesWithUserRole < Rectify::Query
      # Syntactic sugar to initialize the class and return the queried objects.
      #
      # user - a User that needs to find which conferences can manage
      # role - (optional) a Symbol to specify the role privilege
      def self.for(user, role = :any)
        new(user, role).query
      end

      # Initializes the class.
      #
      # user - a User that needs to find which conferences can manage
      # role - (optional) a Symbol to specify the role privilege
      def initialize(user, role = :any)
        @user = user
        @role = role
      end

      # Finds the Conferences that the given user has role privileges.
      # If the special role ':any' is provided it returns all conferences where
      # the user has some kind of role privilege.
      #
      # Returns an ActiveRecord::Relation.
      def query
        # Admin users have all role privileges for all organization conferences
        return Conferences::OrganizationConferences.new(user.organization).query if user.admin?

        Conference.where(id: conference_ids)
      end

      private

      attr_reader :user, :role

      def conference_ids
        user_roles = ConferenceUserRole.where(user: user) if role == :any
        user_roles = ConferenceUserRole.where(user: user, role: role) if role != :any
        user_roles.pluck(:decidim_conference_id)
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
decidim-conferences-0.23.6 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.24.2 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.5 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.24.1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.24.0 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.24.0.rc2 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.4 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.24.0.rc1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.3 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.2 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.1.rc1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.23.0 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.22.0 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.21.0 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.20.1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.20.0 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.19.1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.18.1 app/queries/decidim/conferences/conferences_with_user_role.rb
decidim-conferences-0.19.0 app/queries/decidim/conferences/conferences_with_user_role.rb