Browse Source

Add data field

pull/435/head
baarkerlounger 3 years ago
parent
commit
22e116aa21
  1. 8
      app/models/user.rb
  2. 7
      db/migrate/20220329125601_add_key_contact_field_to_user.rb
  3. 1
      db/schema.rb
  4. 10
      spec/models/user_spec.rb

8
app/models/user.rb

@ -37,6 +37,14 @@ class User < ApplicationRecord
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_key_contact?
is_key_contact
end
def is_key_contact!
update(is_key_contact: true)
end
def is_data_protection_officer? def is_data_protection_officer?
is_dpo is_dpo
end end

7
db/migrate/20220329125601_add_key_contact_field_to_user.rb

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

1
db/schema.rb

@ -316,6 +316,7 @@ ActiveRecord::Schema[7.0].define(version: 202202071123100) do
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.boolean "is_dpo", default: false
t.boolean "is_key_contact", 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"

10
spec/models/user_spec.rb

@ -47,13 +47,17 @@ RSpec.describe User, type: :model do
expect(user.data_coordinator?).to be false expect(user.data_coordinator?).to be false
end end
it "is not a key contact by default" do
expect(user.is_key_contact?).to be false
end
it "is not a data protection officer by default" do it "is not a data protection officer by default" do
expect(user.is_data_protection_officer?).to be false expect(user.is_data_protection_officer?).to be false
end end
it "can be set to data protection officer" do it "can be set to key contact" do
expect { user.is_data_protection_officer! } expect { user.is_key_contact! }
.to change { user.reload.is_data_protection_officer? }.from(false).to(true) .to change { user.reload.is_key_contact? }.from(false).to(true)
end end
end end

Loading…
Cancel
Save