feat(manager#outdated_procedure): allow super admin to enable procedure_expires_when_termine_enabled for old procedure

revew(typo): various typo, tx christophe :-)

fix(spec): due to typo fixes
This commit is contained in:
Martin 2022-08-16 16:53:41 +02:00
parent d878ae645f
commit 2f5528398f
11 changed files with 280 additions and 0 deletions

View file

@ -0,0 +1,39 @@
module Manager
class OutdatedProceduresController < Manager::ApplicationController
def index
@records_per_page = params[:records_per_page] || "10"
resources = Procedure.all
.where(procedure_expires_when_termine_enabled: false)
.order(created_at: :asc)
.page(params[:_page])
.per(@records_per_page)
page = Administrate::Page::Collection.new(dashboard)
render locals: {
resources: resources,
page: page,
show_search_bar: false
}
end
def bulk_update
procedure_ids = params[:procedure][:ids].filter { |_id, selected| selected == "1" }
.keys
successes = procedure_ids.map do |id|
procedure = Procedure.find(id)
success = procedure.update(procedure_expires_when_termine_enabled: true)
if success
administration_emails = procedure.administrateurs.map(&:email)
administration_emails.each do |email|
AdministrateurMailer.notify_procedure_expires_when_termine_forced(email, procedure).deliver_later
end
end
success
end
flash[:notice] = "L'archivage automatique a été activé sur les #{successes.size} procédure(s) choisies"
redirect_to manager_outdated_procedures_path
end
end
end

View file

@ -0,0 +1,13 @@
require "administrate/base_dashboard"
class OutdatedProcedureDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = {
id: Field::Number,
libelle: Field::String,
created_at: Field::DateTime,
dossiers_close_to_expiration: Field::Number
}.freeze
COLLECTION_ATTRIBUTES = [:id, :libelle, :created_at, :dossiers_close_to_expiration].freeze
COLLECTION_FILTERS = {}.freeze
SHOW_PAGE_ATTRIBUTES = {}
end

View file

@ -12,4 +12,13 @@ class AdministrateurMailer < ApplicationMailer
subject: @subject,
reply_to: CONTACT_EMAIL)
end
def notify_procedure_expires_when_termine_forced(user_email, procedure)
@procedure = procedure
@subject = "La suppression automatique des dossiers a été activée sur la démarche #{procedure.libelle}"
mail(to: user_email,
subject: @subject,
reply_to: CONTACT_EMAIL)
end
end

View file

@ -0,0 +1,4 @@
class OutdatedProcedure
extend ActiveModel::Naming
extend ActiveModel::Translation
end

View file

@ -351,6 +351,10 @@ class Procedure < ApplicationRecord
end
end
def dossiers_close_to_expiration
dossiers.close_to_expiration.count
end
def publish_or_reopen!(administrateur)
Procedure.transaction do
if brouillon?

View file

