Browse Source
* Users have roles * Add role to active admin * Add role to users table * Redirect organisation show to details * Remove users tab for data providerspull/141/head
baarkerlounger
3 years ago
committed by
GitHub
19 changed files with 259 additions and 97 deletions
@ -0,0 +1,20 @@ |
|||||||
|
module TabNavHelper |
||||||
|
include GovukLinkHelper |
||||||
|
|
||||||
|
def user_cell(user) |
||||||
|
[govuk_link_to(user.name, user), user.email].join("\n") |
||||||
|
end |
||||||
|
|
||||||
|
def org_cell(user) |
||||||
|
role = "<span class='app-!-colour-muted'>#{user.role.to_s.humanize}</span>" |
||||||
|
[user.organisation.name, role].join("\n") |
||||||
|
end |
||||||
|
|
||||||
|
def tab_items(user) |
||||||
|
items = [{ name: t("Details"), url: details_organisation_path(user.organisation) }] |
||||||
|
if user.data_coordinator? |
||||||
|
items << { name: t("Users"), url: users_organisation_path(user.organisation) } |
||||||
|
end |
||||||
|
items |
||||||
|
end |
||||||
|
end |
@ -1,12 +0,0 @@ |
|||||||
module UserTableHelper |
|
||||||
include GovukLinkHelper |
|
||||||
|
|
||||||
def user_cell(user) |
|
||||||
[govuk_link_to(user.name, user), user.email].join("\n") |
|
||||||
end |
|
||||||
|
|
||||||
def org_cell(user) |
|
||||||
role = "<span class='app-!-colour-muted'>#{user.role}</span>" |
|
||||||
[user.organisation.name, role].join("\n") |
|
||||||
end |
|
||||||
end |
|
@ -0,0 +1,7 @@ |
|||||||
|
module Constants::User |
||||||
|
ROLES = { |
||||||
|
"data_accessor" => 0, |
||||||
|
"data_provider" => 1, |
||||||
|
"data_coordinator" => 2, |
||||||
|
}.freeze |
||||||
|
end |
@ -0,0 +1,15 @@ |
|||||||
|
class ChangeUserRoleToEnum < ActiveRecord::Migration[6.1] |
||||||
|
def up |
||||||
|
change_table :users, bulk: true do |t| |
||||||
|
t.remove :role |
||||||
|
t.column :role, :integer |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
def down |
||||||
|
change_table :users, bulk: true do |t| |
||||||
|
t.remove :role |
||||||
|
t.column :role, :string |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,40 @@ |
|||||||
|
require "rails_helper" |
||||||
|
|
||||||
|
RSpec.describe TabNavHelper do |
||||||
|
let(:organisation) { FactoryBot.create(:organisation) } |
||||||
|
let(:user) { FactoryBot.build(:user, organisation: organisation) } |
||||||
|
|
||||||
|
describe "#user_cell" do |
||||||
|
it "returns user link and email separated by a newline character" do |
||||||
|
expected_html = "<a class=\"govuk-link\" href=\"/users\">Danny Rojas</a>\n#{user.email}" |
||||||
|
expect(user_cell(user)).to match(expected_html) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#org_cell" 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>" |
||||||
|
expect(org_cell(user)).to match(expected_html) |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
describe "#tab_items" do |
||||||
|
context "user is a data_coordinator" do |
||||||
|
let(:user) { FactoryBot.build(:user, :data_coordinator, organisation: organisation) } |
||||||
|
it "returns details and user tabs" do |
||||||
|
result = tab_items(user).map { |i| i[:name] } |
||||||
|
expect(result.count).to eq(2) |
||||||
|
expect(result.first).to match("Details") |
||||||
|
expect(result.second).to match("Users") |
||||||
|
end |
||||||
|
end |
||||||
|
|
||||||
|
context "user is a data_provider" do |
||||||
|
it "returns details tab only" do |
||||||
|
result = tab_items(user).map { |i| i[:name] } |
||||||
|
expect(result.count).to eq(1) |
||||||
|
expect(result.first).to match("Details") |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -1,19 +0,0 @@ |
|||||||
require "rails_helper" |
|
||||||
|
|
||||||
RSpec.describe UserTableHelper do |
|
||||||
let(:user) { FactoryBot.build(:user) } |
|
||||||
|
|
||||||
describe "#user_cell" do |
|
||||||
it "returns user link and email separated by a newline character" do |
|
||||||
expected_html = "<a class=\"govuk-link\" href=\"/users\">Danny Rojas</a>\n#{user.email}" |
|
||||||
expect(user_cell(user)).to match(expected_html) |
|
||||||
end |
|
||||||
end |
|
||||||
|
|
||||||
describe "#org_cell" 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>" |
|
||||||
expect(org_cell(user)).to match(expected_html) |
|
||||||
end |
|
||||||
end |
|
||||||
end |
|
@ -1,58 +1,112 @@ |
|||||||
require "rails_helper" |
require "rails_helper" |
||||||
|
|
||||||
RSpec.describe OrganisationsController, type: :request do |
RSpec.describe OrganisationsController, type: :request do |
||||||
let(:user) { FactoryBot.create(:user) } |
|
||||||
let(:organisation) { user.organisation } |
let(:organisation) { user.organisation } |
||||||
let(:headers) { { "Accept" => "text/html" } } |
let(:headers) { { "Accept" => "text/html" } } |
||||||
let(:page) { Capybara::Node::Simple.new(response.body) } |
let(:page) { Capybara::Node::Simple.new(response.body) } |
||||||
|
|
||||||
context "details tab" do |
describe "#show" do |
||||||
|
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||||
|
|
||||||
before do |
before do |
||||||
sign_in user |
sign_in user |
||||||
get "/organisations/#{organisation.id}", headers: headers, params: {} |
get "/organisations/#{organisation.id}", headers: headers, params: {} |
||||||
end |
end |
||||||
|
|
||||||
it "shows the tab navigation" do |
it "redirects to details" do |
||||||
expected_html = "<nav class=\"app-tab-navigation\"" |
expect(response).to have_http_status(:redirect) |
||||||
expect(response.body).to include(expected_html) |
|
||||||
end |
end |
||||||
|
end |
||||||
|
|
||||||
|
context "As a data coordinator user" do |
||||||
|
let(:user) { FactoryBot.create(:user, :data_coordinator) } |
||||||
|
|
||||||
|
context "details tab" do |
||||||
|
before do |
||||||
|
sign_in user |
||||||
|
get "/organisations/#{organisation.id}/details", headers: headers, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the tab navigation" do |
||||||
|
expected_html = "<nav class=\"app-tab-navigation\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
it "shows a summary list of org details" do |
it "shows a summary list of org details" do |
||||||
expected_html = "<dl class=\"govuk-summary-list\"" |
expected_html = "<dl class=\"govuk-summary-list\"" |
||||||
expect(response.body).to include(expected_html) |
expect(response.body).to include(expected_html) |
||||||
expect(response.body).to include(organisation.name) |
expect(response.body).to include(organisation.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "has a hidden header title" do |
||||||
|
expected_html = "<h2 class=\"govuk-visually-hidden\"> Details" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
end |
end |
||||||
|
|
||||||
it "has a hidden header title" do |
context "users tab" do |
||||||
expected_html = "<h2 class=\"govuk-visually-hidden\"> Details" |
before do |
||||||
expect(response.body).to include(expected_html) |
sign_in user |
||||||
|
get "/organisations/#{organisation.id}/users", headers: headers, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "shows the tab navigation" do |
||||||
|
expected_html = "<nav class=\"app-tab-navigation\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a new user button" do |
||||||
|
expect(page).to have_link("Invite user") |
||||||
|
end |
||||||
|
|
||||||
|
it "shows a table of users" do |
||||||
|
expected_html = "<table class=\"govuk-table\"" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
expect(response.body).to include(user.email) |
||||||
|
end |
||||||
|
|
||||||
|
it "has a hidden header title" do |
||||||
|
expected_html = "<h2 class=\"govuk-visually-hidden\"> Users" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
end |
end |
||||||
end |
end |
||||||
|
|
||||||
context "users tab" do |
context "As a data provider user" do |
||||||
before do |
let(:user) { FactoryBot.create(:user) } |
||||||
sign_in user |
|
||||||
get "/organisations/#{organisation.id}/users", headers: headers, params: {} |
|
||||||
end |
|
||||||
|
|
||||||
it "shows the tab navigation" do |
context "details tab" do |
||||||
expected_html = "<nav class=\"app-tab-navigation\"" |
before do |
||||||
expect(response.body).to include(expected_html) |
sign_in user |
||||||
end |
get "/organisations/#{organisation.id}/details", headers: headers, params: {} |
||||||
|
end |
||||||
|
|
||||||
it "shows a new user button" do |
it "shows the tab navigation" do |
||||||
expect(page).to have_link("Invite user") |
expected_html = "<nav class=\"app-tab-navigation\"" |
||||||
end |
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
|
|
||||||
it "shows a table of users" do |
it "shows a summary list of org details" do |
||||||
expected_html = "<table class=\"govuk-table\"" |
expected_html = "<dl class=\"govuk-summary-list\"" |
||||||
expect(response.body).to include(expected_html) |
expect(response.body).to include(expected_html) |
||||||
expect(response.body).to include(user.email) |
expect(response.body).to include(organisation.name) |
||||||
|
end |
||||||
|
|
||||||
|
it "has a hidden header title" do |
||||||
|
expected_html = "<h2 class=\"govuk-visually-hidden\"> Details" |
||||||
|
expect(response.body).to include(expected_html) |
||||||
|
end |
||||||
end |
end |
||||||
|
|
||||||
it "has a hidden header title" do |
context "users tab" do |
||||||
expected_html = "<h2 class=\"govuk-visually-hidden\"> Users" |
before do |
||||||
expect(response.body).to include(expected_html) |
sign_in user |
||||||
|
get "/organisations/#{organisation.id}/users", headers: headers, params: {} |
||||||
|
end |
||||||
|
|
||||||
|
it "should return unauthorised 401" do |
||||||
|
expect(response).to have_http_status(:unauthorized) |
||||||
|
end |
||||||
end |
end |
||||||
end |
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue