Skip to content

Commit

Permalink
Merge pull request #11 from co-cddo/add-security-classification-step
Browse files Browse the repository at this point in the history
Add security classification step
  • Loading branch information
RobNicholsGDS authored Feb 15, 2024
2 parents ce9bda4 + 0579a1d commit dd950cf
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/forms/security_classification_form.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class SecurityClassificationForm < BaseForm
validates :security_classification, presence: true

def update_item
item.metadata["securityClassification"] = security_classification
end

def security_classification
@security_classification ||= from_params(:security_classification)
end
end
7 changes: 7 additions & 0 deletions app/models/security_classification.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module SecurityClassification
VALUES = %w[OFFICIAL SECRET TOP_SECRET NOT_APPLICABLE].freeze

def self.values
VALUES
end
end
6 changes: 6 additions & 0 deletions app/views/items/forms/_security_classification.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<%= form.govuk_select(:security_classification, label: { text: "Security Classification" }) do %>
<%= options_for_select(
SecurityClassification.values,
selected: form.object.metadata["securityClassification"]
) %>
<% end %>
1 change: 1 addition & 0 deletions app/workflows/item_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class ItemWorkflow
contact_point: ContactPointForm,
creator: CreatorForm,
publisher: PublisherForm,
security_classification: SecurityClassificationForm,
}.freeze

def self.form_for(**options)
Expand Down
25 changes: 25 additions & 0 deletions spec/forms/security_classification_form_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "rails_helper"

RSpec.describe SecurityClassificationForm, type: :form do
let(:item) { build :item }
let(:security_classification) { SecurityClassification.values.sample }
let(:params) do
{ item: { security_classification: } }
end
let(:security_classification_form) { described_class.new(item:, params:) }

describe "#save" do
it "saves the security classification to metadata" do
security_classification_form.save
expect(item.reload.metadata["securityClassification"]).to eq(security_classification)
end

context "when security classification blank" do
let(:security_classification) { "" }

it "invalidates form" do
expect(security_classification_form).to be_invalid
end
end
end
end
1 change: 1 addition & 0 deletions spec/requests/item_workflow_intergration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
creator: Organisation.all.sample.id,
publisher: Organisation.all.sample.id,
security_classification: SecurityClassification.values.sample,
}
end

Expand Down

0 comments on commit dd950cf

Please sign in to comment.