@ -0,0 +1,17 @@
- content_for(:title, "Suppression des dossiers automatique activée")
%p
Bonjour,
%p
Le règlement général sur la protection des données (RGPD) responsabilise les organismes publics et privés qui traitent leurs données.
%p
Dans le cadre du respect du RGPD, nous (la plateforme #{APPLICATION_NAME}) venons d'activer la suppression automatique des dossiers sur la démarche : "#{@procedure.libelle}".
%p
Vous pouvez d'ores et déjà archiver ces données en accédant à
= link_to("notre systeme d'archivage pour les admnistrateurs de démarche",admin_procedures_archived_url(@procedure) )
\.
= render partial: "layouts/mailers/signature"

View file

@ -0,0 +1,110 @@
<%#
# Collection
This partial is used on the `index` and `show` pages
to display a collection of resources in an HTML table.
## Local variables:
- `collection_presenter`:
An instance of [Administrate::Page::Collection][1].
The table presenter uses `ResourceDashboard::COLLECTION_ATTRIBUTES` to determine
the columns displayed in the table
- `resources`:
An ActiveModel::Relation collection of resources to be displayed in the table.
By default, the number of resources is limited by pagination
or by a hard limit to prevent excessive page load times
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
%>
<div class="bt-3">
<%= form_with(url: manager_outdated_procedures_path, method: :get) do |f| %>
<h2>Nombre de démarches sans auto archivage des dossiers: <%= @records_per_page %></h2>
<h2>Nombre de dossiers archivable parmis ces démarches: <%= resources.sum(&:dossiers_close_to_expiration) %> </h2>
<%= f.select :records_per_page, options_for_select([["10", "10"], ["100", "100"], ["1000", "1000"]], @records_per_page) %>
<%= f.submit "Mettre a jour le nombre de démarche a archiver", class: 'button button--nav' %>
<% end %>
</div>
<%= form_with(url: bulk_update_manager_outdated_procedures_path, method: :patch) do |f| %>
<table aria-labelledby="<%= table_title %>">
<thead data-controller="outdated" >
<tr>
<th></th>
<% collection_presenter.attribute_types.each do |attr_name, attr_type| %>
<th class="cell-label
cell-label--<%= attr_type.html_class %>
cell-label--<%= collection_presenter.ordered_html_class(attr_name) %>"
scope="col"
role="columnheader"
aria-sort="<%= sort_order(collection_presenter.ordered_html_class(attr_name)) %>">
<%= link_to(sanitized_order_params(page, collection_field_name).merge(
collection_presenter.order_params_for(attr_name, key: collection_field_name)
)) do %>
<%= t(
"helpers.label.#{collection_presenter.resource_name}.#{attr_name}",
default: resource_class.human_attribute_name(attr_name),
).titleize %>
<% if collection_presenter.ordered_by?(attr_name) %>
<span class="cell-label__sort-indicator cell-label__sort-indicator--<%= collection_presenter.ordered_html_class(attr_name) %>">
<svg aria-hidden="true">
<use xlink:href="#icon-up-caret" />
</svg>
</span>
<% end %>
<% end %>
</th>
<% end %>
<% [valid_action?(:edit, collection_presenter.resource_name),
valid_action?(:destroy, collection_presenter.resource_name)].count(true).times do %>
<th scope="col"></th>
<% end %>
</tr>
</thead>
<tbody>
<% resources.each do |resource| %>
<tr class=""
<% if show_action? :show, resource %>
<%= %(tabindex=0 role=link data-url=#{polymorphic_path([namespace, resource])}) %>
<% end %>
>
<td><%= f.check_box "procedure[ids][#{resource.id}]", checked: true %></td>
<% collection_presenter.attributes_for(resource).each do |attribute| %>
<td class="js-table-row cell-data cell-data--<%= attribute.html_class %>">
<% if show_action? :show, resource -%>
<a href="<%= polymorphic_path([namespace, resource]) -%>"
tabindex="-1"
class="action-show"
>
<%= render_field attribute %>
</a>
<% else %>
<%= render_field attribute %>
<% end -%>
</td>
<% end %>
<% if valid_action? :edit, collection_presenter.resource_name %>
<td><%= link_to(
t("administrate.actions.edit"),
[:edit, namespace, resource],
class: "action-edit",
) if show_action? :edit, resource%></td>
<% end %>
<% if valid_action? :destroy, collection_presenter.resource_name %>
<td><%= link_to(
t("administrate.actions.destroy"),
[namespace, resource],
class: "text-color-red",
method: :delete,
data: { confirm: t("administrate.actions.confirm") }
) if show_action? :destroy, resource %></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<%= f.submit "Activer l'archivage automatique des démarches sélectionnée" %>
<% end %>

View file

@ -0,0 +1,66 @@
<%#
# Index
This view is the template for the index page.
It is responsible for rendering the search bar, header and pagination.
It renders the `_table` partial to display details about the resources.
## Local variables:
- `page`:
An instance of [Administrate::Page::Collection][1].
Contains helper methods to help display a table,
and knows which attributes should be displayed in the resource's table.
- `resources`:
An instance of `ActiveRecord::Relation` containing the resources
that match the user's search criteria.
By default, these resources are passed to the table partial to be displayed.
- `search_term`:
A string containing the term the user has searched for, if any.
- `show_search_bar`:
A boolean that determines if the search bar should be shown.
[1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Collection
%>
<% content_for(:title) do %>
<%= display_resource_name(page.resource_name) %>
<% end %>
<header class="main-content__header" role="banner">
<h1 class="main-content__page-title" id="page-title">
<%= content_for(:title) %>
</h1>
<% if show_search_bar %>
<%= render(
"search",
search_term: search_term,
resource_name: display_resource_name(page.resource_name)
) %>
<% end %>
<div>
<%= link_to(
t(
"administrate.actions.new_resource",
name: display_resource_name(page.resource_name, singular: true).downcase
),
[:new, namespace, page.resource_path.to_sym],
class: "button",
) if valid_action?(:new) && show_action?(:new, new_resource) %>
</div>
</header>
<section class="main-content__body main-content__body--flush">
<%= render(
"collection",
collection_presenter: page,
collection_field_name: resource_name,
page: page,
resources: resources,
table_title: "page-title"
) %>
<%= paginate resources, param_name: '_page' %>
</section>

View file

@ -62,6 +62,9 @@ Rails.application.routes.draw do
resources :zones, only: [:index, :show]
resources :dubious_procedures, only: [:index]
resources :outdated_procedures, only: [:index] do
patch :bulk_update, on: :collection
end
post 'demandes/create_administrateur'
post 'demandes/refuse_administrateur'

View file

@ -0,0 +1,9 @@
RSpec.describe AdministrateurMailer, type: :mailer do
let(:procedure) { create(:procedure) }
let(:admin_email) { 'administrateur@email.fr' }
describe '.notify_procedure_expires_when_termine_forced' do
subject { described_class.notify_procedure_expires_when_termine_forced(admin_email, procedure) }
it { expect(subject.to).to eq([admin_email]) }
it { expect(subject.subject).to include("La suppression automatique des dossiers a été activée sur la démarche") }
end
end

View file

@ -4,4 +4,10 @@ class AdministrateurMailerPreview < ActionMailer::Preview
AdministrateurMailer.activate_before_expiration(administrateur, "a4d4e4f4b4d445")
end
def notify_procedure_expires_when_termine_forced
email = Administrateur.first.email
procedure = Procedure.first
AdministrateurMailer.notify_procedure_expires_when_termine_forced(email, procedure)
end
end