Browse Source

Merge branch 'main' into BuPartialPostcode

pull/2692/head
Rachael Booth 2 years ago committed by GitHub
parent
commit
88886296f8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      Gemfile
  2. 128
      Gemfile.lock
  3. 7
      app/models/forms/bulk_upload_lettings/guidance.rb
  4. 7
      app/models/forms/bulk_upload_sales/guidance.rb
  5. 34
      app/models/validations/sales/setup_validations.rb
  6. 3
      app/policies/user_policy.rb
  7. 2
      app/views/users/edit.html.erb
  8. 2
      config/credentials.yml.enc
  9. 9
      config/locales/en.yml
  10. 25
      config/locales/validations/sales/setup.en.yml
  11. 17
      spec/models/forms/bulk_upload_lettings/guidance_spec.rb
  12. 17
      spec/models/forms/bulk_upload_sales/guidance_spec.rb
  13. 27
      spec/policies/user_policy_spec.rb

2
Gemfile

@ -6,7 +6,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "3.1.4"
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails', branch: 'main'
gem "rails", "~> 7.0.8.3"
gem "rails", "~> 7.0.8.5"
# Use postgresql as the database for Active Record
gem "pg", "~> 1.1"
# Use Puma as the app server

128
Gemfile.lock

@ -1,71 +1,71 @@
GEM
remote: https://rubygems.org/
specs:
actioncable (7.0.8.4)
actionpack (= 7.0.8.4)
activesupport (= 7.0.8.4)
actioncable (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (7.0.8.4)
actionpack (= 7.0.8.4)
activejob (= 7.0.8.4)
activerecord (= 7.0.8.4)
activestorage (= 7.0.8.4)
activesupport (= 7.0.8.4)
actionmailbox (7.0.8.5)
actionpack (= 7.0.8.5)
activejob (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
actionmailer (7.0.8.4)
actionpack (= 7.0.8.4)
actionview (= 7.0.8.4)
activejob (= 7.0.8.4)
activesupport (= 7.0.8.4)
actionmailer (7.0.8.5)
actionpack (= 7.0.8.5)
actionview (= 7.0.8.5)
activejob (= 7.0.8.5)
activesupport (= 7.0.8.5)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
actionpack (7.0.8.4)
actionview (= 7.0.8.4)
activesupport (= 7.0.8.4)
actionpack (7.0.8.5)
actionview (= 7.0.8.5)
activesupport (= 7.0.8.5)
rack (~> 2.0, >= 2.2.4)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (7.0.8.4)
actionpack (= 7.0.8.4)
activerecord (= 7.0.8.4)
activestorage (= 7.0.8.4)
activesupport (= 7.0.8.4)
actiontext (7.0.8.5)
actionpack (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
actionview (7.0.8.4)
activesupport (= 7.0.8.4)
actionview (7.0.8.5)
activesupport (= 7.0.8.5)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (7.0.8.4)
activesupport (= 7.0.8.4)
activejob (7.0.8.5)
activesupport (= 7.0.8.5)
globalid (>= 0.3.6)
activemodel (7.0.8.4)
activesupport (= 7.0.8.4)
activemodel (7.0.8.5)
activesupport (= 7.0.8.5)
activemodel-serializers-xml (1.0.2)
activemodel (> 5.x)
activesupport (> 5.x)
builder (~> 3.1)
activerecord (7.0.8.4)
activemodel (= 7.0.8.4)
activesupport (= 7.0.8.4)
activestorage (7.0.8.4)
actionpack (= 7.0.8.4)
activejob (= 7.0.8.4)
activerecord (= 7.0.8.4)
activesupport (= 7.0.8.4)
activerecord (7.0.8.5)
activemodel (= 7.0.8.5)
activesupport (= 7.0.8.5)
activestorage (7.0.8.5)
actionpack (= 7.0.8.5)
activejob (= 7.0.8.5)
activerecord (= 7.0.8.5)
activesupport (= 7.0.8.5)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (7.0.8.4)
activesupport (7.0.8.5)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
@ -218,7 +218,7 @@ GEM
hashdiff (1.1.0)
html-attributes-utils (1.0.2)
activesupport (>= 6.1.4.4)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
iniparse (1.5.0)
@ -258,13 +258,13 @@ GEM
matrix (0.4.2)
method_source (1.1.0)
mini_mime (1.1.5)
minitest (5.24.1)
minitest (5.25.1)
msgpack (1.7.2)
multipart-post (2.4.1)
nested_form (0.3.2)
net-http (0.4.1)
uri
net-imap (0.4.14)
net-imap (0.4.17)
date
net-protocol
net-pop (0.1.2)
@ -274,11 +274,11 @@ GEM
net-smtp (0.5.0)
net-protocol
nio4r (2.7.3)
nokogiri (1.16.6-arm64-darwin)
nokogiri (1.16.7-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-darwin)
nokogiri (1.16.7-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.6-x86_64-linux)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
notifications-ruby-client (6.0.0)
jwt (>= 1.5, < 3)
@ -319,28 +319,28 @@ GEM
pundit (2.3.1)
activesupport (>= 3.0.0)
raabro (1.4.0)
racc (1.8.0)
rack (2.2.9)
racc (1.8.1)
rack (2.2.10)
rack-attack (6.7.0)
rack (>= 1.0, < 4)
rack-mini-profiler (2.3.4)
rack (>= 1.2.0)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.8.4)
actioncable (= 7.0.8.4)
actionmailbox (= 7.0.8.4)
actionmailer (= 7.0.8.4)
actionpack (= 7.0.8.4)
actiontext (= 7.0.8.4)
actionview (= 7.0.8.4)
activejob (= 7.0.8.4)
activemodel (= 7.0.8.4)
activerecord (= 7.0.8.4)
activestorage (= 7.0.8.4)
activesupport (= 7.0.8.4)
rails (7.0.8.5)
actioncable (= 7.0.8.5)
actionmailbox (= 7.0.8.5)
actionmailer (= 7.0.8.5)
actionpack (= 7.0.8.5)
actiontext (= 7.0.8.5)
actionview (= 7.0.8.5)
activejob (= 7.0.8.5)
activemodel (= 7.0.8.5)
activerecord (= 7.0.8.5)
activestorage (= 7.0.8.5)
activesupport (= 7.0.8.5)
bundler (>= 1.15.0)
railties (= 7.0.8.4)
railties (= 7.0.8.5)
rails-dom-testing (2.2.0)
activesupport (>= 5.0.0)
minitest
@ -354,9 +354,9 @@ GEM
nested_form (~> 0.3)
rails (>= 6.0, < 8)
turbo-rails (~> 1.0)
railties (7.0.8.4)
actionpack (= 7.0.8.4)
activesupport (= 7.0.8.4)
railties (7.0.8.5)
actionpack (= 7.0.8.5)
activesupport (= 7.0.8.5)
method_source
rake (>= 12.2)
thor (~> 1.0)
@ -464,7 +464,7 @@ GEM
stimulus-rails (1.3.3)
railties (>= 6.0.0)
strscan (3.1.0)
thor (1.3.1)
thor (1.3.2)
thread_safe (0.3.6)
timecop (0.9.8)
timeout (0.4.1)
@ -504,7 +504,7 @@ GEM
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.6.16)
zeitwerk (2.6.18)
PLATFORMS
arm64-darwin-21
@ -555,7 +555,7 @@ DEPENDENCIES
rack (>= 2.2.6.3)
rack-attack
rack-mini-profiler (~> 2.0)
rails (~> 7.0.8.3)
rails (~> 7.0.8.5)
rails_admin (~> 3.1)
redcarpet (~> 3.6)
redis (~> 4.8)

7
app/models/forms/bulk_upload_lettings/guidance.rb

@ -4,11 +4,18 @@ module Forms
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
include CollectionTimeHelper
attribute :year, :integer
attribute :referrer
attribute :organisation_id, :integer
def initialize(params)
super(params)
self.year = current_collection_start_year if year.nil?
end
def view_path
"bulk_upload_shared/guidance"
end

7
app/models/forms/bulk_upload_sales/guidance.rb

@ -4,11 +4,18 @@ module Forms
include ActiveModel::Model
include ActiveModel::Attributes
include Rails.application.routes.url_helpers
include CollectionTimeHelper
attribute :year, :integer
attribute :referrer
attribute :organisation_id, :integer
def initialize(params)
super(params)
self.year = current_collection_start_year if year.nil?
end
def view_path
"bulk_upload_shared/guidance"
end

34
app/models/validations/sales/setup_validations.rb

@ -20,7 +20,7 @@ module Validations::Sales::SetupValidations
return unless record.saledate && date_valid?("saledate", record) && !FeatureToggle.allow_future_form_use?
if record.saledate > Time.zone.today + 14.days
record.errors.add :saledate, I18n.t("validations.setup.saledate.later_than_14_days_after")
record.errors.add :saledate, I18n.t("validations.sales.setup.saledate.not_within.next_two_weeks")
end
end
@ -28,16 +28,16 @@ module Validations::Sales::SetupValidations
return unless record.saledate && date_valid?("saledate", record)
if merged_owning_organisation_inactive?(record)
record.errors.add :saledate, I18n.t("validations.setup.saledate.invalid_merged_organisations_saledate",
record.errors.add :saledate, I18n.t("validations.sales.setup.saledate.invalid.merged_organisations",
owning_organisation: record.owning_organisation.name,
owning_organisation_merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date),
owning_absorbing_organisation: record.owning_organisation.absorbing_organisation.name)
merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date),
absorbing_organisation: record.owning_organisation.absorbing_organisation.name)
end
if absorbing_owning_organisation_inactive?(record)
record.errors.add :saledate, I18n.t("validations.setup.saledate.invalid_absorbing_organisations_saledate",
record.errors.add :saledate, I18n.t("validations.sales.setup.saledate.invalid.absorbing_organisations",
owning_organisation: record.owning_organisation.name,
owning_organisation_available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date))
available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date))
end
end
@ -46,14 +46,14 @@ module Validations::Sales::SetupValidations
if record.owning_organisation.present?
if record.owning_organisation&.merge_date.present? && record.owning_organisation.merge_date <= record.saledate
record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_merged_organisation_sales",
record.errors.add :owning_organisation_id, I18n.t("validations.sales.setup.owning_organisation.inactive.merged_organisation",
owning_organisation: record.owning_organisation.name,
owning_organisation_merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date),
owning_absorbing_organisation: record.owning_organisation.absorbing_organisation.name)
merge_date: record.owning_organisation.merge_date.to_formatted_s(:govuk_date),
absorbing_organisation: record.owning_organisation.absorbing_organisation.name)
elsif record.owning_organisation&.absorbed_organisations.present? && record.owning_organisation.available_from.present? && record.owning_organisation.available_from.to_date > record.saledate.to_date
record.errors.add :owning_organisation_id, I18n.t("validations.setup.owning_organisation.inactive_absorbing_organisation_sales",
record.errors.add :owning_organisation_id, I18n.t("validations.sales.setup.owning_organisation.inactive.absorbing_organisation",
owning_organisation: record.owning_organisation.name,
owning_organisation_available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date))
available_from: record.owning_organisation.available_from.to_formatted_s(:govuk_date))
end
end
end
@ -77,24 +77,22 @@ private
end
def saledate_validation_error_message
current_end_year_long = current_collection_end_date.strftime("#{current_collection_end_date.day.ordinalize} %B %Y")
if FormHandler.instance.sales_in_crossover_period?
I18n.t(
"validations.setup.saledate.previous_and_current_collection_year",
"validations.sales.setup.saledate.must_be_within.previous_and_current_collection_year",
previous_start_year_short: previous_collection_start_date.strftime("%y"),
previous_end_year_short: previous_collection_end_date.strftime("%y"),
previous_start_year_long: previous_collection_start_date.strftime("#{previous_collection_start_date.day.ordinalize} %B %Y"),
current_end_year_short: current_collection_end_date.strftime("%y"),
current_end_year_long:,
current_end_year_long: current_collection_end_date.strftime("#{current_collection_end_date.day.ordinalize} %B %Y"),
)
else
I18n.t(
"validations.setup.saledate.current_collection_year",
"validations.sales.setup.saledate.must_be_within.current_collection_year",
current_start_year_short: current_collection_start_date.strftime("%y"),
current_end_year_short: current_collection_end_date.strftime("%y"),
current_start_year_long: current_collection_start_date.strftime("#{current_collection_start_date.day.ordinalize} %B %Y"),
current_end_year_long:,
current_end_year_short: current_collection_end_date.strftime("%y"),
current_end_year_long: current_collection_end_date.strftime("#{current_collection_end_date.day.ordinalize} %B %Y"),
)
end
end

3
app/policies/user_policy.rb

@ -17,8 +17,9 @@ class UserPolicy
].each do |method_name|
define_method method_name do
return true if @current_user.support?
return true if @current_user.data_coordinator? && @user.active?
@current_user.data_coordinator? && @user.active?
Rails.env.staging? && Rails.application.credentials[:staging_role_update_email_allowlist].include?(@current_user.email.split("@").last.downcase)
end
end

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

@ -51,7 +51,7 @@
<% end %>
<% end %>
<% if current_user.data_coordinator? || current_user.support? %>
<% if UserPolicy.new(current_user, @user).edit_roles? %>
<% roles = current_user.assignable_roles.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) } %>
<%= f.govuk_collection_radio_buttons :role,

2
config/credentials.yml.enc

@ -1 +1 @@
QGn9IiI91BaO4IGAtfy92FrNP46X9T2jJErRv+o/PRG9LrimEGeuOE+FwhArKZQ5cTipaDqo8u9Ajv45Kitv3c0GynOOvz0r3OjPRHO/p4hW8BFWQDv581cWWPsyZT2JO51zZ5LnwNFvWrjEB2q49YESgtfADPkJWmtx/By5Cg2/PVIRxvhGKOnheme5cih050wqg/43BdiF0PD9FDTZXJDLJg/QQ8nQYkvQe2jN4nM4mTVpkQkmzDKgGknmUWFfW3qWFzlsdMkdkPdeP9wLnJVbFTeyaaJT3wv6l19d2rKqo8iVvacdaQjRev+LVXqOsNAjVHwcPNQVq9s8pxG24HLk3aQ14Eyjf6tHAuZAV4jLnNqQtBQ0AIldWeOl6SKmlTom1P1tcLp9KpajEADplmWSwUktIGmaakFjk/ApYaUBiYTku2iLHMrT/xSc3jPj5W/ZggeJ0Ij6nuGYE1cmBxWGxda9PzOrDP8coEK9vPHiNeDDM1RoukVmf8gwDmshILi5EwIAsO2gJXM1wtPYMu41+H4/y3c0GIwgfv9QP11q+nqhG1MMcOrAUKGhypAS+M+uLwfGQudfQDKP9Zv3VCnOk3mkKlpIzMMD4UdJxQeE/8sfwIsEhWggEo3oa93ptbRdvJ7YYcVvmMmkVBxk0KWFprl4i/BkFHLWrKNl5LBOGA==--ziMOTnYBB5TDyXYU--3FJMs8e6R8lheqcqB8p8uQ==
M2+y4Ll2PwjN9IiCvliQ5Ytiy+/9bSepV2siwg6hvttLc63q0W4hbNobseAZAYqWLajrnJ7lm9AfT8CuBreHtwFsdQ/HV8NPrvzLB/P+X15MKLtb1Sg7bNjtW24uoE3zYrWILecpNygLc1ZXxgjka3yjc7XdV7MA3NR2/2zvkGREJvjbJlEn7036CWnNfN7PD0S57O1z+LqilrrhecWAmGeJRU2Ve2UZNoUExz865ovpk1enGReiU5+0jlNTIK3SCc75HH3grET6HkAbzsZvC763OkEkEQGVJeaytQ2cGkyk8t98nqGRq6fK9uAwKyGh6KwHH8BT++OOF3Re4Uf2A9boFdJ5AOwuV7ZK+OonPu7x/bThRmb+Sl057+L1pSrpILvFUzA3K8k34G9ZMHMLIX0/rHLEav+ToFFwBxARleiUdSgEv9txP0wU+7fPyuJlHJb7CIrC9dRQIeyM9RAIvxZYhP2KrTqm9eEyCJNttAWpYnXfnoxgbQEoQw94KOal/i26bK09TZNwv10oTYZqxB6PqfsQQ9wVIesO9v6uK3HQ2jVXeCb4caj1HWFOjFLhcDoAEFe6DUmjSdxf2tDQ90pwQKQ7IWi9jPOOQSVQ7VoCc1uD3cImDjsY/04sGbCdSpGt53E3Rn9UCGHdVhzzOXRhU4wQLBFEFin79KJ7q0m71jesGEpVNKI2s8aC+Ux8btSBu92JLS4b9zZHT13D729CW2T8--EZ5GxuRKaFfGdzCE--OZ1EwaObJ4ZF59N0JcJ7Dg==

