-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
50 changed files
with
986 additions
and
928 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/controllers/concerns/decidim/budgeting_pipeline/authorizable.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module BudgetingPipeline | ||
module Authorizable | ||
extend ActiveSupport::Concern | ||
|
||
# This ensures that only people eligible to vote can enter the voting | ||
# pipeline after the authorization step. The authorization conditions | ||
# should be used to control user's ability to vote (e.g. where they live, | ||
# how old they are, etc.). | ||
def user_authorized? | ||
@user_authorized ||= user_signed_in? && action_authorized_to("vote").ok? | ||
end | ||
|
||
def authorization_required? | ||
@authorization_required ||= begin | ||
permission = current_component.permissions&.fetch("vote", nil) | ||
handlers = permission&.fetch("authorization_handlers", nil)&.keys | ||
if handlers && handlers.any? | ||
providers = Decidim::BudgetingPipeline.authorization_providers | ||
providers = providers.call(current_organization) if providers.respond_to?(:call) | ||
(handlers & providers).any? | ||
else | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/helpers/decidim/budgeting_pipeline/authorization_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
module Decidim | ||
module BudgetingPipeline | ||
module AuthorizationHelper | ||
include Decidim::BudgetingPipeline::ProjectsHelperExtensions | ||
include Decidim::BudgetingPipeline::ProjectItemUtilities | ||
include Decidim::BudgetingPipeline::TextUtilities | ||
|
||
def available_authorization_provider_keys | ||
providers = Decidim::BudgetingPipeline.authorization_providers | ||
providers = providers.call(current_organization) if providers.respond_to?(:call) | ||
providers | ||
end | ||
|
||
def authorization_providers | ||
Verifications::Adapter.from_collection( | ||
available_authorization_provider_keys - user_authorizations.pluck(:name) | ||
) | ||
end | ||
|
||
def user_authorizations(type = :all) | ||
base = Decidim::Authorization.where( | ||
name: available_authorization_provider_keys, | ||
user: current_user | ||
) | ||
return base.where.not(granted_at: nil) if type == :granted | ||
return base.where(granted_at: nil) if type == :pending | ||
|
||
base | ||
end | ||
|
||
def authorization_provider_name(provider) | ||
Decidim::BudgetingPipeline.authorization_provider_name.call(provider) | ||
end | ||
|
||
def invalid_authorization_title | ||
translated_attribute(component_settings.vote_identify_invalid_authorization_title) | ||
end | ||
|
||
def invalid_authorization_content | ||
translated_attribute(component_settings.vote_identify_invalid_authorization_content) | ||
end | ||
|
||
# This is for the projects view that displays the project filters that | ||
# refers the `budgets` variable. | ||
def budgets | ||
selected_budgets | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.