Browse Source

Change data protection officer from role to attribute

pull/428/head
baarkerlounger 3 years ago
parent
commit
9d5f7d652c
  1. 9
      app/models/user.rb
  2. 4
      app/services/imports/data_protection_confirmation_import_service.rb
  3. 7
      db/migrate/20220328105332_change_dpo_to_attribute.rb
  4. 1
      db/schema.rb
  5. 2
      spec/factories/user.rb
  6. 9
      spec/models/user_spec.rb
  7. 2
      spec/services/imports/data_protection_confirmation_import_service_spec.rb

9
app/models/user.rb

@ -14,7 +14,6 @@ class User < ApplicationRecord
data_accessor: 0, data_accessor: 0,
data_provider: 1, data_provider: 1,
data_coordinator: 2, data_coordinator: 2,
data_protection_officer: 3,
}.freeze }.freeze
enum role: ROLES enum role: ROLES
@ -37,4 +36,12 @@ class User < ApplicationRecord
def reset_password_notify_template def reset_password_notify_template
last_sign_in_at ? RESET_PASSWORD_TEMPLATE_ID : SET_PASSWORD_TEMPLATE_ID last_sign_in_at ? RESET_PASSWORD_TEMPLATE_ID : SET_PASSWORD_TEMPLATE_ID
end end
def is_data_protection_officer?
is_dpo
end
def is_data_protection_officer!
update!(is_dpo: true)
end
end end

4
app/services/imports/data_protection_confirmation_import_service.rb

@ -11,14 +11,14 @@ module Imports
dp_officer = User.find_by( dp_officer = User.find_by(
name: record_field_value(xml_document, "dp-user"), name: record_field_value(xml_document, "dp-user"),
organisation: org, organisation: org,
role: "data_protection_officer", is_dpo: true,
) )
if dp_officer.blank? if dp_officer.blank?
dp_officer = User.new( dp_officer = User.new(
name: record_field_value(xml_document, "dp-user"), name: record_field_value(xml_document, "dp-user"),
organisation: org, organisation: org,
role: "data_protection_officer", is_dpo: true,
encrypted_password: SecureRandom.hex(10), encrypted_password: SecureRandom.hex(10),
) )
dp_officer.save!(validate: false) dp_officer.save!(validate: false)

7
db/migrate/20220328105332_change_dpo_to_attribute.rb

@ -0,0 +1,7 @@
class ChangeDpoToAttribute < ActiveRecord::Migration[7.0]
def change
change_table :users, bulk: true do |t|
t.column :is_dpo, :boolean, default: false
end
end
end

1
db/schema.rb

@ -315,6 +315,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
t.integer "failed_attempts", default: 0 t.integer "failed_attempts", default: 0
t.string "unlock_token" t.string "unlock_token"
t.datetime "locked_at", precision: nil t.datetime "locked_at", precision: nil
t.boolean "is_dpo", default: false
t.string "phone" t.string "phone"
t.index ["email"], name: "index_users_on_email", unique: true t.index ["email"], name: "index_users_on_email", unique: true
t.index ["organisation_id"], name: "index_users_on_organisation_id" t.index ["organisation_id"], name: "index_users_on_organisation_id"

2
spec/factories/user.rb

@ -9,7 +9,7 @@ FactoryBot.define do
role { "data_coordinator" } role { "data_coordinator" }
end end
trait :data_protection_officer do trait :data_protection_officer do
role { "data_protection_officer" } is_dpo { true }
end end
created_at { Time.zone.now } created_at { Time.zone.now }
updated_at { Time.zone.now } updated_at { Time.zone.now }

9
spec/models/user_spec.rb

@ -46,6 +46,15 @@ RSpec.describe User, type: :model do
expect(user.data_provider?).to be true expect(user.data_provider?).to be true
expect(user.data_coordinator?).to be false expect(user.data_coordinator?).to be false
end end
it "is not a data protection officer by default" do
expect(user.is_data_protection_officer?).to be false
end
it "can be set to data protection officer" do
expect { user.is_data_protection_officer! }
.to change { user.reload.is_data_protection_officer? }.from(false).to(true)
end
end end
describe "paper trail" do describe "paper trail" do

2
spec/services/imports/data_protection_confirmation_import_service_spec.rb

@ -34,7 +34,7 @@ RSpec.describe Imports::DataProtectionConfirmationImportService do
it "creates a data protection officer without sign in credentials" do it "creates a data protection officer without sign in credentials" do
expect { import_service.create_data_protection_confirmations("data_protection_directory") } expect { import_service.create_data_protection_confirmations("data_protection_directory") }
.to change(User, :count).by(1) .to change(User, :count).by(1)
data_protection_officer = User.find_by(organisation:, role: "data_protection_officer") data_protection_officer = User.find_by(organisation:, is_dpo: true)
expect(data_protection_officer.email).to eq("") expect(data_protection_officer.email).to eq("")
end end

Loading…
Cancel
Save