Skip to content

Commit

Permalink
POC allow registration when service is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
slawosz committed Feb 15, 2024
1 parent 71c550b commit cf47bb8
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 6 deletions.
21 changes: 21 additions & 0 deletions app/controllers/admin/closed_registration_users_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class Admin::ClosedRegistrationUsersController < SuperAdminController
def index
@users = ClosedRegistrationUser.all
@user = ClosedRegistrationUser.new
end

def new
@user = ClosedRegistrationUser.new
end

def create
@user = ClosedRegistrationUser.new(params[:closed_registration_user].permit(:email))
if @user.save
flash[:success] = "New closed registration user created"
redirect_to admin_closed_registration_users_path
else
flash[:error] = "Can not create a user"
render :index
end
end
end
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class ApplicationController < ActionController::Base
default_form_builder GOVUKDesignSystemFormBuilder::FormBuilder

before_action :set_sentry_user
# This will be moved to more suitable place in the implementation
before_action :set_feature_flag_users

private

Expand Down Expand Up @@ -41,4 +43,9 @@ def current_admin
Admin.find_by(id: session[:admin_id])
end
helper_method :current_admin

def set_feature_flag_users
users = User.where(email: ClosedRegistrationUser.pluck(:email))
users.each { |u| Flipper.enable_actor(Feature::REGISTRATION_OPEN, u) }
end
end
11 changes: 10 additions & 1 deletion app/controllers/registration_wizard_controller.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class RegistrationWizardController < ApplicationController
before_action :registration_closed
before_action :set_wizard
before_action :set_form
before_action :check_end_of_journey, only: %i[update]
Expand Down Expand Up @@ -49,12 +50,20 @@ def check_end_of_journey
end
end

def registration_closed
return if request.path == registration_wizard_show_path(:closed)

if Feature.registration_closed?(current_user)
redirect_to registration_wizard_show_path(:closed)
end
end

def store
session["registration_store"] ||= {}
end

def wizard_params
return {} if Feature.registration_closed?
return {} if Feature.registration_closed?(current_user)

params.fetch(:registration_wizard, {}).permit(RegistrationWizard.permitted_params_for_step(params[:step].underscore))
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/closed_registration_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class ClosedRegistrationUser < ApplicationRecord
end
3 changes: 2 additions & 1 deletion app/models/registration_wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class InvalidStep < StandardError; end
attr_reader :current_step, :params, :store, :request, :current_user

def initialize(current_step:, store:, request:, current_user:, params: {})
current_step = :closed if Feature.registration_closed?
# current_step = :closed if Feature.registration_closed?

set_current_step(current_step)

@current_user = current_user
Expand Down
8 changes: 4 additions & 4 deletions app/services/feature.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
class Feature
REGISTRATION_OPEN_DATE = Time.zone.parse("6 June 2022 12:00")

REGISTRATION_CLOSED_KEY = "Registration closed".freeze
REGISTRATION_OPEN = "Registration open".freeze
REGISTRATION_DISABLED = "Registration disabled".freeze

FEATURE_FLAG_KEYS = [
REGISTRATION_CLOSED_KEY,
REGISTRATION_OPEN,
].freeze

class << self
Expand All @@ -27,8 +27,8 @@ def trn_required?
true
end

def registration_closed?
Flipper.enabled?(REGISTRATION_CLOSED_KEY)
def registration_closed?(user)
!Flipper.enabled?(REGISTRATION_OPEN, user)
end

def registration_disabled?
Expand Down
35 changes: 35 additions & 0 deletions app/views/admin/closed_registration_users/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= render "admin/layout", title: "Closed registration users" %>

<h2 class="govuk-heading-l">Add new email</h2>
<%= form_for [:admin, @user] do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_text_field :email, legend: { text: 'Provide course start date' } %>
<%= f.govuk_submit "Save" %>
<% end %>

<h2 class="govuk-heading-l">Currently allowed emails</h2>

<table class="govuk-table">
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">User</th>
<th scope="col" class="govuk-table__header">Has account</th>
<th scope="col" class="govuk-table__header">Last application date</th>
</tr>
</thead>

<tbody class="govuk-table__body">
<% @users.each do |user| %>
<tr class="govuk-table__row">
<td class="govuk-table__cell"><%= user.email %></td>
<td class="govuk-table__cell"><%= %></td>
<td class="govuk-table__cell"></td>
</tr>
<% end %>
</tbody>
</table>

</div>
</div>
13 changes: 13 additions & 0 deletions app/views/admin/closed_registration_users/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<h1>Admin::LateRegistrants#new</h1>
<p>Find me in app/views/admin/late_registrants/new.html.erb</p>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<%= render "admin/layout", title: "Settings" %>
<%= form_for [:admin, @user] do |f| %>
<%= f.govuk_error_summary %>
<%= f.govuk_text_field :email, legend: { text: 'Provide course start date' } %>
<%= f.govuk_submit "Save" %>
<% end %>
</div>
</div>
3 changes: 3 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
end

namespace :admin do
get 'closed_registration_users/index'
get 'closed_registration_users/new'
resources :applications, only: %i[index show] do
# This routes are only written for review apps in order to update the external statuses
member do
Expand Down Expand Up @@ -70,6 +72,7 @@
constraints HasFlipperAccess do
mount Flipper::UI.app(Flipper) => "/feature_flags"
end
resources :closed_registration_users
end

get "/admin", to: "admin#show"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAllowClosedRegistrationToUsers < ActiveRecord::Migration[7.1]
def change
add_column :users, :allow_closed_registration, :boolean
end
end
9 changes: 9 additions & 0 deletions db/migrate/20240215174312_create_closed_registration_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateClosedRegistrationUsers < ActiveRecord::Migration[7.1]
def change
create_table :closed_registration_users do |t|
t.string :email

t.timestamps
end
end
end

0 comments on commit cf47bb8

Please sign in to comment.