9
config/locales/en.yml

@ -281,14 +281,7 @@ en:
intermediate_rent_product_name:
blank: "Enter name of other intermediate rent product."
saledate:
later_than_14_days_after: "Sale completion date must not be later than 14 days from today’s date."
current_collection_year:
"Enter a date within the %{current_start_year_short}/%{current_end_year_short} collection year, which is between %{current_start_year_long} and %{current_end_year_long}."
previous_and_current_collection_year:
"Enter a date within the %{previous_start_year_short}/%{previous_end_year_short} or %{previous_end_year_short}/%{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}."
year_not_two_digits: "Sale completion year must be 2 digits."
invalid_merged_organisations_saledate: "Enter a date when the owning organisation was active. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}."
invalid_absorbing_organisations_saledate: "Enter a date when the owning organisation was active. %{owning_organisation} became active on %{owning_organisation_available_from}."
type:
percentage_bought_must_be_at_least_threshold: "The minimum increase in equity while staircasing is %{threshold}% for this shared ownership type."
@ -341,8 +334,6 @@ en:
data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the owning organisation."
inactive_merged_organisation: "The owning organisation must be active on the tenancy start date. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}."
inactive_absorbing_organisation: "The owning organisation must be active on the tenancy start date. %{owning_organisation} became active on %{owning_organisation_available_from}."
inactive_merged_organisation_sales: "The owning organisation must be active on the sale completion date. %{owning_organisation} became inactive on %{owning_organisation_merge_date} and was replaced by %{owning_absorbing_organisation}."
inactive_absorbing_organisation_sales: "The owning organisation must be active on the sale completion date. %{owning_organisation} became active on %{owning_organisation_available_from}."
managing_organisation:
invalid: "Please select the owning organisation or managing organisation that you belong to."
data_sharing_agreement_not_signed: "The organisation must accept the Data Sharing Agreement before it can be selected as the managing organisation."

25
config/locales/validations/sales/setup.en.yml

@ -0,0 +1,25 @@
en:
validations:
sales:
setup:
saledate:
not_within:
next_two_weeks: "Sale completion date must not be later than 14 days from today’s date."
must_be_within:
current_collection_year:
"Enter a date within the %{current_start_year_short}/%{current_end_year_short} collection year, which is between %{current_start_year_long} and %{current_end_year_long}."
previous_and_current_collection_year:
"Enter a date within the %{previous_start_year_short}/%{previous_end_year_short} or %{previous_end_year_short}/%{current_end_year_short} collection years, which is between %{previous_start_year_long} and %{current_end_year_long}."
invalid:
merged_organisations:
"Enter a date when the owning organisation was active. %{owning_organisation} became inactive on %{merge_date} and was replaced by %{absorbing_organisation}."
absorbing_organisations:
"Enter a date when the owning organisation was active. %{owning_organisation} became active on %{available_from}."
owning_organisation:
inactive:
merged_organisation:
"The owning organisation must be active on the sale completion date. %{owning_organisation} became inactive on %{merge_date} and was replaced by %{absorbing_organisation}."
absorbing_organisation:
"The owning organisation must be active on the sale completion date. %{owning_organisation} became active on %{available_from}."

17
spec/models/forms/bulk_upload_lettings/guidance_spec.rb

