BathHacked/energy-sparks

View on GitHub
app/views/admin/schools/removal.html.erb

Summary

Maintainability
Test Coverage
<% if @school.deleted? %>
  <h1><%= @school.name %></h1>
  <p>This school was deleted on <%= @school.removal_date %></p>
<% elsif @school.archived? %>
  <h1><%= @school.name %></h1>
  <p>This school has been archived.</p>
  <%= link_to 'Reenable school', reenable_admin_school_path(@school), method: :post, class: 'btn btn-success' %>
<% elsif @school_remover.school_ready? %>
  <h1>Removing <%= @school.name %></h1>
  <% if @school.users.any? %>
    <h2>User status</h2>
    <% unless @school_remover.users_ready? %>
      <%= component 'notice', status: :negative, classes: 'mb-4' do %>
        <p>School cannot be removed while it has active users.</p>
      <% end %>
    <% end %>
    <p>Current users:</p>
    <ol>
      <% @school.users.each do |user| %>
        <li><%= user.email %><%= user.access_locked? ? ' (LOCKED)' : '' %></li>
      <% end %>
    </ol>
    <% unless @school_remover.users_ready? %>
      <div class="mt-4">
        <p>Locking a user account will prevent the user from logging in again. If they are
        linked to other schools, they'll still be able to login but will be removed from
        this school.</p>
        <%= button_to 'Lock user accounts', deactivate_users_admin_school_path(@school), method: :post, class: 'btn btn-success'%>
      </div>
    <% end %>
  <% end %>

  <% if @school.meters.any? %>
    <h2>Meter status</h2>
    <% unless @school_remover.meters_ready? %>
      <%= component 'notice', status: :negative, classes: 'mb-4' do %>
        <p>School cannot be removed while it has active meters</p>
      <% end %>
    <% end %>
    <p>Current meters:</p>
    <ol>
      <% @school.meters.each do |meter| %>
        <li><%= meter.mpan_mprn %><%= meter.active? ? '' : ' (INACTIVE)' %></li>
      <% end %>
    </ol>
  <% end %>

  <% unless @school_remover.meters_ready? %>
    <div class="mt-4">
      <p>Archiving meters will mark them all as inactive. Validated data will be removed, but unvalidated
        data will remain linked to the meter.</p>
      <%= button_to 'Archive meters', archive_meters_admin_school_path(@school), method: :post, class: 'btn btn-success'%>
    </div>
    <div class="mt-4">
      <p>
        Deactivating and deleting meter data, will mark meters as inactive. Validated data will be removed and
        the unvalidated data will be unlinked from the meter.
      </p>
      <%= button_to 'Deactivate all meters and delete data', delete_meters_admin_school_path(@school), method: :post, class: 'btn btn-success'%>
    </div>
  <% end %>

  <% if @school.active && @school_remover.can_remove_school? %>
    <h2>School ready for removal</h2>
    <div class="mt-4">
      <p>Archiving a school will mark it as inactive and disable data processing. An archive school can be later
      re-enabled</p>
      <%= button_to 'Archive school', archive_admin_school_path(@school), method: :post, class: 'btn btn-success'%>
    </div>
    <div class="mt-4">
      <p>Deleting a school will do the same, but also flag the school as deleted. A deleted school cannot be re-enabled.</p>
      <%= button_to 'Delete school', delete_admin_school_path(@school), method: :post, class: 'btn btn-success'%>
    </div>
  <% end %>

<% else %>
  <h1><%= @school.name %></h1>
  <p>This school is still visible so cannot be deleted or archived.</p>
  <p>Mark school has not visible to hide it from the website.</p>
<% end %>