Skip to content

Commit

Permalink
refactor submissions table and tags
Browse files Browse the repository at this point in the history
* update api key
* ensure registry records can be published if they don't have a contact (for legacy records)
  • Loading branch information
ryanwoldatwork authored May 15, 2023
1 parent 0ec9e4f commit 8981d93
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 76 deletions.
6 changes: 6 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ LOGIN_GOV_OPENID_CERT_URL='https://idp.int.identitysandbox.gov/api/openid_connec
# For New Relic
NEW_RELIC_KEY=YOUR-NEW-RELIC-KEY-HERE

# See: rails db:encryption:init
# Also see: rails credentials:help
RAILS_ACTIVE_RECORD_PRIMARY_KEY=
RAILS_ACTIVE_RECORD_DETERMINISTIC_KEY=
RAILS_ACTIVE_RECORD_KEY_DERIVATION_SALT=

# Redis cache store
REDIS_URL=redis://localhost:6379/1

Expand Down
7 changes: 6 additions & 1 deletion app/controllers/admin/digital_products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,16 @@ def publish
if @digital_product.publish!
Event.log_event(Event.names[:digital_product_published], 'Digital Product', @digital_product.id, "Digital Product #{@digital_product.name} published at #{DateTime.now}", current_user.id)

@account_contacts = []
if @digital_product.roles.first
@account_contacts = @digital_product.roles.first.users.collect(&:email)
end

UserMailer.notification(
title: 'Digital Product has been published',
body: "Digital Product #{@digital_product.name} published at #{DateTime.now} by #{current_user.email}",
path: admin_digital_product_url(@digital_product),
emails: (User.admins.collect(&:email) + User.registry_managers.collect(&:email) + @digital_product.roles.first.users.collect(&:email)).uniq,
emails: (User.admins.collect(&:email) + User.registry_managers.collect(&:email) + @account_contacts).uniq,
).deliver_later

redirect_to admin_digital_product_path(@digital_product), notice: "Digital Product #{@digital_product.name} was published."
Expand Down
9 changes: 7 additions & 2 deletions app/controllers/admin/digital_service_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,17 @@ def publish
'Digital Service Account',
@digital_service_account.id,
"Digital Service Account #{@digital_service_account.name} published at #{DateTime.now}", current_user.id)


@account_contacts = []
if @digital_service_account.roles.first
@account_contacts = @digital_service_account.roles.first.users.collect(&:email)
end

UserMailer.notification(
title: 'Digital Service Account was published',
body: "Digital Service Account #{@digital_service_account.name} published at #{DateTime.now} by #{current_user.email}",
path: admin_digital_service_account_url(@digital_service_account),
emails: (User.admins.collect(&:email) + User.registry_managers.collect(&:email) + @digital_service_account.roles.first.users.collect(&:email)).uniq,
emails: (User.admins.collect(&:email) + User.registry_managers.collect(&:email) + @account_contacts).uniq
).deliver_later

redirect_to admin_digital_service_account_path(@digital_service_account), notice: "Digital Service Account #{@digital_service_account.name} was published."
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

class User < ApplicationRecord
encrypts :api_key, deterministic: true

rolify
# Include default devise modules. Others available are:
# :lockable
Expand Down
3 changes: 0 additions & 3 deletions app/views/admin/submissions/_responses_by_status.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
<label class="usa-label text-uppercase font-body-3xs">
Responses by status
</label>
<%= render 'components/responses_by_status', submissions: form.submissions %>
2 changes: 1 addition & 1 deletion app/views/admin/submissions/_submissions.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Filter by tag
</p>
<div class="tag-list">
<% @tags.each do | tag | %>
<% @tags.uniq.each do | tag | %>
<a href="#" class="search-tag-link" data-name="<%= tag.name %>">
<span class="usa-tag">
<%= tag.name %>
Expand Down
121 changes: 53 additions & 68 deletions app/views/components/_responses_by_status.html.erb
Original file line number Diff line number Diff line change
@@ -1,70 +1,55 @@
<label class="usa-label text-uppercase font-body-3xs">
Responses by status
</label>
<table class="usa-table">
<tr>
<td>
</td>
<td>
Total
</td>
<td>
Received
</td>
<td>
Acknowledged
</td>
<td>
Dispatched
</td>
<td>
Responded
</td>
<td>
Flagged
</td>
</tr>
<tr>
<td>
Active
</td>
<td>
<%= submissions.non_archived.size %>
</td>
<td>
<%= submissions.non_archived.where(aasm_state: "received").size %>
</td>
<td>
<%= submissions.non_archived.where(aasm_state: "acknowledged").size %>
</td>
<td>
<%= submissions.non_archived.where(aasm_state: "dispatched").size %>
</td>
<td>
<%= submissions.non_archived.where(aasm_state: "responded").size %>
</td>
<td>
<%= submissions.non_archived.where(flagged: true).size %>
</td>
</tr>
<tr>
<td>
Archived
</td>
<td>
<%= submissions.archived.size %>
</td>
<td>
<%= submissions.archived.where(aasm_state: "received").size %>
</td>
<td>
<%= submissions.archived.where(aasm_state: "acknowledged").size %>
</td>
<td>
<%= submissions.archived.where(aasm_state: "dispatched").size %>
</td>
<td>
<%= submissions.archived.where(aasm_state: "responded").size %>
</td>
<td>
<%= submissions.archived.where(flagged: true).size %>
</td>
</tr>
<thead>
<tr>
<th>
Received
</th>
<th>
Acknowledged
</th>
<th>
Dispatched
</th>
<th>
Responded
</th>
<th>
Archived
</th>
<th>
Flagged
</th>
<th>
Total
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<%= submissions.select { |s| s.aasm_state == "received" }.size %>
</td>
<td>
<%= submissions.select { |s| s.acknowledged? }.size %>
</td>
<td>
<%= submissions.select { |s| s.dispatched? }.size %>
</td>
<td>
<%= submissions.select { |s| s.responded? }.size %>
</td>
<td>
<%= submissions.archived.size %>
</td>
<td>
<%= submissions.where(flagged: true).size %>
</td>
<td>
<%= submissions.size %>
</td>
</tr>
</tbody>
</table>
5 changes: 5 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,9 @@

# Uncomment if you wish to allow Action Cable access from any origin.
# config.action_cable.disable_request_forgery_protection = true

config.active_record.encryption.primary_key = ENV.fetch("RAILS_ACTIVE_RECORD_PRIMARY_KEY")
config.active_record.encryption.deterministic_key = ENV.fetch("RAILS_ACTIVE_RECORD_DETERMINISTIC_KEY")
config.active_record.encryption.key_derivation_salt = ENV.fetch("RAILS_ACTIVE_RECORD_KEY_DERIVATION_SALT")
config.active_record.encryption.support_unencrypted_data = true
end
5 changes: 5 additions & 0 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,9 @@
# config.active_record.database_selector = { delay: 2.seconds }
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session

config.active_record.encryption.primary_key = ENV.fetch("RAILS_ACTIVE_RECORD_PRIMARY_KEY")
config.active_record.encryption.deterministic_key = ENV.fetch("RAILS_ACTIVE_RECORD_DETERMINISTIC_KEY")
config.active_record.encryption.key_derivation_salt = ENV.fetch("RAILS_ACTIVE_RECORD_KEY_DERIVATION_SALT")
config.active_record.encryption.support_unencrypted_data = true
end
5 changes: 5 additions & 0 deletions config/environments/staging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,9 @@

config.action_mailer.delivery_method = :ses
config.action_mailer.perform_deliveries = true

config.active_record.encryption.primary_key = ENV.fetch("RAILS_ACTIVE_RECORD_PRIMARY_KEY")
config.active_record.encryption.deterministic_key = ENV.fetch("RAILS_ACTIVE_RECORD_DETERMINISTIC_KEY")
config.active_record.encryption.key_derivation_salt = ENV.fetch("RAILS_ACTIVE_RECORD_KEY_DERIVATION_SALT")
config.active_record.encryption.support_unencrypted_data = true
end
5 changes: 5 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,9 @@

# Annotate rendered view with file names.
# config.action_view.annotate_rendered_view_with_filenames = true

config.active_record.encryption.primary_key = ENV.fetch("RAILS_ACTIVE_RECORD_PRIMARY_KEY")
config.active_record.encryption.deterministic_key = ENV.fetch("RAILS_ACTIVE_RECORD_DETERMINISTIC_KEY")
config.active_record.encryption.key_derivation_salt = ENV.fetch("RAILS_ACTIVE_RECORD_KEY_DERIVATION_SALT")
config.active_record.encryption.support_unencrypted_data = true
end
9 changes: 9 additions & 0 deletions db/migrate/20230511190351_user_api_keys.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class UserApiKeys < ActiveRecord::Migration[7.0]
def change
User.where("api_key IS NOT NULL").each do |user|
@existing_key = user.api_key
user.update(api_key: "")
user.update(api_key: @existing_key)
end
end
end
2 changes: 1 addition & 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_03_23_222925) do
ActiveRecord::Schema[7.0].define(version: 2023_05_11_190351) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down
14 changes: 14 additions & 0 deletions spec/features/admin/digital_products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@
end
end

describe '#publish' do
let!(:submitted_digital_product) { FactoryBot.create(:digital_product, name: 'Test1', service: 'Gov Mobile App', aasm_state: 'submitted') }

before do
visit admin_digital_product_path(submitted_digital_product)
end

it 'can publish digital product record' do
expect(page).to have_content('Mobile App')
click_on("Publish")
expect(page).to have_content("Digital Product #{digital_product.name} was published.")
end
end

describe '#delete' do
before do
visit admin_digital_product_path(digital_product)
Expand Down
14 changes: 14 additions & 0 deletions spec/features/admin/digital_service_accounts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,20 @@
end
end

describe '#publish' do
let(:digital_service_account) { FactoryBot.create(:digital_service_account, aasm_state: :submitted) }

before do
visit admin_digital_service_account_path(digital_service_account)
end

it 'can publish digital service account' do
expect(page).to have_content('Social Media Account')
click_on("Publish")
expect(page).to have_content("Digital Service Account #{digital_service_account.name} was published.")
end
end

describe '#delete' do
let(:digital_service_account) { FactoryBot.create(:digital_service_account) }

Expand Down

0 comments on commit 8981d93

Please sign in to comment.