Skip to content

Commit

Permalink
Allow disabling of account creation via environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKvalheim committed May 8, 2024
1 parent b166651 commit ff3131f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
8 changes: 8 additions & 0 deletions app/controllers/registrations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

class RegistrationsController < Devise::RegistrationsController
prepend_before_action :require_account_creation, only: [:create, :new]
prepend_before_action :check_captcha, only: [:create]

def create
Expand Down Expand Up @@ -44,4 +45,11 @@ def check_captcha
respond_with_navigational(resource) { render :new }
end
end

def require_account_creation
if Feature.inactive?(:account_creation)
flash[:error] = 'Account sign-up is not currently open'
redirect_to root_path, status: :see_other
end
end
end
21 changes: 11 additions & 10 deletions app/views/layouts/_navigation.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@
= render 'layouts/user_menu'
- else
%ul.nav.navbar-nav.navbar-right
- if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true'
%li{class: "#{active_nav_li(new_ichain_registration_path('user'))}"}
= link_to(new_ichain_registration_path('user')) do
%span.fa-solid.fa-heart
Sign Up
- else
%li{class: "#{active_nav_li(new_registration_path('user'))}"}
= link_to(new_registration_path('user')) do
%span.fa-solid.fa-heart
Sign Up
- if Feature.active?(:account_creation)
- if ENV.fetch('OSEM_ICHAIN_ENABLED', nil) == 'true'
%li{class: "#{active_nav_li(new_ichain_registration_path('user'))}"}
= link_to(new_ichain_registration_path('user')) do
%span.fa-solid.fa-heart
Sign Up
- else
%li{class: "#{active_nav_li(new_registration_path('user'))}"}
= link_to(new_registration_path('user')) do
%span.fa-solid.fa-heart
Sign Up
%li.dropdown.visible-desktop
%a.dropdown-toggle{"data-toggle" => "dropdown", href: '#'}
%span.fa-solid.fa-user
Expand Down
3 changes: 3 additions & 0 deletions config/initializers/feature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
repo = Feature::Repository::SimpleRepository.new

# configure features here
unless ActiveRecord::Type::Boolean.new.cast(ENV.fetch('DISABLE_ACCOUNT_CREATION', 'false'))
repo.add_active_feature :account_creation
end
unless(ENV['RECAPTCHA_SITE_KEY'].blank? || ENV['RECAPTCHA_SECRET_KEY'].blank?)
repo.add_active_feature :recaptcha
end
Expand Down

0 comments on commit ff3131f

Please sign in to comment.