Merge branch 'staging'

This commit is contained in:
Xavier J 2016-02-25 11:53:36 +01:00
commit 1b50d96e59
16 changed files with 251 additions and 26 deletions

View file

@ -0,0 +1,39 @@
class AdministrationsController < ApplicationController
include SmartListing::Helper::ControllerExtensions
helper SmartListing::Helper
before_action :authenticate_administration!
def index
@admins = smart_listing_create :admins,
Administrateur.all,
partial: "administrations/list",
array: true
@admin = Administrateur.new
end
def show
@admin = Administrateur.find(params[:id])
end
def create
admin = Administrateur.new create_administrateur_params
if admin.save
flash.notice = "Administrateur créé"
NewAdminMailer.new_admin_email(admin, params[:administrateur][:password]).deliver_now!
else
flash.alert = admin.errors.full_messages.join('<br>').html_safe
end
redirect_to administrations_path
end
private
def create_administrateur_params
params.require(:administrateur).permit(:email, :password)
end
end

View file

@ -10,6 +10,9 @@ class RootController < ApplicationController
elsif administrateur_signed_in?
redirect_to admin_procedures_path
elsif administration_signed_in?
redirect_to administrations_path
else
@latest_release = Github::Releases.latest
render 'landing'

View file

@ -6,5 +6,6 @@ class Sessions::SessionsController < Devise::SessionsController
sign_out :user if user_signed_in?
sign_out :gestionnaire if gestionnaire_signed_in?
sign_out :administrateur if administrateur_signed_in?
sign_out :administration if administration_signed_in?
end
end

View file

@ -4,6 +4,7 @@ class ChampDecorator < Draper::Decorator
if type_champ == 'checkbox'
return object.value == 'on' ? 'Oui' : 'Non'
end
object.value
end
def type_champ

View file

@ -0,0 +1,10 @@
class NewAdminMailer < ApplicationMailer
def new_admin_email admin, password
@admin = admin
@password = password
mail(from: "tech@apientreprise.fr", to: 'tech@apientreprise.fr',
subject: "Création d'un compte Admin TPS")
end
end

View file

@ -0,0 +1,5 @@
class Administration < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :rememberable, :trackable, :validatable
end

View file

@ -0,0 +1,25 @@
- unless smart_listing.empty?
%table.table
%thead
%th.col-md-4.col-lg-4= smart_listing.sortable 'Email', :email
%th.col-md-4.col-lg-4= smart_listing.sortable 'API Token', :api_token
%th.col-md-4.col-lg-4= smart_listing.sortable 'Date de dernière connexion', :last_sign_in_at
- @admins.each do |admin|
%tr
%td
= admin.email
%td
= admin.api_token
%td
- unless admin.last_sign_in_at.nil?
= time_ago_in_words(l(admin.last_sign_in_at, format: "%d/%m/%Y %H:%M UTC +02:00"))
(
= admin.last_sign_in_at.to_date.strftime('%d/%m/%Y')
)
= smart_listing.paginate
= smart_listing.pagination_per_page_links
- else
%h4.center
Aucun administrateur créé

View file

@ -0,0 +1,19 @@
%br
%br
= form_for @admin, url: {controller: 'administrations', action: :create} do |f|
.form-group.form-inline.center
= f.text_field :email, placeholder: :email, class: 'form-control'
= f.text_field :password, placeholder: :password, class: 'form-control'
= f.submit 'Valider', class: 'btn btn-success', id: 'submit_new_administrateur'
%br
= smart_listing_render :admins
%br
%br
.center
=link_to 'Deconnexion', '/administrations/sign_out', method: :delete

View file

@ -0,0 +1,9 @@
Un nouvel administrateur a été créé sur TPS.
Plateforme : <%= TPS::Application::URL %>
Login : <%= @admin.email %>
Password : <%= @password %>
---
L'équipe TPS - tps@apientreprise.fr

View file

