Merge branch 'develop' of github.com:sgmap/tps into develop
This commit is contained in:
commit
1652a747a1
13 changed files with 145 additions and 61 deletions
|
@ -179,4 +179,9 @@ div.pagination {
|
|||
|
||||
#confirm {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.fa {
|
||||
width: 15px;
|
||||
text-align: center;
|
||||
}
|
5
app/controllers/admin/profile_controller.rb
Normal file
5
app/controllers/admin/profile_controller.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class Admin::ProfileController < ApplicationController
|
||||
def show
|
||||
|
||||
end
|
||||
end
|
|
@ -6,4 +6,25 @@ class Administrateur < ActiveRecord::Base
|
|||
|
||||
has_many :gestionnaires
|
||||
has_many :procedures
|
||||
|
||||
before_save :ensure_api_token
|
||||
|
||||
def ensure_api_token
|
||||
if api_token.nil?
|
||||
self.api_token = generate_api_token
|
||||
end
|
||||
end
|
||||
|
||||
def renew_api_token
|
||||
update_attributes(api_token: generate_api_token)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_api_token
|
||||
loop do
|
||||
token = SecureRandom.hex(20)
|
||||
break token unless Administrateur.find_by(api_token: token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
1
app/views/admin/profile/show.html.haml
Normal file
1
app/views/admin/profile/show.html.haml
Normal file
|
@ -0,0 +1 @@
|
|||
#profile_page
|
21
app/views/administrateurs/_login_banner.html.haml
Normal file
21
app/views/administrateurs/_login_banner.html.haml
Normal file
|
@ -0,0 +1,21 @@
|
|||
%div{ style: "decorate:none; display: flex;box-shadow:none; float:right; display: flex" }
|
||||
%div{ style: "vertical-align: middle; margin-right: 10px; margin-top: auto; margin-bottom: auto;" }
|
||||
mps-test@apientreprise.fr
|
||||
.dropdown#admin_menu
|
||||
%button.btn.btn-default.dropdown-toggle#dropdownMenuAdmin{ type: :button, 'data-toggle' => 'dropdown', 'aria-haspopup' => true, 'aria-expanded' => false}
|
||||
%i.fa.fa-cog
|
||||
%span.caret
|
||||
%ul.dropdown-menu.dropdown-menu-right
|
||||
%li
|
||||
= link_to(admin_procedures_path, id: :menu_item_procedure) do
|
||||
%i.fa.fa-list{ style: "background-size: 10px;"}
|
||||
Procédures
|
||||
%li
|
||||
= link_to(admin_profile_path, id: :profile) do
|
||||
%i.fa.fa-user
|
||||
Profile
|
||||
%li.divider{ role: :separator}
|
||||
%li
|
||||
= link_to('/administrateurs/sign_out',id: :admin_sign_out, method: :delete) do
|
||||
%i.fa.fa-power-off
|
||||
Se déconnecter
|
|
@ -1,7 +1,7 @@
|
|||
#form_login
|
||||
= image_tag('logo-tps.png')
|
||||
%br
|
||||
%h2#login_user Administration
|
||||
%h2#login_admin Administration
|
||||
|
||||
%br
|
||||
%br
|
||||
|
|
|
@ -22,10 +22,7 @@
|
|||
= current_gestionnaire.email
|
||||
= link_to "Déconnexion", '/gestionnaires/sign_out', method: :delete, :class => 'btn btn-md'
|
||||
-elsif administrateur_signed_in?
|
||||
%div
|
||||
= current_administrateur.email
|
||||
= link_to "Déconnexion", '/administrateurs/sign_out', method: :delete, :class => 'btn btn-md'
|
||||
|
||||
= render partial: 'administrateurs/login_banner'
|
||||
- elsif user_signed_in?
|
||||
%div.user
|
||||
-if current_user.loged_in_with_france_connect
|
||||
|
|
|
@ -46,7 +46,7 @@ Rails.application.routes.draw do
|
|||
namespace :admin do
|
||||
get 'sign_in' => '/administrateurs/sessions#new'
|
||||
get 'procedures/archived' => 'procedures#archived'
|
||||
|
||||
get 'profile' => 'profile#show', as: :profile
|
||||
resources :procedures do
|
||||
resource :types_de_champ, only: [:show, :update] do
|
||||
post '/:index/move_up' => 'types_de_champ#move_up', as: :move_up
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddAPITokenToAdministrateur < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :administrateurs, :api_token, :string
|
||||
end
|
||||
end
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151211093833) do
|
||||
ActiveRecord::Schema.define(version: 20151214133426) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -29,6 +29,7 @@ ActiveRecord::Schema.define(version: 20151211093833) do
|
|||
t.inet "last_sign_in_ip"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.string "api_token"
|
||||
end
|
||||
|
||||
add_index "administrateurs", ["email"], name: "index_administrateurs_on_email", unique: true, using: :btree
|
||||
|
@ -62,8 +63,8 @@ ActiveRecord::Schema.define(version: 20151211093833) do
|
|||
t.boolean "autorisation_donnees"
|
||||
t.string "nom_projet"
|
||||
t.integer "procedure_id"
|
||||
t.datetime "created_at", default: '2015-12-07 09:51:46'
|
||||
t.datetime "updated_at", default: '2015-12-07 09:51:46'
|
||||
t.datetime "created_at", default: '2015-09-22 09:25:29'
|
||||
t.datetime "updated_at", default: '2015-09-22 09:25:29'
|
||||
t.string "state"
|
||||
t.integer "user_id"
|
||||
t.text "json_latlngs"
|
||||
|
|
59
spec/features/admin/connection_spec.rb
Normal file
59
spec/features/admin/connection_spec.rb
Normal file
|
@ -0,0 +1,59 @@
|
|||
require 'spec_helper'
|
||||
|
||||
feature 'Administrator connection' do
|
||||
let(:admin) { create(:administrateur) }
|
||||
before do
|
||||
visit new_administrateur_session_path
|
||||
end
|
||||
scenario 'administrator is on admin loggin page' do
|
||||
expect(page).to have_css('#login_admin')
|
||||
end
|
||||
|
||||
context "admin fills form and log in" do
|
||||
before do
|
||||
page.find_by_id('administrateur_email').set admin.email
|
||||
page.find_by_id('administrateur_password').set admin.password
|
||||
page.click_on 'Se connecter'
|
||||
end
|
||||
scenario 'a menu button is available' do
|
||||
expect(page).to have_css('#admin_menu')
|
||||
end
|
||||
|
||||
context 'when he click on the menu' do
|
||||
before do
|
||||
page.find_by_id('admin_menu').click
|
||||
end
|
||||
scenario 'it displays the menu' do
|
||||
expect(page).to have_css('a#profile')
|
||||
expect(page).to have_css('a#admin_sign_out')
|
||||
end
|
||||
context 'when clicking on sign_out' do
|
||||
before do
|
||||
page.find_by_id('admin_sign_out').click
|
||||
end
|
||||
scenario 'admin is redireted to home page' do
|
||||
expect(page).to have_css('#login_user')
|
||||
end
|
||||
end
|
||||
context 'when clicking on profile' do
|
||||
before do
|
||||
page.find_by_id('profile').click
|
||||
end
|
||||
scenario 'it redirects to profile page' do
|
||||
expect(page).to have_css('#profile_page')
|
||||
end
|
||||
context 'when clicking on procedure' do
|
||||
before do
|
||||
page.find_by_id('admin_menu').click
|
||||
page.find_by_id('menu_item_procedure').click
|
||||
end
|
||||
|
||||
scenario 'it redirects to procedure page' do
|
||||
expect(page).to have_content('Gestion des procédures')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
|
@ -1,52 +0,0 @@
|
|||
require 'spec_helper'
|
||||
|
||||
# feature 'delete a type de piece_justificative form', js: true do
|
||||
# let(:administrateur) { create(:administrateur) }
|
||||
|
||||
# before do
|
||||
# login_as administrateur, scope: :administrateur
|
||||
# end
|
||||
|
||||
# context 'when user click on type de piece_justificative red X button' do
|
||||
# let!(:procedure) { create(:procedure, :with_two_type_de_piece_justificative) }
|
||||
|
||||
# before do
|
||||
# visit admin_procedure_path id: procedure.id
|
||||
# end
|
||||
|
||||
# context 'when user edit a type de piece_justificative already save in database' do
|
||||
# let(:type_de_piece_justificative) { procedure.types_de_piece_justificative.first }
|
||||
|
||||
# before do
|
||||
# page.click_on 'delete_type_de_piece_justificative_1_procedure'
|
||||
# end
|
||||
|
||||
# scenario 'form is mask for the user' do
|
||||
# expect(page.find_by_id('type_de_piece_justificative_1', visible: false).visible?).to be_falsey
|
||||
# end
|
||||
|
||||
# scenario 'delete attribut of type de piece_justificative is turn to true' do
|
||||
# expect(page.find_by_id('type_de_piece_justificative_1', visible: false).find('input[class="destroy"]', visible: false).value).to eq('true')
|
||||
# end
|
||||
# end
|
||||
|
||||
# context 'when user edit a type de piece_justificative just add on the form page' do
|
||||
# before do
|
||||
# page.click_on 'add_type_de_piece_justificative_procedure'
|
||||
# page.click_on 'add_type_de_piece_justificative_procedure'
|
||||
# page.click_on 'delete_type_de_piece_justificative_2_procedure'
|
||||
# page.click_on 'delete_type_de_piece_justificative_3_procedure'
|
||||
# end
|
||||
|
||||
# scenario 'form is mask for the user' do
|
||||
# expect(page.find_by_id('type_de_piece_justificative_2', visible: false).visible?).to be_falsey
|
||||
# expect(page.find_by_id('type_de_piece_justificative_3', visible: false).visible?).to be_falsey
|
||||
# end
|
||||
|
||||
# scenario 'delete attribut of type de piece_justificative is turn to true' do
|
||||
# expect(page.find_by_id('type_de_piece_justificative_2', visible: false).find('input[class="destroy"]', visible: false).value).to eq('true')
|
||||
# expect(page.find_by_id('type_de_piece_justificative_3', visible: false).find('input[class="destroy"]', visible: false).value).to eq('true')
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# end
|
|
@ -14,6 +14,7 @@ describe Administrateur, type: :model do
|
|||
it { is_expected.to have_db_column(:last_sign_in_ip) }
|
||||
it { is_expected.to have_db_column(:created_at) }
|
||||
it { is_expected.to have_db_column(:updated_at) }
|
||||
it { is_expected.to have_db_column(:api_token) }
|
||||
end
|
||||
|
||||
describe 'assocations' do
|
||||
|
@ -21,4 +22,24 @@ describe Administrateur, type: :model do
|
|||
it { is_expected.to have_many(:procedures) }
|
||||
end
|
||||
|
||||
describe 'after_save' do
|
||||
subject { described_class.new(email: 'toto@tps.com', password: 'password') }
|
||||
before do
|
||||
subject.save
|
||||
end
|
||||
it { expect(subject.api_token).not_to be_blank }
|
||||
end
|
||||
|
||||
describe 'generate_api_token' do
|
||||
let(:token) { 'bullshit' }
|
||||
let(:new_token) { 'pocket_master' }
|
||||
let!(:admin_1) { create(:administrateur, email: 'toto@tps.com', password: 'password', api_token: token) }
|
||||
before do
|
||||
allow(SecureRandom).to receive(:hex).and_return(token, new_token)
|
||||
admin_1.renew_api_token
|
||||
end
|
||||
it 'generate a token who does not already exist' do
|
||||
expect(admin_1.api_token).to eq(new_token)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue