Skip to content

Commit

Permalink
Merge branch 'feature/half_signup_and_budgets_booth' into fix/sign-in…
Browse files Browse the repository at this point in the history
…-link-if-disabled
  • Loading branch information
AyakorK committed Dec 3, 2024
2 parents ebad29f + 5bee2b5 commit c2cfdd9
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def initialize(auth_settings, form)

def call
return broadcast(:invalid) if form.invalid?
return broadcast(:sms_service_not_configured) if form.enable_partial_sms_signup && !sms_gateway_service_configured?

update_auth_settings
broadcast(:ok)
Expand All @@ -26,6 +27,10 @@ def call

attr_reader :form

def sms_gateway_service_configured?
Decidim.config.sms_gateway_service.present?
end

def update_auth_settings
Decidim.traceability.update!(
@auth_settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def update
flash.now[:alert] = I18n.t("organization.update.error", scope: "decidim.admin")
render :edit
end

on(:sms_service_not_configured) do
flash[:alert] = I18n.t("sms_gateway_service_not_defined", scope: "decidim.half_signup.admin.auth_settings")
redirect_to action: :edit
end
end
end
end
Expand Down
11 changes: 10 additions & 1 deletion app/views/decidim/half_signup/admin/auth_settings/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<div class="wrapper">
<div class="row">
<div class="field">
<%= form.check_box :enable_partial_sms_signup, help_text: t("help_text", scope:"decidim.half_signup.admin.auth_settings.sms") %>
<% if Decidim.config.sms_gateway_service.nil? %>
<div class="help-text">
<%= form.check_box :enable_partial_sms_signup, disabled: true %>
</div>
<div class="text-alert help-text">
<%= t("help_text", scope:"decidim.half_signup.admin.auth_settings.sms_disabled") %>
</div>
<% else %>
<%= form.check_box :enable_partial_sms_signup, help_text: t("help_text", scope:"decidim.half_signup.admin.auth_settings.sms") %>
<% end %>
</div>
<br/>
<div class="field">
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ en:
sms:
help_text: This option allows users to sign up and sign in to the platform
using their email address by receiving a verification code by SMS.
sms_disabled:
help_text: This option is disabled please contact the host of the platform
to enable it.
sms_gateway_service_not_defined: The SMS gateway service is not defined.
title: Settings available through code
menu:
auth_settings: Authentication settings
Expand Down
5 changes: 5 additions & 0 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ fr:
help_text: Cette option permet aux utilisateurs de s'inscrire et de se
connecter à la plateforme en utilisant leur adresse e-mail en recevant
un code de vérification par SMS.
sms_disabled:
help_text: Cette option est désactivée, veuillez contacter l'hôte de
la plateforme pour l'activer.
sms_gateway_service_not_defined: Le service de passerelle SMS n'est pas
défini.
title: Paramètres disponibles via le code
menu:
auth_settings: Paramètres d'authentification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
)
end
let(:command) { described_class.new(auth_settings, form) }
let(:sms_gateway_service) { instance_double(Decidim::Verifications::Sms::ExampleGateway, present?: true) }

before do
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

describe "#call" do
subject { command.call }
Expand Down Expand Up @@ -48,5 +57,13 @@
expect(subject).to broadcast(:invalid)
end
end

context "when the sms gateway is not defined" do
let(:sms_gateway_service) { nil }