@ -6,6 +6,7 @@ RSpec.describe Forms::BulkUploadLettings::Guidance do
subject(:bu_guidance) { described_class.new(year:, referrer:) }
let(:year) { 2024 }
let(:referrer) { nil }
describe "#back_path" do
context "when referrer is prepare-your-file" do
@ -40,4 +41,20 @@ RSpec.describe Forms::BulkUploadLettings::Guidance do
end
end
end
describe "year" do
context "when year is not provided" do
let(:year) { nil }
before do
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030)
# rubocop:enable RSpec/AnyInstance
end
it "is set to the current collection start year" do
expect(bu_guidance.year).to eq(2030)
end
end
end
end

17
spec/models/forms/bulk_upload_sales/guidance_spec.rb

@ -6,6 +6,7 @@ RSpec.describe Forms::BulkUploadSales::Guidance do
subject(:bu_guidance) { described_class.new(year:, referrer:) }
let(:year) { 2024 }
let(:referrer) { nil }
describe "#back_path" do
context "when referrer is prepare-your-file" do
@ -40,4 +41,20 @@ RSpec.describe Forms::BulkUploadSales::Guidance do
end
end
end
describe "year" do
context "when year is not provided" do
let(:year) { nil }
before do
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(2030)
# rubocop:enable RSpec/AnyInstance
end
it "is set to the current collection start year" do
expect(bu_guidance.year).to eq(2030)
end
end
end
end

