Browse Source

Fix user view for no role (#632)

* Nil safe humanizing

* Remove data accessor role
pull/634/head
baarkerlounger 3 years ago committed by GitHub
parent
commit
2f2cd71141
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/user.rb
  2. 2
      app/views/users/show.html.erb
  3. 16
      spec/models/user_spec.rb
  4. 13
      spec/requests/users_controller_spec.rb
  5. 10
      spec/services/imports/user_import_service_spec.rb

1
app/models/user.rb

@ -24,7 +24,6 @@ class User < ApplicationRecord
has_one_time_password(encrypted: true) has_one_time_password(encrypted: true)
ROLES = { ROLES = {
data_accessor: 0,
data_provider: 1, data_provider: 1,
data_coordinator: 2, data_coordinator: 2,
support: 99, support: 99,

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

@ -63,7 +63,7 @@
<%= summary_list.row do |row| <%= summary_list.row do |row|
row.key { "Role" } row.key { "Role" }
row.value { @user.role.humanize } row.value { @user.role&.humanize }
if can_edit_roles?(@user, current_user) if can_edit_roles?(@user, current_user)
row.action( row.action(
visually_hidden_text: "role", visually_hidden_text: "role",

16
spec/models/user_spec.rb

@ -33,12 +33,12 @@ RSpec.describe User, type: :model do
end end
it "has case logs through their organisation" do it "has case logs through their organisation" do
expect(user.case_logs.to_a).to eq([owned_case_log, managed_case_log]) expect(user.case_logs.to_a).to match_array([owned_case_log, managed_case_log])
end end
it "has case log status helper methods" do it "has case log status helper methods" do
expect(user.completed_case_logs.to_a).to eq([owned_case_log]) expect(user.completed_case_logs.to_a).to match_array([owned_case_log])
expect(user.not_completed_case_logs.to_a).to eq([managed_case_log]) expect(user.not_completed_case_logs.to_a).to match_array([managed_case_log])
end end
it "has a role" do it "has a role" do
@ -103,20 +103,11 @@ RSpec.describe User, type: :model do
end end
end end
context "when the user is a data accessor" do
let(:user) { FactoryBot.create(:user, :data_accessor) }
it "cannot assign roles" do
expect(user.assignable_roles).to eq({})
end
end
context "when the user is a data coordinator" do context "when the user is a data coordinator" do
let(:user) { FactoryBot.create(:user, :data_coordinator) } let(:user) { FactoryBot.create(:user, :data_coordinator) }
it "can assign all roles except support" do it "can assign all roles except support" do
expect(user.assignable_roles).to eq({ expect(user.assignable_roles).to eq({
data_accessor: 0,
data_provider: 1, data_provider: 1,
data_coordinator: 2, data_coordinator: 2,
}) })
@ -141,7 +132,6 @@ RSpec.describe User, type: :model do
it "can assign all roles" do it "can assign all roles" do
expect(user.assignable_roles).to eq({ expect(user.assignable_roles).to eq({
data_accessor: 0,
data_provider: 1, data_provider: 1,
data_coordinator: 2, data_coordinator: 2,
support: 99, support: 99,

13
spec/requests/users_controller_spec.rb

@ -164,6 +164,19 @@ RSpec.describe UsersController, type: :request do
end end
end end
context "when the user does not have a role because they are a data protection officer only" do
let(:user) { FactoryBot.create(:user, role: nil) }
before do
sign_in user
get "/users/#{user.id}", headers:, params: {}
end
it "shows their details" do
expect(response).to have_http_status(:ok)
end
end
context "when the current user does not match the user ID" do context "when the current user does not match the user ID" do
before do before do
sign_in user sign_in user

10
spec/services/imports/user_import_service_spec.rb

@ -58,16 +58,6 @@ RSpec.describe Imports::UserImportService do
end end
end end
context "when the user is a data accessor" do
let(:old_user_id) { "b7829b1a5dfb68bb1e01c08445830c0add40907c" }
it "sets their role correctly" do
FactoryBot.create(:organisation, old_org_id:)
import_service.create_users("user_directory")
expect(User.find_by(old_user_id:)).to be_data_accessor
end
end
context "when the user is a data protection officer" do context "when the user is a data protection officer" do
let(:old_user_id) { "10c887710550844e2551b3e0fb88dc9b4a8a642b" } let(:old_user_id) { "10c887710550844e2551b3e0fb88dc9b4a8a642b" }

Loading…
Cancel
Save