Add UI SuperAdmin
This commit is contained in:
parent
56f9b2f71a
commit
36954c595e
14 changed files with 216 additions and 1 deletions
39
app/controllers/administrations_controller.rb
Normal file
39
app/controllers/administrations_controller.rb
Normal 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
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
|
|
10
app/mailers/new_admin_mailer.rb
Normal file
10
app/mailers/new_admin_mailer.rb
Normal 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
|
5
app/models/administration.rb
Normal file
5
app/models/administration.rb
Normal 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
|
25
app/views/administrations/_list.html.haml
Normal file
25
app/views/administrations/_list.html.haml
Normal 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éé
|
19
app/views/administrations/index.html.haml
Normal file
19
app/views/administrations/index.html.haml
Normal 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
|
9
app/views/new_admin_mailer/new_admin_email.text.erb
Normal file
9
app/views/new_admin_mailer/new_admin_email.text.erb
Normal 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
|
|
@ -127,6 +127,7 @@ task :deploy => :environment do
|
|||
invoke :'deploy:link_shared_paths'
|
||||
invoke :'bundle:install'
|
||||
invoke :'rails:db_migrate'
|
||||
invoke :'rails:db_seed'
|
||||
invoke :'rails:assets_precompile'
|
||||
|
||||
to :launch do
|
||||
|
|
|
@ -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"
|
|
@ -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
|
||||
|
|
42
db/migrate/20160223134354_devise_create_administrations.rb
Normal file
42
db/migrate/20160223134354_devise_create_administrations.rb
Normal 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
|
20
db/schema.rb
20
db/schema.rb
|
@ -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
1
db/seeds/super_admin.rb
Normal file
|
@ -0,0 +1 @@
|
|||
Administration.create(email: SUPERADMIN.email, password: SUPERADMIN.password)
|
Loading…
Reference in a new issue