27
spec/policies/user_policy_spec.rb

@ -4,7 +4,7 @@ require "rails_helper"
RSpec.describe UserPolicy do
subject(:policy) { described_class }
let(:data_provider) { FactoryBot.create(:user, :data_provider) }
let(:data_provider) { FactoryBot.create(:user, :data_provider, email: "provider@example.com") }
let(:data_coordinator) { FactoryBot.create(:user, :data_coordinator) }
let(:support) { FactoryBot.create(:user, :support) }
@ -63,6 +63,11 @@ RSpec.describe UserPolicy do
expect(policy).not_to permit(data_provider, data_provider)
end
it "as a provider it does not allow changing roles when user is in email allowlist" do
allow(Rails.application.credentials).to receive(:[]).with(:staging_role_update_email_allowlist).and_return(["example.com"])
expect(policy).not_to permit(data_provider, data_provider)
end
it "as a coordinator allows changing other user's roles" do
expect(policy).to permit(data_coordinator, data_provider)
end
@ -70,6 +75,26 @@ RSpec.describe UserPolicy do
it "as a support user allows changing other user's roles" do
expect(policy).to permit(support, data_provider)
end
context "when on staging" do
context "and user is in the email allowlist" do
it "allows changing roles" do
allow(Rails.env).to receive(:staging?).and_return(true)
allow(Rails.application.credentials).to receive(:[]).with(:staging_role_update_email_allowlist).and_return(["example.com"])
expect(policy).to permit(data_provider, data_provider)
end
end
context "and user is not in the email allowlist" do
it "does not allow changing roles" do
allow(Rails.env).to receive(:staging?).and_return(true)
allow(Rails.application.credentials).to receive(:[]).with(:staging_role_update_email_allowlist).and_return(["something.com"])
expect(policy).not_to permit(data_provider, data_provider)
end
end
end
end
permissions :edit_dpo? do

Loading…
Cancel
Save