Whitelist: add whitelist button in admin

This commit is contained in:
simon lehericey 2018-01-10 16:46:12 +01:00 committed by Simon Lehericey
parent 202d0489a1
commit 53687bf84a
5 changed files with 59 additions and 18 deletions

View file

@ -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

View file

@ -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)

View 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

View file

@ -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"

View 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