Browse Source

Show if user is deactivated and fix form

pull/624/head
Kat 3 years ago
parent
commit
ccb2e51869
  1. 6
      app/views/users/deactivate.html.erb
  2. 4
      app/views/users/show.html.erb
  3. 11
      spec/requests/users_controller_spec.rb

6
app/views/users/deactivate.html.erb

@ -1,7 +1,7 @@
<% content_for :title, current_user == @user ? "Your account" : "#{@user.name.presence || @user.email}’s account" %> <% content_for :title, current_user == @user ? "Your account" : "#{@user.name.presence || @user.email}’s account" %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<%= form_with model: @user, url: user_path(@user), method: "post", local: true do |f| %> <%= form_for(@user, as: :user, html: { method: :patch }) do |f| %>
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-l"> <h1 class="govuk-heading-l">
<span class="govuk-caption-l"><%= @user.name %></span> <span class="govuk-caption-l"><%= @user.name %></span>
@ -10,6 +10,10 @@
<p>Deactivating this user will mean they can no longer access this service to submit CORE data.</p> <p>Deactivating this user will mean they can no longer access this service to submit CORE data.</p>
<p>Any logs this user has already submitted will not be affected.</p> <p>Any logs this user has already submitted will not be affected.</p>
<input type="hidden" id="<%= @user.id %>" name="active" value=false> <input type="hidden" id="<%= @user.id %>" name="active" value=false>
<%= f.govuk_text_field :active,
value: false,
hidden: true %>
<%= f.govuk_submit "I’m sure - deactivate this user" %> <%= f.govuk_submit "I’m sure - deactivate this user" %>
<p class="govuk-body"> <p class="govuk-body">
<%= govuk_link_to("No - I’ve changed my mind", user_path(@user)) %> <%= govuk_link_to("No - I’ve changed my mind", user_path(@user)) %>

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

@ -6,7 +6,11 @@
<%= content_for(:title) %> <%= content_for(:title) %>
</h1> </h1>
<% if can_toggle_active?(@user, current_user) %> <% if can_toggle_active?(@user, current_user) %>
<% if @user.active? %>
<%= govuk_link_to "Deactivate user", "/users/#{@user.id}/deactivate" %> <%= govuk_link_to "Deactivate user", "/users/#{@user.id}/deactivate" %>
<% else %>
<span class="app-!-colour-muted govuk-!-margin-right-2">This user has been deactivated.</span>
<% end %>
<% end %> <% end %>
<h2 class="govuk-heading-m"> <h2 class="govuk-heading-m">

11
spec/requests/users_controller_spec.rb

@ -505,6 +505,17 @@ RSpec.describe UsersController, type: :request do
it "allows deactivating the user" do it "allows deactivating the user" do
expect(page).to have_link("Deactivate user", href: "/users/#{other_user.id}/deactivate") expect(page).to have_link("Deactivate user", href: "/users/#{other_user.id}/deactivate")
end end
context "when user is deactivated" do
before do
other_user.update!(active: false)
get "/users/#{other_user.id}", headers:, params: {}
end
it "shows if user is not active" do
expect(page).to have_content("This user has been deactivated.")
end
end
end end
context "when the user is not part of the same organisation as the current user" do context "when the user is not part of the same organisation as the current user" do

Loading…
Cancel
Save