diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml
index f27f714b2db82..7f288c9d0d6de 100644
--- a/config/i18n-tasks.yml
+++ b/config/i18n-tasks.yml
@@ -320,6 +320,7 @@ ignore_unused:
- decidim.assemblies.admin.assembly_members.form.explanation
- decidim.assemblies.admin.assembly_members.form.image_guide
- decidim.assemblies.admin.assembly_members.form.non_user_avatar_help
+ - decidim.initiatives.create_initiative.select_initiative_type.*
- decidim.blogs.admin_log.*
- decidim.templates.admin_log.*
- decidim.forms.upload_help.explanation
diff --git a/decidim-initiatives/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb b/decidim-initiatives/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb
new file mode 100644
index 0000000000000..8a722d0ccf190
--- /dev/null
+++ b/decidim-initiatives/app/controllers/decidim/initiatives/authorization_create_modals_controller.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+module Decidim
+ module Initiatives
+ class AuthorizationCreateModalsController < Decidim::Initiatives::ApplicationController
+ helper_method :authorizations, :authorize_action_path
+ layout false
+
+ def show
+ @initiative_type = Decidim::InitiativesType.find_by(id: params[:slug])
+ render template: "decidim/authorization_modals/show"
+ end
+
+ private
+
+ def authorize_action_path(handler_name)
+ authorizations.status_for(handler_name).current_path(redirect_url: URI(request.referer).path)
+ end
+
+ def authorizations
+ @authorizations ||= action_authorized_to("create", permissions_holder: @initiative_type)
+ end
+ end
+ end
+end
diff --git a/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb b/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb
index 1804347a681c7..809753fe5b3ef 100644
--- a/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb
+++ b/decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb
@@ -37,12 +37,11 @@ class CreateInitiativeController < Decidim::Initiatives::ApplicationController
before_action :ensure_type_exists, only: :show
def show
- enforce_permission_to :create, :initiative
send("#{step}_step", initiative: session_initiative)
end
def update
- enforce_permission_to :create, :initiative
+ enforce_permission_to :create, :initiative, { initiative_type: initiative_type_from_params }
send("#{step}_step", params)
end
@@ -72,6 +71,9 @@ def select_initiative_type_step(_parameters)
def previous_form_step(parameters)
@form = build_form(Decidim::Initiatives::PreviousForm, parameters)
+
+ enforce_permission_to :create, :initiative, { initiative_type: initiative_type }
+
render_wizard
end
@@ -170,6 +172,10 @@ def initiative_type
@initiative_type ||= InitiativesType.where(organization: current_organization).find_by(id: initiative_type_id)
end
+ def initiative_type_from_params
+ Decidim::InitiativesType.find_by(id: params["initiative"]["type_id"])
+ end
+
def initiative_type_id
session_initiative[:type_id] || @form&.type_id
end
diff --git a/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb b/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb
index 230836dae0c37..74cf52a246171 100644
--- a/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb
+++ b/decidim-initiatives/app/controllers/decidim/initiatives/initiatives_controller.rb
@@ -30,7 +30,7 @@ class InitiativesController < Decidim::Initiatives::ApplicationController
include SingleInitiativeType
helper_method :collection, :initiatives, :filter, :stats
- helper_method :initiative_type
+ helper_method :initiative_type, :available_initiative_types
# GET /initiatives
def index
diff --git a/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb b/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb
index 75357b1f67e52..805da0cbee3f9 100644
--- a/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb
+++ b/decidim-initiatives/app/helpers/decidim/initiatives/initiative_helper.rb
@@ -85,6 +85,26 @@ def popularity_level5?(initiative)
initiative.percentage >= 100
end
+ def authorized_create_modal_button(type, html_options, &block)
+ tag = "button"
+ html_options ||= {}
+
+ if current_user
+ if action_authorized_to("create", permissions_holder: type).ok?
+ html_options["data-open"] = "not-authorized-modal"
+ else
+ html_options["data-open"] = "authorizationModal"
+ html_options["data-open-url"] = authorization_create_modal_initiative_path(type)
+ end
+ else
+ html_options["data-open"] = "loginModal"
+ end
+
+ html_options["onclick"] = "event.preventDefault();"
+
+ send("#{tag}_to", "", html_options, &block)
+ end
+
def authorized_vote_modal_button(initiative, html_options, &block)
return if current_user && action_authorized_to("vote", resource: initiative, permissions_holder: initiative.type).ok?
diff --git a/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb b/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb
index 429c31d06ce69..6c0bc65ab0f6f 100644
--- a/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb
+++ b/decidim-initiatives/app/permissions/decidim/initiatives/permissions.rb
@@ -88,9 +88,9 @@ def update_public_initiative?
def creation_enabled?
Decidim::Initiatives.creation_enabled && (
Decidim::Initiatives.do_not_require_authorization ||
- UserAuthorizations.for(user).any? ||
- Decidim::UserGroups::ManageableUserGroups.for(user).verified.any?
- )
+ UserAuthorizations.for(user).any? ||
+ Decidim::UserGroups::ManageableUserGroups.for(user).verified.any?) &&
+ authorized?(:create, permissions_holder: initiative_type)
end
def request_membership?
diff --git a/decidim-initiatives/app/views/decidim/initiatives/_modal.html.erb b/decidim-initiatives/app/views/decidim/initiatives/_modal.html.erb
new file mode 100644
index 0000000000000..d171a48863e65
--- /dev/null
+++ b/decidim-initiatives/app/views/decidim/initiatives/_modal.html.erb
@@ -0,0 +1,19 @@
+
+
+
+
+
+ <%= t(".not_authorized.explanation") %>
+
+
+
+
+
diff --git a/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb b/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb
index dba0adbb7c5c5..28c47b0350a2c 100644
--- a/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb
+++ b/decidim-initiatives/app/views/decidim/initiatives/create_initiative/select_initiative_type.html.erb
@@ -39,9 +39,15 @@
<%= raw translated_attribute type.description %>
- <%= decidim_form_for(@form, url: next_wizard_path, method: :put, html: { id: "new_initiative_#{type.id}", class: "form select-initiative_type-form" }) do |f| %>
- <%= f.hidden_field :type_id, value: type.id, id: "initiative_type_id_#{ type.id }" %>
- <%= f.submit t(".select"), class: "button" %>
+ <% if allowed_to?(:create, :initiative, { initiative_type: type }) %>
+ <%= decidim_form_for(@form, url: next_wizard_path, method: :put, html: { id: "new_initiative_#{type.id}", class: "form select-initiative_type-form" }) do |f| %>
+ <%= f.hidden_field :type_id, value: type.id, id: "initiative_type_id_#{ type.id }" %>
+ <%= f.submit t(".select"), class: "button" %>
+ <% end %>
+ <% else %>
+ <%= authorized_create_modal_button(type, remote: true, class: "button") do %>
+ <%= t(".verification_required") %>
+ <% end %>
<% end %>
<% end %>
@@ -51,3 +57,4 @@
+<%= render partial: "decidim/initiatives/modal" %>
diff --git a/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb b/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb
index 13fdcef667b34..6fba4f4c85ef0 100644
--- a/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb
+++ b/decidim-initiatives/app/views/decidim/initiatives/initiatives/_index_header.html.erb
@@ -3,16 +3,23 @@
<%= render partial: "count" %>
<% if Decidim::Initiatives.creation_enabled %>
- <% if current_user && allowed_to?(:create, :initiative) %>
+ <% if current_user && available_initiative_types.size > 1 %>
<%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small" do %>
<%= t(".new_initiative") %>
<%= icon "plus", role: "img", "aria-hidden": true %>
<% end %>
<% elsif current_user %>
-
+ <% if allowed_to?(:create, :initiative, { initiative_type: available_initiative_types.first }) %>
+ <%= link_to create_initiative_path(:select_initiative_type), class: "title-action__action button small" do %>
+ <%= t(".new_initiative") %>
+ <%= icon "plus", role: "img", "aria-hidden": true %>
+ <% end %>
+ <% else %>
+ <%= authorized_create_modal_button(available_initiative_types.first, remote: true, class: "title-action__action button small") do %>
+ <%= icon "plus", role: "img", "aria-hidden": true %>
+ <%= t(".new_initiative") %>
+ <% end %>
+ <% end %>
<% else %>
<% content_for(:redirect_after_login) { create_initiative_url(:select_initiative_type) } %>