Skip to content

Commit

Permalink
Improve registration and verification flow (decidim#13295)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandru Emil Lupu <[email protected]>
Co-authored-by: Maxim Colls <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent ea44d41 commit 74701b1
Show file tree
Hide file tree
Showing 87 changed files with 1,564 additions and 413 deletions.
7 changes: 3 additions & 4 deletions decidim-admin/spec/shared/manage_impersonations_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,9 @@
context "and the action not allowed by the handler used to impersonate", :slow do
let(:authorization_handler) { "another_dummy_authorization_handler" }

it "shows popup to require verification" do
expect(page).to have_content(
/In order to perform this action, you need to be authorized with "Another example authorization"/
)
it "redirects to the authorization form" do
expect(page).to have_content("We need to verify your identity")
expect(page).to have_content("Verify with Another example authorization")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
budget_order_line_item_path(model.budget, project_id: model, show_only_added: options[:show_only_added]),
method: vote_button_method,
remote: true,
class: "button w-full #{vote_button_classes}",
resource: model,
class: "button #{vote_button_classes}",
id: "project-vote-button-#{model.id}",
data: {
add: !resource_added?,
disable: true,
budget: model.budget_amount,
allocation: resource_allocation,
"redirect-url": resource_path
"redirect-url": resource_path,
onboarding_redirect_path: resource_index_path
},
disabled: vote_button_disabled?,
title: vote_button_label do %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def resource_path
resource_locator([model.budget, model]).path
end

def resource_index_path
resource_locator(model.budget).path
end

def resource_title
translated_attribute model.title
end
Expand Down
55 changes: 42 additions & 13 deletions decidim-budgets/spec/system/orders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include_context "with a component"
let(:manifest_name) { "budgets" }

let(:organization) { create(:organization, available_authorizations: %w(dummy_authorization_handler)) }
let(:organization) { create(:organization, available_authorizations: %w(dummy_authorization_handler another_dummy_authorization_handler)) }
let!(:user) { create(:user, :confirmed, organization:) }
let(:project) { projects.first }

Expand Down Expand Up @@ -247,26 +247,55 @@
end

context "and is not authorized" do
before do
permissions = {
vote: {
authorization_handlers: {
"dummy_authorization_handler" => {}
context "when there is only an authorization required" do
before do
permissions = {
vote: {
authorization_handlers: {
"dummy_authorization_handler" => {}
}
}
}
}

component.update!(permissions:)
component.update!(permissions:)
end

it "redirects to the authorization form" do
visit_budget

within "#project-#{project.id}-item" do
page.find(".budget-list__action").click
end

expect(page).to have_content("We need to verify your identity")
expect(page).to have_content("Verify with Example authorization")
end
end

it "shows a modal dialog" do
visit_budget
context "when there are more than one authorization required" do
before do
permissions = {
vote: {
authorization_handlers: {
"dummy_authorization_handler" => {},
"another_dummy_authorization_handler" => { "options" => {} }
}
}
}

within "#project-#{project.id}-item" do
page.find(".budget-list__action").click
component.update!(permissions:)
end

expect(page).to have_content("Authorization required")
it "redirects to pending onboarding authorizations page" do
visit_budget

within "#project-#{project.id}-item" do
page.find(".budget-list__action").click
end

expect(page).to have_content("You are almost ready to vote")
expect(page).to have_css("a[data-verification]", count: 2)
end
end
end

Expand Down
4 changes: 4 additions & 0 deletions decidim-comments/app/cells/decidim/comments/comment_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ def vote_button_to(path, params, &)

action_authorized_button_to(:vote_comment, path, params.merge(resource: root_commentable), &)
end

def decidim_verifications
Decidim::Verifications::Engine.routes.url_helpers
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
<%== cell("decidim/comments/comment_form", model, root_depth:) %>
<% else %>
<p>
<span>
<%== t(
"decidim.components.add_comment_form.account_message",
sign_in_url: decidim.new_user_session_path,
sign_up_url: decidim.new_user_registration_path
) %>
</span>
<div class="flash flex-col warning">
<div class="flash__message">
<%= action_authorized_link_to("comment", t("decidim.components.add_comment_form.account_message"), "#", **onboarding_action_params) %>
</div>
</div>
</p>
<% end %>
</div>
22 changes: 16 additions & 6 deletions decidim-comments/app/cells/decidim/comments/comments_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,16 +150,26 @@ def current_participatory_space
model.try(:participatory_space)
end

def onboarding_action_params
params = if model.try(:component).present? || current_component.present?
{ resource: model }
else
{ resource: model, permissions_holder: model }
end
return params if ResourceLocatorPresenter.new(model).url
rescue NoMethodError
params.merge!(data: { onboarding_redirect_path: request.path })
end

def blocked_comments_for_unauthorized_user_warning_link
options = if current_component.present?
{ resource: model }
else
{ resource: model, permissions_holder: model }
end
action_authorized_link_to(:comment, commentable_path, options) do
action_authorized_link_to(:comment, commentable_path, onboarding_action_params) do
t("decidim.components.comments.blocked_comments_for_unauthorized_user_warning")
end
end

def decidim_verifications
Decidim::Verifications::Engine.routes.url_helpers
end
end
end
end
8 changes: 3 additions & 5 deletions decidim-comments/app/packs/stylesheets/comments.scss
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,8 @@
@apply mr-2;
}

.button_to:first-child,
button:first-child,
button:nth-child(2),
.button_to:nth-child(2) {
> :first-child,
> :nth-child(2) {
svg:first-child {
@apply block;
}
Expand Down Expand Up @@ -161,7 +159,7 @@
}
}

.button_to:nth-child(2) {
> :nth-child(2) {
svg:first-child {
@apply block;
}
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ ca:
error: S'ha produït un error en votar el comentari.
components:
add_comment_form:
account_message: <a href="%{sign_in_url}">Inicia sessió</a> o <a href="%{sign_up_url}">crea un compte</a> per afegir el teu comentari.
account_message: Inicia sessió o crea un compte per afegir el teu comentari.
form:
body:
label: Comentari
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ en:
error: There was a problem voting the comment.
components:
add_comment_form:
account_message: <a href="%{sign_in_url}">Log in</a> or <a href="%{sign_up_url}">create an account</a> to add your comment.
account_message: Log in or create an account to add your comment.
form:
body:
label: Comment
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ es:
error: Se ha producido un error al votar el comentario.
components:
add_comment_form:
account_message: <a href="%{sign_in_url}">Inicia sesión</a> o <a href="%{sign_up_url}">crea una cuenta</a> para añadir tu comentario.
account_message: Inicia sesión o crea una cuenta para añadir tu comentario.
form:
body:
label: Comentario
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ module Decidim::Comments
end

it "renders an action_authorized button" do
expect(subject).to have_css("[data-dialog-open=\"authorizationModal\"]")
expect(subject).to have_css("[data-onboarding-action=\"vote_comment\"]")
end
end

context "when commentable has no permissions set for the vote_comment action" do
it "renders a plain button" do
expect(subject).to have_no_css("[data-dialog-open=\"authorizationModal\"]")
expect(subject).to have_no_css("[data-onboarding-action=\"vote_comment\"]")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<%= action_authorized_link_to :amend,
promote_amend_path,
method: :post,
resource: emendation,
data: { confirm: promote_confirm_text },
title: promote_amend_button_label,
class: "button button__sm button__transparent-secondary" do %>
<span><%= promote_amend_button_label %></span>
<%= icon "pencil-line" %>
Expand Down
3 changes: 1 addition & 2 deletions decidim-core/app/cells/decidim/follow_button/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<%= render :content %>
<% end %>
<% else %>
<%= action_authorized_button_to(
:follow,
<%= logged_button_to(
path,
resource: model,
class: button_classes,
Expand Down
5 changes: 5 additions & 0 deletions decidim-core/app/cells/decidim/follow_button_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ def id_option

private

# This method is required by action_authorized_button_to
def current_component
controller.try(:current_component)
end

def button_classes
options[:button_classes] || "button button__sm button__text-secondary only:m-auto"
end
Expand Down
15 changes: 15 additions & 0 deletions decidim-core/app/cells/decidim/onboarding_action_message/show.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div id="onboarding-messages-container" class="container">
<div class="flash info" data-closable>
<div class="flash__icon">
<%= info_icon %>
</div>

<div class="flash__message">
<%= message_text %>
</div>

<%= button_to decidim_verifications.clear_onboarding_data_authorizations_path, form_class: "close-button", role: :button, method: :delete, remote: true, data: { close: "" } do %>
<%= close_icon %>
<% end %>
</div>
</div>
76 changes: 76 additions & 0 deletions decidim-core/app/cells/decidim/onboarding_action_message_cell.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# frozen_string_literal: true

module Decidim
# This cell renders an announcement of pending onboarding action
# if exists for a user
#
# The `model` is expected to be a user
#
class OnboardingActionMessageCell < Decidim::ViewModel
include ActiveLinkTo

alias user model

def show
return if is_active_link?(onboarding_path)
return unless onboarding_manager.valid?
return unless onboarding_manager.pending_action?
return if authorization_status == :unauthorized
return if pending_authorization_link_active?

render :show
end

private

def onboarding_path
decidim_verifications.onboarding_pending_authorizations_path
end

def onboarding_manager
@onboarding_manager ||= OnboardingManager.new(user)
end

def authorizations
@authorizations ||= action_authorized_to(onboarding_manager.action, **onboarding_manager.action_authorized_resources)
end

def authorization_status
@authorization_status ||= authorizations.global_code
end

def pending_authorization_link_active?
return unless authorizations.single_authorization_required?

is_active_link? authorizations.statuses.first.current_path
end

def message_text
t(
"cta_html",
scope: "decidim.onboarding_action_message",
link_text:,
path: onboarding_path,
action: onboarding_manager.action_text.downcase,
resource_name: onboarding_manager.model_name.human.downcase,
resource_title: decidim_sanitize_translated(onboarding_manager.model_title)
)
end

def link_text
if onboarding_manager.finished_verifications?
t("click_link", scope: "decidim.onboarding_action_message")
else
t("finish_authorization_process", scope: "decidim.onboarding_action_message")
end
end

def info_icon
icon("information-line")
end

def close_icon
icon("close-line")
end
end
end
Loading

0 comments on commit 74701b1

Please sign in to comment.