Merge pull request #1207 from betagouv/easier_whitelist
Easier whitelist
This commit is contained in:
commit
e2bcace4ff
7 changed files with 62 additions and 20 deletions
|
@ -1,21 +1,9 @@
|
|||
module Manager
|
||||
class ProceduresController < Manager::ApplicationController
|
||||
# To customize the behavior of this controller,
|
||||
# simply overwrite any of the RESTful actions. For example:
|
||||
#
|
||||
# def index
|
||||
# super
|
||||
# @resources = Procedure.
|
||||
# page(params[:page]).
|
||||
# per(10)
|
||||
# end
|
||||
|
||||
# Define a custom finder by overriding the `find_resource` method:
|
||||
# def find_resource(param)
|
||||
# Procedure.find_by!(slug: param)
|
||||
# end
|
||||
|
||||
# See https://administrate-prototype.herokuapp.com/customizing_controller_actions
|
||||
# for more information
|
||||
def whitelist
|
||||
procedure = Procedure.find(params[:procedure_id])
|
||||
procedure.whitelist!
|
||||
redirect_to manager_procedure_path(procedure)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,7 +11,7 @@ class AdministrationMailer < ApplicationMailer
|
|||
|
||||
def dubious_procedures(procedures_and_type_de_champs)
|
||||
@procedures_and_type_de_champs = procedures_and_type_de_champs
|
||||
mail(to: 'tech@tps.apientreprise.fr',
|
||||
mail(to: 'equipe@tps.apientreprise.fr',
|
||||
subject: "[RGS] De nouvelles procédures comportent des champs interdits")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -248,6 +248,10 @@ class Procedure < ActiveRecord::Base
|
|||
}.to_json
|
||||
end
|
||||
|
||||
def whitelist!
|
||||
update_attribute('whitelisted_at', DateTime.now)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def field_hash(label, table, column)
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
%ul
|
||||
- @procedures_and_type_de_champs.each do |procedure, type_de_champs|
|
||||
%li
|
||||
Nº #{procedure.id}, #{procedure.libelle} :
|
||||
= link_to "Nº #{procedure.id},", manager_procedure_url(procedure)
|
||||
#{procedure.libelle} :
|
||||
%b= type_de_champs.map(&:libelle).join(', ')
|
||||
|
|
32
app/views/manager/procedures/show.html.haml
Normal file
32
app/views/manager/procedures/show.html.haml
Normal file
|
@ -0,0 +1,32 @@
|
|||
-# # Show
|
||||
-#
|
||||
-# This view is the template for the show page.
|
||||
-# It renders the attributes of a resource,
|
||||
-# as well as a link to its edit page.
|
||||
-#
|
||||
-# ## Local variables:
|
||||
-#
|
||||
-# - `page`:
|
||||
-# An instance of [Administrate::Page::Show][1].
|
||||
-# Contains methods for accessing the resource to be displayed on the page,
|
||||
-# as well as helpers for describing how each attribute of the resource
|
||||
-# should be displayed.
|
||||
-#
|
||||
-# [1]: http://www.rubydoc.info/gems/administrate/Administrate/Page/Show
|
||||
|
||||
- content_for(:title) { page.page_title }
|
||||
- procedure = page.resource
|
||||
|
||||
%header.header
|
||||
%h1.header__heading= content_for(:title)
|
||||
.header__actions
|
||||
- if procedure.whitelisted_at.nil?
|
||||
= link_to 'whitelister', manager_procedure_whitelist_path(procedure), method: :post, class: 'button'
|
||||
|
||||
%dl
|
||||
- page.attributes.each do |attribute|
|
||||
%dt.attribute-label
|
||||
= t("helpers.label.#{resource_name}.#{attribute.name}", default: attribute.name.titleize)
|
||||
|
||||
%dd.attribute-data{ class: "attribute-data--#{attribute.html_class}" }
|
||||
= render_field attribute
|
|
@ -1,6 +1,9 @@
|
|||
Rails.application.routes.draw do
|
||||
namespace :manager do
|
||||
resources :procedures, only: [:index, :show]
|
||||
resources :procedures, only: [:index, :show] do
|
||||
post '/whitelist' => 'procedures#whitelist'
|
||||
end
|
||||
|
||||
resources :administrateurs, only: [:index, :show]
|
||||
|
||||
root to: "procedures#index"
|
||||
|
|
14
spec/controllers/manager/procedures_controller_spec.rb
Normal file
14
spec/controllers/manager/procedures_controller_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
describe Manager::ProceduresController, type: :controller do
|
||||
describe '#whitelist' do
|
||||
let(:administration) { create :administration }
|
||||
let!(:procedure) { create(:procedure) }
|
||||
|
||||
before do
|
||||
sign_in administration
|
||||
post :whitelist, procedure_id: procedure.id
|
||||
procedure.reload
|
||||
end
|
||||
|
||||
it { expect(procedure.whitelisted_at).not_to be_nil }
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue