Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cba flag #1976

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/controllers/super_admin/organisations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class SuperAdmin::OrganisationsController < SuperAdminController
helper_method :sort_column, :sort_direction

before_action :set_organisation, only: %i[toggle_cba_feature]

def index
@organisations = Organisation.sortable_with_child_counts(sort_column, sort_direction)

Expand Down Expand Up @@ -31,8 +33,17 @@ def destroy
redirect_to super_admin_organisations_path, notice: "Organisation has been removed"
end

def toggle_cba_feature
@organisation.update!(cba_enabled: !@organisation.cba_enabled)
redirect_to super_admin_organisation_path, notice: "Cba feature flag toggled successfully"
end

private

def set_organisation
@organisation = Organisation.find(params[:id])
end

def sortable_columns
%w[name created_at locations_count ips_count active_storage_attachments.created_at last_sign_in_at email sign_in_count]
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/organisation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Organisation < ApplicationRecord
validates :service_email, format: { with: Devise.email_regexp }
validate :validate_in_register?, unless: proc { |org| org.name.blank? }

validates :cba_enabled, inclusion: { in: [true, false] }, allow_nil: true

validates_associated :locations

scope :sortable_with_child_counts, lambda { |sort_column, sort_direction|
Expand All @@ -19,6 +21,14 @@ class Organisation < ApplicationRecord
.order(sort_column => sort_direction)
}

def enable_cba_feature!
update(cba_enabled: true)
end

def disable_cba_feature!
update(cba_enabled: false)
end

def meets_invited_admin_user_minimum?
memberships.count(&:administrator?) >= 2
end
Expand Down
1 change: 1 addition & 0 deletions app/views/logs/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<% end %>
</td>
<% end %>

<td class="govuk-table__cell"><%= log.ap %></td>
<td class="govuk-table__cell"><%= log.mac %></td>
<% unless log_search_form.ip %>
Expand Down
21 changes: 21 additions & 0 deletions app/views/super_admin/organisations/_cba_form.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<% cba_enabled = organisation.cba_enabled %>

<p class="govuk-body">
Show both EAP/TLS and MS-CHAPv2 authentication attempts in the logs. This is for organisations using Certificate Based Authentication (CBA)
</p>
<% if cba_enabled %>
<p class="govuk-body">
This organisation can see the CBA logs.
</p>
<% else %>
<p class="govuk-body">
This organisation cannot see the CBA logs.
</p>
<% end %>

<div id="cba-form">
<%= form_with(model: @organisation, url: toggle_cba_feature_super_admin_organisation_path(@organisation), method: :patch) do |form| %>
<%= form.hidden_field :cba_enabled, value: !@organisation.cba_enabled %>
<%= form.submit(@organisation.cba_enabled ? "Turn off CBA logs" : "Turn on CBA logs", class: @organisation.cba_enabled ? "govuk-button govuk-button--secondary" : "govuk-button") %>
<% end %>
</div>
4 changes: 4 additions & 0 deletions app/views/super_admin/organisations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<%= render "mou_form", organisation: @organisation %>
<% end %>

<%= render "section", heading: "CBA" do %>
<%= render "cba_form", organisation: @organisation %>
<% end %>

<%= render "section", heading: "Locations" do %>
<%== pagy_nav_govuk(@pagy) %>
<%= render "locations", locations: @locations %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
end
resources :mou, only: %i[index update create]
resources :organisations, only: %i[index show destroy] do
patch "toggle_cba_feature", to: "organisations#toggle_cba_feature", on: :member
collection do
get "service_emails", to: "organisations#service_emails", constraints: { format: "csv" }
end
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20231228135538_add_cba_enabled_to_organisations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddCbaEnabledToOrganisations < ActiveRecord::Migration[7.0]
def change
add_column :organisations, :cba_enabled, :boolean
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_06_19_161245) do
ActiveRecord::Schema[7.0].define(version: 2023_12_28_135538) do
create_table "active_storage_attachments", charset: "utf8", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
Expand Down Expand Up @@ -96,6 +96,7 @@
t.datetime "created_at", precision: nil, null: false
t.datetime "updated_at", precision: nil, null: false
t.string "service_email"
t.boolean "cba_enabled"
t.index ["name"], name: "index_organisations_on_name", unique: true
end

Expand Down
4 changes: 4 additions & 0 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ def create_user_for_organisations(
end

MouTemplate.create!

Organisation.all.each do |org|
org.update(cba_enabled: false)
end
Loading