Browse Source

Merge branch 'main' into BuGuidanceBackLinks

pull/2482/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
604fc499ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      Gemfile
  2. 22
      Gemfile.lock
  3. 3
      app/helpers/tab_nav_helper.rb
  4. 2
      app/views/users/show.html.erb
  5. 20
      lib/tasks/handle_unpended_logs.rake
  6. 8
      spec/helpers/tab_nav_helper_spec.rb
  7. 11
      spec/requests/users_controller_spec.rb

2
Gemfile

@ -63,7 +63,7 @@ gem "possessive"
gem "auto_strip_attributes" gem "auto_strip_attributes"
# Use sidekiq for background processing # Use sidekiq for background processing
gem "method_source", "~> 1.1" gem "method_source", "~> 1.1"
gem "rails_admin", "~> 3.0" gem "rails_admin", "~> 3.1"
gem "ruby-openai" gem "ruby-openai"
gem "sidekiq" gem "sidekiq"
gem "sidekiq-cron" gem "sidekiq-cron"

22
Gemfile.lock

@ -104,7 +104,7 @@ GEM
bindex (0.8.1) bindex (0.8.1)
bootsnap (1.18.3) bootsnap (1.18.3)
msgpack (~> 1.2) msgpack (~> 1.2)
builder (3.2.4) builder (3.3.0)
bundler-audit (0.9.1) bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3) bundler (>= 1.2.0, < 3)
thor (~> 1.0) thor (~> 1.0)
@ -128,7 +128,7 @@ GEM
launchy launchy
childprocess (5.0.0) childprocess (5.0.0)
coderay (1.1.3) coderay (1.1.3)
concurrent-ruby (1.3.1) concurrent-ruby (1.3.3)
connection_pool (2.4.1) connection_pool (2.4.1)
crack (1.0.0) crack (1.0.0)
bigdecimal bigdecimal
@ -163,7 +163,7 @@ GEM
rainbow rainbow
rubocop rubocop
smart_properties smart_properties
erubi (1.12.0) erubi (1.13.0)
et-orbi (1.2.7) et-orbi (1.2.7)
tzinfo tzinfo
event_stream_parser (1.0.0) event_stream_parser (1.0.0)
@ -241,13 +241,13 @@ GEM
matrix (0.4.2) matrix (0.4.2)
method_source (1.1.0) method_source (1.1.0)
mini_mime (1.1.5) mini_mime (1.1.5)
minitest (5.23.1) minitest (5.24.1)
msgpack (1.7.2) msgpack (1.7.2)
multipart-post (2.4.1) multipart-post (2.4.1)
nested_form (0.3.2) nested_form (0.3.2)
net-http (0.4.1) net-http (0.4.1)
uri uri
net-imap (0.4.12) net-imap (0.4.14)
date date
net-protocol net-protocol
net-pop (0.1.2) net-pop (0.1.2)
@ -257,11 +257,11 @@ GEM
net-smtp (0.5.0) net-smtp (0.5.0)
net-protocol net-protocol
nio4r (2.7.3) nio4r (2.7.3)
nokogiri (1.16.5-arm64-darwin) nokogiri (1.16.6-arm64-darwin)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.5-x86_64-darwin) nokogiri (1.16.6-x86_64-darwin)
racc (~> 1.4) racc (~> 1.4)
nokogiri (1.16.5-x86_64-linux) nokogiri (1.16.6-x86_64-linux)
racc (~> 1.4) racc (~> 1.4)
notifications-ruby-client (6.0.0) notifications-ruby-client (6.0.0)
jwt (>= 1.5, < 3) jwt (>= 1.5, < 3)
@ -333,7 +333,7 @@ GEM
rails-html-sanitizer (1.6.0) rails-html-sanitizer (1.6.0)
loofah (~> 2.21) loofah (~> 2.21)
nokogiri (~> 1.14) nokogiri (~> 1.14)
rails_admin (3.1.2) rails_admin (3.1.3)
activemodel-serializers-xml (>= 1.0) activemodel-serializers-xml (>= 1.0)
kaminari (>= 0.14, < 2.0) kaminari (>= 0.14, < 2.0)
nested_form (~> 0.3) nested_form (~> 0.3)
@ -484,7 +484,7 @@ GEM
websocket-extensions (0.1.5) websocket-extensions (0.1.5)
xpath (3.2.0) xpath (3.2.0)
nokogiri (~> 1.8) nokogiri (~> 1.8)
zeitwerk (2.6.15) zeitwerk (2.6.16)
PLATFORMS PLATFORMS
arm64-darwin-21 arm64-darwin-21
@ -535,7 +535,7 @@ DEPENDENCIES
rack-attack rack-attack
rack-mini-profiler (~> 2.0) rack-mini-profiler (~> 2.0)
rails (~> 7.0.8.3) rails (~> 7.0.8.3)
rails_admin (~> 3.0) rails_admin (~> 3.1)
redis (~> 4.8) redis (~> 4.8)
roo roo
rspec-rails rspec-rails

3
app/helpers/tab_nav_helper.rb

@ -19,7 +19,8 @@ module TabNavHelper
end end
def org_cell(user) def org_cell(user)
org_name = current_user.support? ? govuk_link_to(user.organisation.name, lettings_logs_organisation_path(user.organisation)) : user.organisation.name
role = "<span class=\"app-!-colour-muted\">#{user.role.to_s.humanize}</span>" role = "<span class=\"app-!-colour-muted\">#{user.role.to_s.humanize}</span>"
[user.organisation.name, role].join("\n") [org_name, role].join("\n")
end end
end end

2
app/views/users/show.html.erb

@ -67,7 +67,7 @@
<%= summary_list.with_row do |row| <%= summary_list.with_row do |row|
row.with_key { "Organisation" } row.with_key { "Organisation" }
row.with_value { @user.organisation.name } row.with_value { current_user.support? ? govuk_link_to(@user.organisation.name, lettings_logs_organisation_path(@user.organisation)) : @user.organisation.name }
row.with_action row.with_action
end %> end %>

20
lib/tasks/handle_unpended_logs.rake

@ -1,6 +1,6 @@
desc "Deduplicates logs where we have inadvertently turned some pending logs to in progress / completed" desc "Deduplicates logs where we have inadvertently turned some pending logs to in progress / completed"
task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args| task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args|
dry_run = true # args[:perform_updates].blank? || args[:perform_updates] != "true" dry_run = args[:perform_updates].blank? || args[:perform_updates] != "true"
pg = ActiveRecord::Base.connection pg = ActiveRecord::Base.connection
query = "SELECT \"versions\".* FROM \"versions\" WHERE \"versions\".\"item_type\" = 'LettingsLog' AND whodunnit is null AND ((object_changes like '%status:\n- 3\n- 1%') OR (object_changes like '%status:\n- 3\n- 2%'))" query = "SELECT \"versions\".* FROM \"versions\" WHERE \"versions\".\"item_type\" = 'LettingsLog' AND whodunnit is null AND ((object_changes like '%status:\n- 3\n- 1%') OR (object_changes like '%status:\n- 3\n- 2%'))"
@ -115,9 +115,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args
affected_non_updated_duplicates.each do |d| affected_non_updated_duplicates.each do |d|
seen.add(d.id) seen.add(d.id)
csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of unaffected log(s)", unaffected_logs_reference] csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of unaffected log(s)", unaffected_logs_reference]
# unless dry_run unless dry_run
# d.discard! d.discard!
# end end
end end
next next
end end
@ -133,9 +133,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args
affected_non_updated_duplicates.each do |d| affected_non_updated_duplicates.each do |d|
seen.add(d.id) seen.add(d.id)
csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of log(s) which have been updated since being affected", updated_logs_reference] csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of log(s) which have been updated since being affected", updated_logs_reference]
# unless dry_run unless dry_run
# d.discard! d.discard!
# end end
end end
next next
end end
@ -149,9 +149,9 @@ task :handle_unpended_logs, %i[perform_updates] => :environment do |_task, _args
seen.add(d.id) seen.add(d.id)
csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of more recently created affected log", latest_created.id] csv << [d.id, d.collection_start_year, d.status, d.owning_organisation_name, d.assigned_to_id, d.assigned_to.email, "Delete", "Log is a duplicate of more recently created affected log", latest_created.id]
# unless dry_run unless dry_run
# d.discard! d.discard!
# end end
end end
end end
end end

8
spec/helpers/tab_nav_helper_spec.rb

@ -2,21 +2,21 @@ require "rails_helper"
RSpec.describe TabNavHelper do RSpec.describe TabNavHelper do
let(:organisation) { FactoryBot.create(:organisation) } let(:organisation) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.build(:user, organisation:) } let(:current_user) { FactoryBot.build(:user, organisation:) }
let(:scheme) { FactoryBot.create(:scheme, service_name: "Some name") } let(:scheme) { FactoryBot.create(:scheme, service_name: "Some name") }
let(:location) { FactoryBot.create(:location, scheme:) } let(:location) { FactoryBot.create(:location, scheme:) }
describe "#user_cell" do describe "#user_cell" do
it "returns user link and email separated by a newline character" do it "returns user link and email separated by a newline character" do
expected_html = "<a class=\"govuk-link\" href=\"/users\">#{user.name}</a>\n<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{user.email}</span>" expected_html = "<a class=\"govuk-link\" href=\"/users\">#{current_user.name}</a>\n<span class=\"govuk-visually-hidden\">User </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{current_user.email}</span>"
expect(user_cell(user)).to match(expected_html) expect(user_cell(current_user)).to match(expected_html)
end end
end end
describe "#org_cell" do describe "#org_cell" do
it "returns the users org name and role separated by a newline character" do it "returns the users org name and role separated by a newline character" do
expected_html = "DLUHC\n<span class=\"app-!-colour-muted\">Data provider</span>" expected_html = "DLUHC\n<span class=\"app-!-colour-muted\">Data provider</span>"
expect(org_cell(user)).to match(expected_html) expect(org_cell(current_user)).to match(expected_html)
end end
end end

11
spec/requests/users_controller_spec.rb

@ -1188,7 +1188,7 @@ RSpec.describe UsersController, type: :request do
describe "#index" do describe "#index" do
let!(:other_user) { create(:user, organisation: user.organisation, name: "User 2", email: "other@example.com") } let!(:other_user) { create(:user, organisation: user.organisation, name: "User 2", email: "other@example.com") }
let!(:inactive_user) { create(:user, organisation: user.organisation, active: false, name: "User 3", email: "inactive@example.com", last_sign_in_at: Time.zone.local(2022, 10, 10)) } let!(:inactive_user) { create(:user, organisation: user.organisation, active: false, name: "User 3", email: "inactive@example.com", last_sign_in_at: Time.zone.local(2022, 10, 10)) }
let!(:other_org_user) { create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc)) } let!(:other_org_user) { create(:user, name: "User 4", email: "otherorg@otherexample.com", organisation: create(:organisation, :without_dpc, name: "Other name")) }
before do before do
get "/users", headers:, params: {} get "/users", headers:, params: {}
@ -1201,6 +1201,11 @@ RSpec.describe UsersController, type: :request do
expect(page).to have_content(other_org_user.name) expect(page).to have_content(other_org_user.name)
end end
it "links to user organisations" do
expect(page).to have_link(user.organisation.name, href: "/organisations/#{user.organisation.id}/lettings-logs", count: 3)
expect(page).to have_link(other_org_user.organisation.name, href: "/organisations/#{other_org_user.organisation.id}/lettings-logs", count: 1)
end
it "shows last logged in date for all users" do it "shows last logged in date for all users" do
expect(page).to have_content("10 October 2022") expect(page).to have_content("10 October 2022")
end end
@ -1432,6 +1437,10 @@ RSpec.describe UsersController, type: :request do
expect(page).to have_link("Change", text: "if a key contact") expect(page).to have_link("Change", text: "if a key contact")
end end
it "links to user organisation" do
expect(page).to have_link(other_user.organisation.name, href: "/organisations/#{other_user.organisation.id}/lettings-logs")
end
it "does not show option to resend confirmation email" do it "does not show option to resend confirmation email" do
expect(page).not_to have_button("Resend invite link") expect(page).not_to have_button("Resend invite link")
end end

Loading…
Cancel
Save