Sha256: a7cd6927ef33313078017206ffdf733f65d4c144e179ea5d6298fb87b59a48e8
Contents?: true
Size: 1.25 KB
Versions: 7
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module Decidim module Votings # This class infers the current voting we are scoped to by # looking at the request parameters and the organization in the request # environment, and injects it into the environment. class CurrentVoting # Public: Matches the request against an voting and injects it # into the environment. # # request - The request that holds the voting relevant # information. # # Returns a true if the request matched, false otherwise def matches?(request) env = request.env @organization = env["decidim.current_organization"] return false unless @organization current_voting(env, request.params).present? end private def current_voting(env, params) env["decidim.current_participatory_space"] ||= detect_current_voting(params) end def detect_current_voting(params) organization_votings.where(slug: params["voting_slug"]).or( organization_votings.where(id: params["voting_slug"]) ).first! end def organization_votings @organization_votings ||= OrganizationVotings.new(@organization).query end end end end
Version data entries
7 entries across 7 versions & 1 rubygems