it "broadcasts :sms_service_not_configured" do
expect(subject).to broadcast(:sms_service_not_configured)
end
end
end
end
9 changes: 9 additions & 0 deletions spec/commands/decidim/half_signup/send_verification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
let(:valid) { true }
let(:phone_number) { nil }
let(:phone_country) { nil }
let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" }
let(:form) do
double(
valid?: valid,
Expand All @@ -27,6 +28,14 @@

before do
allow(SecureRandom).to receive(:random_number).and_return(verification)

Decidim.configure do |config|
config.sms_gateway_service = sms_gateway_service
end
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

describe "when email" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
let(:attempts) { 0 }
let!(:correct_code) { "correct code" }
let!(:wrong_code) { "wrong code" }
let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" }
let(:auth_session) do
{
"code" => "correct code",
Expand All @@ -34,6 +35,12 @@
request.env["decidim.current_organization"] = organization
request.env["devise.mapping"] = ::Devise.mappings[:user]
request.session[:auth_attempt] = auth_session

allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

describe "GET #sms" do
Expand Down
7 changes: 7 additions & 0 deletions spec/system/add_update_phone_number_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
let(:user) { create(:user, :confirmed, organization: organization) }
let!(:auth_settings) { create(:auth_setting, organization: organization) }
let(:decidim_half_signup_admin) { Decidim::HalfSignup::AdminEngine.routes.url_helpers }
let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" }
let(:phone) { "4578878784" }

before do
sign_in user
switch_to_host(organization.host)
visit decidim.account_path

allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

context "when sms_auth is not enabled" do
Expand Down
54 changes: 54 additions & 0 deletions spec/system/admin_manage_auth_settings_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@
let(:admin) { create(:user, :admin, :confirmed, organization: organization) }
let(:auth_settings) { create(:auth_setting, organization: organization) }
let(:decidim_half_signup_admin) { Decidim::HalfSignup::AdminEngine.routes.url_helpers }
let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" }

before do
sign_in admin
switch_to_host(organization.host)
visit decidim_admin.edit_organization_path

allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

it "shows the menu in the admin panel in a correct place" do
Expand Down Expand Up @@ -48,4 +55,51 @@
expect(auth_settings.enable_partial_email_signup).to be(false)
expect(auth_settings.enable_partial_sms_signup).to be(true)
end

context "when sms gateway service is not present" do
before do
allow(Decidim.config).to receive(:sms_gateway_service).and_return(nil)
end

it "shows a warning message when the SMS gateway service is not configured" do
click_link "Authentication settings"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
expect(page).to have_css(".is-active", text: "Authentication settings")
expect(page.find("#auth_setting_enable_partial_sms_signup")).to be_disabled
expect(page).to have_content("This option is disabled please contact the host of the platform to enable it.")
end
end

context "when user tries to force the SMS verification without configuring the SMS gateway" do
before do
# Simplest way to simulate the behavior if the user tries to manually change the checkbox value even if sms_gateway_service is disabled)
allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

it "shows an error message when the SMS gateway service is not configured if the user tries to force the change" do
click_link "Authentication settings"

expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
expect(page).to have_css(".is-active", text: "Authentication settings")
check "Enable partial sign up and sign in using SMS verification"
check "Enable partial sign up and sign in using email verification"

allow(Decidim.config).to receive(:sms_gateway_service).and_return(nil)

click_button "Update"
expect(page).to have_current_path(decidim_half_signup_admin.edit_auth_setting_path(slug: "authentication_settings"))
within ".callout-wrapper" do
expect(page).not_to have_content("Organization updated successfully.")
expect(page).to have_content("The SMS gateway service is not defined.")
end
expect(page).to have_content("Settings available through code")
within "code" do
expect(page).to have_content("Decidim::HalfSignup.configure do |config|")
end
expect(page.find("#auth_setting_enable_partial_sms_signup")).not_to be_checked
auth_settings = Decidim::HalfSignup::AuthSetting.last
expect(auth_settings.enable_partial_email_signup).to be(false)
expect(auth_settings.enable_partial_sms_signup).to be(false)
end
end
end
7 changes: 7 additions & 0 deletions spec/system/budgets_view_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
let(:projects_count) { 1 }
let(:decidim_budgets) { Decidim::EngineRouter.main_proxy(component) }
let(:user) { create(:user, :confirmed, organization: organization) }
let(:sms_gateway_service) { "Decidim::Verifications::Sms::ExampleGateway" }

before do
switch_to_host(organization.host)

allow(Decidim.config).to receive(:sms_gateway_service).and_return(sms_gateway_service)
end

after do
allow(Decidim.config).to receive(:sms_gateway_service).and_call_original
end

context "with multiple budgets" do
Expand Down

0 comments on commit c2cfdd9

Please sign in to comment.