@ -20,7 +20,7 @@ print "Deploy to #{ENV['to']} environment branch #{branch}\n"
# set :domain, '5.135.190.60'
set :domain, ENV['domain']
set :repository,'https://github.com/sgmap/tps.git'
set :repository, 'https://github.com/sgmap/tps.git'
set :port, 2200
set :deploy_to, '/var/www/tps_dev'
@ -66,11 +66,12 @@ set :shared_paths, [
'config/initializers/secret_token.rb',
"config/environments/#{ENV['to']}.rb",
"config/initializers/token.rb",
"config/initializers/super_admin.rb",
"config/unicorn.rb",
"config/initializers/raven.rb",
'config/france_connect.yml',
'config/initializers/mailjet.rb'
]
]
set :rbenv_path, "/usr/local/rbenv/bin/rbenv"
@ -78,7 +79,7 @@ set :rbenv_path, "/usr/local/rbenv/bin/rbenv"
# Optional settings:
# set :user, 'foobar' # Username in the server to SSH to.
# set :port, '30000' # SSH port number.
set :forward_agent, true # SSH forward_agent.
set :forward_agent, true # SSH forward_agent.
# This task is the environment that is loaded for most commands, such as
# `mina deploy` or `mina rake`.
@ -131,6 +132,10 @@ task :deploy => :environment do
to :launch do
queue "/etc/init.d/#{user} upgrade "
queue "cd #{deploy_to}/#{current_path}/"
queue "bundle exec rake db:seed RAILS_ENV=#{rails_env}"
queue %[echo "-----> Rake Seeding Completed."]
end
end
end

View file

@ -140,3 +140,41 @@ fr:
connexion: "Erreur lors de la connexion à France Connect."
extension_white_list_error: "Le format de fichier de la pièce jointe n'est pas valide."
datetime:
distance_in_words:
about_x_hours:
one: environ une heure
other: environ %{count} heures
about_x_months:
one: environ un mois
other: environ %{count} mois
about_x_years:
one: environ un an
other: environ %{count} ans
almost_x_years:
one: presqu'un an
other: presque %{count} ans
half_a_minute: une demi-minute
less_than_x_minutes:
zero: moins d'une minute
one: moins d'une minute
other: moins de %{count} minutes
less_than_x_seconds:
zero: moins d'une seconde
one: moins d'une seconde
other: moins de %{count} secondes
over_x_years:
one: plus d'un an
other: plus de %{count} ans
x_days:
one: 1 jour
other: "%{count} jours"
x_minutes:
one: 1 minute
other: "%{count} minutes"
x_months:
one: 1 mois
other: "%{count} mois"
x_seconds:
one: 1 seconde
other: "%{count} secondes"

View file

@ -1,5 +1,7 @@
Rails.application.routes.draw do
devise_for :administrations, skip: [:password, :registrations]
devise_for :administrateurs, controllers: {
sessions: 'administrateurs/sessions'
}, skip: [:password, :registrations]
@ -106,6 +108,8 @@ Rails.application.routes.draw do
resources :commentaires, only: [:create]
end
resources :administrations
namespace :api do
namespace :v1 do
resources :procedures, only: [:index, :show] do

View file

@ -0,0 +1,42 @@
class DeviseCreateAdministrations < ActiveRecord::Migration
def change
create_table(:administrations) do |t|
## Database authenticatable
t.string :email, null: false, default: ""
t.string :encrypted_password, null: false, default: ""
## Recoverable
t.string :reset_password_token
t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.inet :current_sign_in_ip
t.inet :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps
end
add_index :administrations, :email, unique: true
add_index :administrations, :reset_password_token, unique: true
# add_index :administrations, :confirmation_token, unique: true
# add_index :administrations, :unlock_token, unique: true
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20160204155519) do
ActiveRecord::Schema.define(version: 20160223134354) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -35,6 +35,24 @@ ActiveRecord::Schema.define(version: 20160204155519) do
add_index "administrateurs", ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree
add_index "administrateurs", ["reset_password_token"], name: "index_administrateurs_on_reset_password_token", unique: true, using: :btree
create_table "administrations", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "administrations", ["email"], name: "index_administrations_on_email", unique: true, using: :btree
add_index "administrations", ["reset_password_token"], name: "index_administrations_on_reset_password_token", unique: true, using: :btree
create_table "cadastres", force: :cascade do |t|
t.string "surface_intersection"
t.float "surface_parcelle"

1
db/seeds/super_admin.rb Normal file
View file

@ -0,0 +1 @@
Administration.create(email: SUPERADMIN.email, password: SUPERADMIN.password)

View file

@ -4,6 +4,11 @@ describe 'dossiers/_infos_dossier.html.haml', type: :view do
let(:dossier) { create(:dossier, :with_entreprise, procedure: create(:procedure, :with_api_carto, :with_type_de_champ)) }
before do
champs.each do |champ|
champ.value = ((0...8).map { (65 + rand(26)).chr }.join)
champ.save
end
assign(:facade, DossierFacades.new(dossier.id, dossier.user.email))
render
end