generated from dxw/rails-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cms): ability to sync frameworks with FaF
Jira: PWNN-1529
- Loading branch information
1 parent
e339e2a
commit 1058aa9
Showing
18 changed files
with
232 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,4 +64,6 @@ AWS_SECRET_ACCESS_KEY= | |
AWS_REGION= | ||
BUCKET_NAME= | ||
|
||
# FaF | ||
FAF_WEBHOOK_SECRET= | ||
FAF_FRAMEWORK_ENDPOINT= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,3 +46,6 @@ MS_GRAPH_CLIENT_SECRET="z" | |
MS_GRAPH_SHARED_MAILBOX_USER_ID="c" | ||
MS_GRAPH_SHARED_MAILBOX_NAME="mailbox" | ||
MS_GRAPH_SHARED_MAILBOX_ADDRESS="[email protected]" | ||
|
||
# FaF | ||
FAF_FRAMEWORK_ENDPOINT=http://faf.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,7 @@ jobs: | |
-e PROC_OPS_TEAM="DSI Caseworkers" \ | ||
-e QUALTRICS_SURVEY_URL=https://dferesearch.fra1.qualtrics.com \ | ||
-e [email protected] \ | ||
-e FAF_FRAMEWORK_ENDPOINT=http://faf.test \ | ||
-e CI_NODE_TOTAL=${{ matrix.ci_node_total }} \ | ||
-e CI_NODE_INDEX=${{ matrix.ci_node_index }} \ | ||
-e CI=1 \ | ||
|
29 changes: 0 additions & 29 deletions
29
app/controllers/api/find_a_framework/frameworks_controller.rb
This file was deleted.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
app/controllers/support/management/sync_frameworks_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Support | ||
module Management | ||
class SyncFrameworksController < BaseController | ||
after_action -> { flash.discard }, only: :create | ||
|
||
def index; end | ||
|
||
def create | ||
Support::SyncFrameworksJob.perform_later | ||
flash[:notice] = "Task triggered" | ||
render :index | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Support | ||
class SyncFrameworksJob < ApplicationJob | ||
queue_as :support | ||
|
||
def perform | ||
Support::SyncFrameworks.new.call | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
module Support | ||
class SyncFrameworks | ||
def initialize(endpoint: ENV["FAF_FRAMEWORK_ENDPOINT"]) | ||
@endpoint = endpoint | ||
end | ||
|
||
def call | ||
fetch_frameworks | ||
upsert_frameworks if @frameworks.present? | ||
end | ||
|
||
private | ||
|
||
def fetch_frameworks | ||
uri = URI.parse(@endpoint) | ||
response = | ||
Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") do |http| | ||
request = Net::HTTP::Get.new(uri) | ||
http.request(request) | ||
end | ||
|
||
if response.code == "200" | ||
@frameworks = JSON.parse(response.body) | ||
else | ||
Rollbar.error("Could not fetch frameworks", uri: @endpoint, status: response.code) | ||
end | ||
end | ||
|
||
def upsert_frameworks | ||
prepared_frameworks = prepare_frameworks(@frameworks) | ||
Support::Framework.upsert_all( | ||
prepared_frameworks, | ||
unique_by: %i[ref], | ||
) | ||
end | ||
|
||
def prepare_frameworks(frameworks) | ||
frameworks.select { |framework| framework["expiry"].present? }.map do |framework| | ||
{ | ||
name: framework["title"], | ||
ref: framework["ref"], | ||
supplier: framework["provider"].try(:[], "initials"), | ||
category: framework["cat"].try(:[], "title"), | ||
expires_at: Date.parse(framework["expiry"]), | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
app/views/support/management/sync_frameworks/index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%= content_for :title, "#{I18n.t("support.management.base.header")} | #{I18n.t("support.management.sync_frameworks.header")}" %> | ||
|
||
<div class="govuk-breadcrumbs"> | ||
<ol class="govuk-breadcrumbs__list"> | ||
<li class="govuk-breadcrumbs__list-item"> | ||
<%= link_to I18n.t("support.management.base.header"), support_management_path, class: "govuk-breadcrumbs__link" %> | ||
</li> | ||
<li class="govuk-breadcrumbs__list-item"> | ||
<%= link_to I18n.t("support.management.sync_frameworks.header"), support_management_email_templates_path, class: "govuk-breadcrumbs__link" %> | ||
</li> | ||
</ol> | ||
</div> | ||
|
||
<h1 class="govuk-heading-l"><%= I18n.t("support.management.sync_frameworks.header") %></h1> | ||
|
||
<% I18n.t("support.management.sync_frameworks.body").each do |p| %> | ||
<p class="govuk-body"><%= p.html_safe %></p> | ||
<% end %> | ||
<%= button_to I18n.t("support.management.sync_frameworks.sync"), support_management_sync_frameworks_path, class: "govuk-button" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class AddRefToSupportFrameworks < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :support_frameworks, :ref, :string | ||
add_index :support_frameworks, :ref, unique: true | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
spec/requests/self-serve/api/find_a_framework/webhook_upsert_framework_spec.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.