Skip to content

Commit

Permalink
Merge pull request #9505 from neinteractiveliterature/recaptcha-disab…
Browse files Browse the repository at this point in the history
…le-flag

Recaptcha disable flag + null order fix
  • Loading branch information
nbudin authored Sep 16, 2024
2 parents 1d56d14 + edf3d88 commit 8e20ad8
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 7 deletions.
7 changes: 4 additions & 3 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,23 @@ class RegistrationsController < Devise::RegistrationsController
prepend_before_action :disable_destroy, only: [:destroy]

def new
respond_to { |format| format.html { redirect_with_authentication('signUp') } }
respond_to { |format| format.html { redirect_with_authentication("signUp") } }
end

private

def check_captcha
return if RootSite.instance.disable_captcha?
return if verify_recaptcha

configure_permitted_parameters # we prepended, so this won't have run
self.resource = resource_class.new sign_up_params
resource.validate # Look for any other validation errors besides Recaptcha
resource.errors.add :recaptcha, 'failed verification'
resource.errors.add :recaptcha, "failed verification"
respond_with resource
end

def disable_destroy
redirect_to root_path, alert: 'To delete your account, please email the site administrators.'
redirect_to root_path, alert: "To delete your account, please email the site administrators."
end
end
1 change: 1 addition & 0 deletions app/models/root_site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# Table name: root_sites
#
# id :bigint not null, primary key
# disable_captcha :boolean default(FALSE), not null
# site_name :text
# default_layout_id :bigint
# root_page_id :bigint
Expand Down
3 changes: 2 additions & 1 deletion app/presenters/convention_reports_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def sales_count_by_product_and_payment_amount
"COALESCE(price_per_item_cents, 0)",
"COALESCE(price_per_item_currency, #{ActiveRecord::Base.connection.quote(convention.default_currency_code_or_site_default)})"
)
.where("product_id IS NOT NULL")
.pluck(
:product_id,
:status,
Arel.sql("COALESCE(price_per_item_cents, 0)"),
Arel.sql(
"COALESCE(price_per_item_currency, #{ActiveRecord::Base.connection.quote(convention.default_currency_code_or_site_default)})"
),
Arel.sql("SUM(quantity) sum_quantity")
Arel.sql("COALESCE(SUM(quantity), 0) sum_quantity")
)

grouped_count_data.map do |product_id, status, amount_cents, amount_currency, sum_quantity|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddDisableCaptchaToRootSites < ActiveRecord::Migration[7.2]
def change
add_column :root_sites, :disable_captcha, :boolean, null: false, default: false
end
end
4 changes: 3 additions & 1 deletion db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2422,7 +2422,8 @@ CREATE TABLE public.root_sites (
id bigint NOT NULL,
site_name text,
root_page_id bigint,
default_layout_id bigint
default_layout_id bigint,
disable_captcha boolean DEFAULT false NOT NULL
);


Expand Down Expand Up @@ -6119,6 +6120,7 @@ ALTER TABLE ONLY public.cms_files_pages
SET search_path TO "$user", public;

INSERT INTO "schema_migrations" (version) VALUES
('20240916155847'),
('20240807155222'),
('20240717150224'),
('20240620014115'),
Expand Down
2 changes: 1 addition & 1 deletion test/factories/root_sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Table name: root_sites
#
# id :bigint not null, primary key
# disable_captcha :boolean default(FALSE), not null
# site_name :text
# default_layout_id :bigint
# root_page_id :bigint
Expand All @@ -19,7 +20,6 @@
# fk_rails_... (root_page_id => pages.id)
#
# rubocop:enable Layout/LineLength, Lint/RedundantCopDisableDirective
# rubocop:disable Metrics/LineLength, Lint/RedundantCopDisableDirective
FactoryBot.define do
factory :root_site do
site_name { "The Root Site" }
Expand Down
2 changes: 1 addition & 1 deletion test/models/root_site_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Table name: root_sites
#
# id :bigint not null, primary key
# disable_captcha :boolean default(FALSE), not null
# site_name :text
# default_layout_id :bigint
# root_page_id :bigint
Expand All @@ -19,7 +20,6 @@
# fk_rails_... (root_page_id => pages.id)
#
# rubocop:enable Layout/LineLength, Lint/RedundantCopDisableDirective
# rubocop:disable Layout/LineLength, Lint/RedundantCopDisableDirective
require "test_helper"

class RootSiteTest < ActiveSupport::TestCase
Expand Down

0 comments on commit 8e20ad8

Please sign in to comment.