diff --git a/app/controllers/user/registrations_controller.rb b/app/controllers/user/registrations_controller.rb
index e4f2e906..fbfe1f81 100644
--- a/app/controllers/user/registrations_controller.rb
+++ b/app/controllers/user/registrations_controller.rb
@@ -1,9 +1,13 @@
+# frozen_string_literal: true
+
class User::RegistrationsController < Devise::RegistrationsController
+ before_action :redirect_if_registrations_disabled!, only: %w[create new]
+
def create
if captcha_valid?
super
else
- respond_with_navigational(resource){ redirect_to new_user_registration_path }
+ respond_with_navigational(resource) { redirect_to new_user_registration_path }
end
end
@@ -18,7 +22,7 @@ class User::RegistrationsController < Devise::RegistrationsController
resource.destroy
set_flash_message :notice, :destroyed if is_flashing_format?
yield resource if block_given?
- respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
+ respond_with_navigational(resource) { redirect_to after_sign_out_path_for(resource_name) }
end
private
@@ -29,4 +33,8 @@ class User::RegistrationsController < Devise::RegistrationsController
verify_hcaptcha
end
+
+ def redirect_if_registrations_disabled!
+ redirect_to root_path unless APP_CONFIG.dig(:features, :registration, :enabled)
+ end
end
diff --git a/app/views/about/index.html.haml b/app/views/about/index.html.haml
index 87bf9d14..f35cb2c9 100644
--- a/app/views/about/index.html.haml
+++ b/app/views/about/index.html.haml
@@ -5,12 +5,18 @@
= render "layouts/messages"
%h1= APP_CONFIG["site_name"]
%p= t(".subtitle")
- %p
- %a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_registration_path) }
- = t(".register")
- %small
- = t(".already_member")
- = link_to t("voc.login"), new_user_session_path
+ - if APP_CONFIG.dig(:features, :registration, :enabled)
+ %p
+ %a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_registration_path) }
+ = t(".register")
+ %small
+ = t(".already_member")
+ = link_to t("voc.login"), new_user_session_path
+ - else
+ %p
+ %a.btn.btn-outline-light.btn-lg{ href: url_for(new_user_session_path) }
+ = t("voc.login")
+
.row.my-5.my-sm-10
.col-sm-6.order-5.order-sm-1.text-center.text-sm-right
%h2.mb-4= t(".questions.header")
@@ -77,12 +83,13 @@
= t(".your_data.header")
%p= t(".your_data.body", app_name: APP_CONFIG["site_name"])
- .card
- .card-body
- %h2= t(".prompt.header")
- %p= t(".prompt.body")
- %p
- %a.btn.btn-primary.btn-lg{ href: url_for(new_user_registration_path) }
- = t(".register")
+ - if APP_CONFIG.dig(:features, :registration, :enabled)
+ .card
+ .card-body
+ %h2= t(".prompt.header")
+ %p= t(".prompt.body")
+ %p
+ %a.btn.btn-primary.btn-lg{ href: url_for(new_user_registration_path) }
+ = t(".register")
= render "shared/links"
diff --git a/app/views/application/_questionbox.html.haml b/app/views/application/_questionbox.html.haml
index c6bfee72..33ecf06f 100644
--- a/app/views/application/_questionbox.html.haml
+++ b/app/views/application/_questionbox.html.haml
@@ -40,24 +40,29 @@
%input{ name: "qb-to", type: "hidden", value: user.id }/
%button.btn.btn-primary{ name: "qb-ask",
type: :button,
- data: { loading_text: t(".load"), promote: user_signed_in? ? "false" : "true", "character-count-target": "action" } }
+ data: { loading_text: t(".load"), promote: user_signed_in? || !user_signed_in? && !APP_CONFIG.dig(:features, :registration, :enabled) ? "false" : "true", "character-count-target": "action" } }
Ask
- unless user_signed_in?
- if user.privacy_allow_anonymous_questions?
- .d-none#question-box-promote
- .row
- .col-12.text-center
- %strong= t(".promote.message")
- .row
- .col-sm-5.offset-sm-1
- .d-grid
- %button.btn.btn-primary#create-account= t(".promote.create")
- .col-sm-5
- .d-grid
- %button.btn.btn-default#new-question= t(".promote.another")
- .row
- .col-xs-12.col-sm-10.offset-sm-1.text-center
- %small= t(".promote.join", app_title: APP_CONFIG["site_name"])
+ - if APP_CONFIG.dig(:features, :registration, :enabled)
+ .d-none#question-box-promote
+ .row
+ .col-12.text-center
+ %strong= t(".promote.message")
+ .row
+ .col-sm-5.offset-sm-1
+ .d-grid
+ %button.btn.btn-primary#create-account= t(".promote.create")
+ .col-sm-5
+ .d-grid
+ %button.btn.btn-default#new-question= t(".promote.another")
+ .row
+ .col-xs-12.col-sm-10.offset-sm-1.text-center
+ %small= t(".promote.join", app_title: APP_CONFIG["site_name"])
- else
.text-center
- %strong= t(".status.non_anonymous_html", sign_in: link_to(t("voc.login"), new_user_session_path), sign_up: link_to(t("voc.register"), new_user_registration_path))
+ - if APP_CONFIG.dig(:features, :registration, :enabled)
+ %strong= t(".status.non_anonymous_html", sign_in: link_to(t("voc.login"), new_user_session_path), sign_up: link_to(t("voc.register"), new_user_registration_path))
+ - else
+ %strong= t(".status.non_anonymous_no_registration_html", sign_in: link_to(t("voc.login"), new_user_session_path))
+
diff --git a/app/views/navigation/_guest.html.haml b/app/views/navigation/_guest.html.haml
index 4d9c330d..a06fab83 100644
--- a/app/views/navigation/_guest.html.haml
+++ b/app/views/navigation/_guest.html.haml
@@ -14,4 +14,5 @@
.collapse.navbar-collapse#j2-main-navbar-collapse
%ul.nav.navbar-nav.ms-auto
= nav_entry t("voc.login"), new_user_session_path
- = nav_entry t("voc.register"), new_user_registration_path
+ - if APP_CONFIG.dig(:features, :registration, :enabled)
+ = nav_entry t("voc.register"), new_user_registration_path
diff --git a/config/justask.yml.example b/config/justask.yml.example
index 22f309a4..f27c3089 100644
--- a/config/justask.yml.example
+++ b/config/justask.yml.example
@@ -52,6 +52,9 @@ features:
# Public timeline
public:
enabled: true
+ # Registrations
+ registration:
+ enabled: true
# Redis
redis_url: "redis://localhost:6379"
diff --git a/config/locales/views.en.yml b/config/locales/views.en.yml
index f918d3e4..c938bf06 100644
--- a/config/locales/views.en.yml
+++ b/config/locales/views.en.yml
@@ -146,6 +146,9 @@ en:
non_anonymous_html: |
This user does not want to receive anonymous questions.
(%{sign_in} or %{sign_up})
+ non_anonymous_no_registration_html: |
+ This user does not want to receive anonymous questions.
+ (%{sign_in})
comment:
show_reactions:
title: "People who smiled this comment"
diff --git a/config/routes.rb b/config/routes.rb
index 52d1f53b..9790212f 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -63,7 +63,7 @@ Rails.application.routes.draw do
# :registrations
get "settings/delete_account" => "devise/registrations#cancel", :as => :cancel_user_registration
post "/user/create" => "user/registrations#create", :as => :user_registration
- get "/sign_up" => "devise/registrations#new", :as => :new_user_registration
+ get "/sign_up" => "user/registrations#new", :as => :new_user_registration
get "/settings/account" => "devise/registrations#edit", :as => :edit_user_registration
patch "/settings/account" => "devise/registrations#update", :as => :update_user_registration
put "/settings/account" => "devise/registrations#update"