Migrate Admin / Gestionnaire / Procédure gestion in database
This commit is contained in:
parent
fe4d921997
commit
1923f2aec1
22 changed files with 159 additions and 29 deletions
|
@ -15,6 +15,8 @@ class Admin::GestionnairesController < AdminController
|
|||
@gestionnaire = Gestionnaire.create(create_gestionnaire_params)
|
||||
|
||||
if @gestionnaire.errors.messages.empty?
|
||||
@gestionnaire.administrateurs.push current_administrateur
|
||||
|
||||
flash.notice = 'Gestionnaire ajouté'
|
||||
GestionnaireMailer.new_gestionnaire(@gestionnaire.email, @gestionnaire.password).deliver_now!
|
||||
else
|
||||
|
@ -33,8 +35,6 @@ class Admin::GestionnairesController < AdminController
|
|||
|
||||
def create_gestionnaire_params
|
||||
params.require(:gestionnaire).permit(:email)
|
||||
.merge(administrateur_id: current_administrateur.id)
|
||||
.merge(password: SecureRandom.hex(5))
|
||||
end
|
||||
|
||||
end
|
|
@ -1,10 +1,8 @@
|
|||
class Administrateur < ActiveRecord::Base
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
has_many :gestionnaires
|
||||
has_and_belongs_to_many :gestionnaires
|
||||
has_many :procedures
|
||||
|
||||
before_save :ensure_api_token
|
||||
|
|
4
app/models/assign_to.rb
Normal file
4
app/models/assign_to.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class AssignTo < ActiveRecord::Base
|
||||
belongs_to :procedure
|
||||
belongs_to :gestionnaire
|
||||
end
|
|
@ -1,12 +1,11 @@
|
|||
class Gestionnaire < ActiveRecord::Base
|
||||
# Include default devise modules. Others available are:
|
||||
# :confirmable, :lockable, :timeoutable and :omniauthable
|
||||
devise :database_authenticatable, :registerable,
|
||||
:recoverable, :rememberable, :trackable, :validatable
|
||||
|
||||
belongs_to :administrateur
|
||||
has_and_belongs_to_many :administrateurs
|
||||
|
||||
has_many :procedures, through: :administrateur
|
||||
has_many :assign_to
|
||||
has_many :procedures, through: :assign_to
|
||||
has_many :dossiers, through: :procedures
|
||||
|
||||
def dossiers_filter
|
||||
|
|
|
@ -7,6 +7,9 @@ class Procedure < ActiveRecord::Base
|
|||
|
||||
belongs_to :administrateur
|
||||
|
||||
has_many :assign_to
|
||||
has_many :gestionnaires, through: :assign_to
|
||||
|
||||
delegate :use_api_carto, to: :module_api_carto
|
||||
|
||||
accepts_nested_attributes_for :types_de_champ,:reject_if => proc { |attributes| attributes['libelle'].blank? }, :allow_destroy => true
|
||||
|
|
|
@ -13,6 +13,7 @@ ActiveSupport::Inflector.inflections(:en) do |inflect|
|
|||
inflect.irregular 'piece_justificative', 'pieces_justificatives'
|
||||
inflect.irregular 'type_de_piece_justificative', 'types_de_piece_justificative'
|
||||
inflect.irregular 'type_de_champ', 'types_de_champ'
|
||||
inflect.irregular 'assign_to', 'assign_tos'
|
||||
end
|
||||
|
||||
# These inflection rules are supported but not enabled by default:
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
class AdminHasAndBelongGestionnaire < ActiveRecord::Migration
|
||||
class Gestionnaire < ActiveRecord::Base
|
||||
end
|
||||
|
||||
class AdministrateursGestionnaire < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def up
|
||||
create_table :administrateurs_gestionnaires, id: false do |t|
|
||||
t.belongs_to :administrateur, index: true
|
||||
t.belongs_to :gestionnaire, index: true
|
||||
end
|
||||
|
||||
Gestionnaire.all.each do |gestionnaire|
|
||||
execute "insert into administrateurs_gestionnaires (gestionnaire_id, administrateur_id) values (#{gestionnaire.id}, #{gestionnaire.administrateur_id}) "
|
||||
end
|
||||
|
||||
remove_column :gestionnaires, :administrateur_id
|
||||
end
|
||||
|
||||
def down
|
||||
add_column :gestionnaires, :administrateur_id, :integer
|
||||
|
||||
AdministrateursGestionnaire.all.each do |ag|
|
||||
gestionnaire = Gestionnaire.find(ag.gestionnaire_id)
|
||||
gestionnaire.administrateur_id = ag.administrateur_id
|
||||
gestionnaire.save
|
||||
end
|
||||
|
||||
drop_table :administrateurs_gestionnaires
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
class GestionnaireIsAssignToProcedure < ActiveRecord::Migration
|
||||
class AssignTo < ActiveRecord::Base
|
||||
belongs_to :gestionnaire
|
||||
belongs_to :procedure
|
||||
end
|
||||
|
||||
class Gestionnaire < ActiveRecord::Base
|
||||
has_and_belongs_to_many :administrateurs
|
||||
has_many :procedures, through: :assign_to
|
||||
end
|
||||
|
||||
class Administrateur < ActiveRecord::Base
|
||||
has_and_belongs_to_many :gestionnaires
|
||||
has_many :procedures
|
||||
end
|
||||
|
||||
class Procedure < ActiveRecord::Base
|
||||
belongs_to :administrateur
|
||||
has_many :gestionnaires, through: :assign_to
|
||||
end
|
||||
|
||||
def change
|
||||
create_table :assign_tos, id: false do |t|
|
||||
t.belongs_to :gestionnaire, index: true
|
||||
t.belongs_to :procedure, index: true
|
||||
end
|
||||
|
||||
Administrateur.all.each do |administrateur|
|
||||
administrateur.gestionnaires.each do |gestionnaire|
|
||||
administrateur.procedures.each do |procedure|
|
||||
AssignTo.create gestionnaire: gestionnaire, procedure: procedure
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
19
db/schema.rb
19
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: 20160513093425) do
|
||||
ActiveRecord::Schema.define(version: 20160519101018) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -35,6 +35,14 @@ ActiveRecord::Schema.define(version: 20160513093425) 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 "administrateurs_gestionnaires", id: false, force: :cascade do |t|
|
||||
t.integer "administrateur_id"
|
||||
t.integer "gestionnaire_id"
|
||||
end
|
||||
|
||||
add_index "administrateurs_gestionnaires", ["administrateur_id"], name: "index_administrateurs_gestionnaires_on_administrateur_id", using: :btree
|
||||
add_index "administrateurs_gestionnaires", ["gestionnaire_id"], name: "index_administrateurs_gestionnaires_on_gestionnaire_id", using: :btree
|
||||
|
||||
create_table "administrations", force: :cascade do |t|
|
||||
t.string "email", default: "", null: false
|
||||
t.string "encrypted_password", default: "", null: false
|
||||
|
@ -53,6 +61,14 @@ ActiveRecord::Schema.define(version: 20160513093425) do
|
|||
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 "assign_tos", id: false, force: :cascade do |t|
|
||||
t.integer "gestionnaire_id"
|
||||
t.integer "procedure_id"
|
||||
end
|
||||
|
||||
add_index "assign_tos", ["gestionnaire_id"], name: "index_assign_tos_on_gestionnaire_id", using: :btree
|
||||
add_index "assign_tos", ["procedure_id"], name: "index_assign_tos_on_procedure_id", using: :btree
|
||||
|
||||
create_table "cadastres", force: :cascade do |t|
|
||||
t.string "surface_intersection"
|
||||
t.float "surface_parcelle"
|
||||
|
@ -176,7 +192,6 @@ ActiveRecord::Schema.define(version: 20160513093425) do
|
|||
t.inet "last_sign_in_ip"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
t.integer "administrateur_id"
|
||||
t.integer "procedure_filter", default: [], array: true
|
||||
end
|
||||
|
||||
|
|
|
@ -19,13 +19,19 @@ describe Admin::GestionnairesController, type: :controller do
|
|||
before do
|
||||
subject
|
||||
end
|
||||
|
||||
let(:gestionnaire) { Gestionnaire.last }
|
||||
|
||||
it { expect(response.status).to eq(302) }
|
||||
it { expect(response).to redirect_to admin_gestionnaires_path }
|
||||
|
||||
describe 'Gestionnaire attributs in database' do
|
||||
let(:gestionnaire) { Gestionnaire.last }
|
||||
it { expect(gestionnaire.email).to eq(email) }
|
||||
it { expect(gestionnaire.administrateur_id).to eq(admin.id) }
|
||||
end
|
||||
|
||||
describe 'New gestionnaire is assign to the admin' do
|
||||
it { expect(gestionnaire.administrateurs).to include admin }
|
||||
it { expect(admin.gestionnaires).to include gestionnaire }
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ describe Backoffice::DossiersController, type: :controller do
|
|||
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:bad_dossier_id) { Dossier.count + 10 }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: create(:administrateur)) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [create(:administrateur)]) }
|
||||
|
||||
describe 'GET #show' do
|
||||
context 'gestionnaire is connected' do
|
||||
|
|
4
spec/factories/assign_to.rb
Normal file
4
spec/factories/assign_to.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
FactoryGirl.define do
|
||||
factory :assign_to do
|
||||
end
|
||||
end
|
|
@ -21,7 +21,7 @@ feature 'when gestionnaire come to /backoffice and is not authenticated' do
|
|||
end
|
||||
context 'when user enter good credentials' do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
||||
|
||||
before do
|
||||
page.find_by_id(:gestionnaire_email).set gestionnaire.email
|
||||
|
|
|
@ -2,13 +2,16 @@ require 'spec_helper'
|
|||
|
||||
feature 'on backoffice page' do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
||||
let(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
|
||||
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
|
||||
visit backoffice_path
|
||||
end
|
||||
|
||||
context 'when gestionnaire is logged in' do
|
||||
before do
|
||||
page.find_by_id(:gestionnaire_email).set gestionnaire.email
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
feature 'on click on tabs button' do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
||||
|
||||
before do
|
||||
login_as gestionnaire, scope: :gestionnaire
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
feature 'search file on gestionnaire backoffice' do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
||||
|
||||
before do
|
||||
login_as gestionnaire, scope: :gestionnaire
|
||||
|
@ -11,8 +11,11 @@ feature 'search file on gestionnaire backoffice' do
|
|||
context 'when gestionnaire is logged in' do
|
||||
context 'when he click on search button' do
|
||||
let(:terms) { '' }
|
||||
let!(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
|
||||
|
||||
visit backoffice_dossiers_url
|
||||
page.find_by_id(:q).set terms
|
||||
page.find_by_id(:search_button).click
|
||||
|
@ -36,7 +39,6 @@ feature 'search file on gestionnaire backoffice' do
|
|||
end
|
||||
|
||||
context 'when terms input does return result' do
|
||||
let!(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
let!(:dossier) { create(:dossier, :with_entreprise, procedure: procedure, state: 'initiated') }
|
||||
let!(:dossier_2) { create(:dossier, procedure: procedure, state: 'initiated', nom_projet: 'Projet de test') }
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ describe Administrateur, type: :model do
|
|||
end
|
||||
|
||||
describe 'assocations' do
|
||||
it { is_expected.to have_many(:gestionnaires) }
|
||||
it { is_expected.to have_and_belong_to_many(:gestionnaires) }
|
||||
it { is_expected.to have_many(:procedures) }
|
||||
end
|
||||
|
||||
|
|
|
@ -387,10 +387,14 @@ describe Dossier do
|
|||
let(:admin) { create(:administrateur) }
|
||||
let(:admin_2) { create(:administrateur) }
|
||||
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: admin) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [admin]) }
|
||||
let(:procedure_admin) { create(:procedure, administrateur: admin) }
|
||||
let(:procedure_admin_2) { create(:procedure, administrateur: admin_2) }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_admin
|
||||
end
|
||||
|
||||
let!(:dossier1) { create(:dossier, procedure: procedure_admin, state: 'draft') }
|
||||
let!(:dossier2) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #a_traiter
|
||||
let!(:dossier3) { create(:dossier, procedure: procedure_admin, state: 'initiated') } #a_traiter
|
||||
|
@ -432,8 +436,13 @@ describe Dossier do
|
|||
let(:administrateur_1) { create(:administrateur) }
|
||||
let(:administrateur_2) { create(:administrateur) }
|
||||
|
||||
let(:gestionnaire_1) { create(:gestionnaire, administrateur: administrateur_1) }
|
||||
let(:gestionnaire_2) { create(:gestionnaire, administrateur: administrateur_2) }
|
||||
let(:gestionnaire_1) { create(:gestionnaire, administrateurs: [administrateur_1]) }
|
||||
let(:gestionnaire_2) { create(:gestionnaire, administrateurs: [administrateur_2]) }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire_1, procedure: procedure_1
|
||||
create :assign_to, gestionnaire: gestionnaire_2, procedure: procedure_2
|
||||
end
|
||||
|
||||
let(:procedure_1) { create(:procedure, administrateur: administrateur_1) }
|
||||
let(:procedure_2) { create(:procedure, administrateur: administrateur_2) }
|
||||
|
|
|
@ -17,7 +17,7 @@ describe Gestionnaire, type: :model do
|
|||
end
|
||||
|
||||
describe 'association' do
|
||||
it { is_expected.to belong_to(:administrateur) }
|
||||
it { is_expected.to have_and_belong_to_many(:administrateurs) }
|
||||
it { is_expected.to have_many(:procedures) }
|
||||
it { is_expected.to have_many(:dossiers) }
|
||||
end
|
||||
|
@ -26,10 +26,15 @@ describe Gestionnaire, type: :model do
|
|||
let(:admin) { create :administrateur }
|
||||
let(:procedure) { create :procedure, administrateur: admin }
|
||||
let(:procedure_2) { create :procedure, administrateur: admin }
|
||||
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateur: admin }
|
||||
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateurs: [admin] }
|
||||
let!(:dossier) { create :dossier, procedure: procedure }
|
||||
let(:procedure_filter) { [] }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2
|
||||
end
|
||||
|
||||
subject { gestionnaire.dossiers_filter }
|
||||
|
||||
context 'before filter' do
|
||||
|
@ -47,7 +52,12 @@ describe Gestionnaire, type: :model do
|
|||
let(:admin) { create :administrateur }
|
||||
let!(:procedure) { create :procedure, administrateur: admin }
|
||||
let!(:procedure_2) { create :procedure, administrateur: admin }
|
||||
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateur: admin }
|
||||
let(:gestionnaire) { create :gestionnaire, procedure_filter: procedure_filter, administrateurs: [admin] }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure_2
|
||||
end
|
||||
|
||||
let(:procedure_filter) { [] }
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ describe 'admin/gestionnaires/index.html.haml', type: :view do
|
|||
|
||||
context 'Ajout d\'un accompagnateur' do
|
||||
before do
|
||||
create(:gestionnaire, administrateur: admin)
|
||||
create(:gestionnaire, administrateurs: [admin])
|
||||
admin.reload
|
||||
assign(:gestionnaires, (smart_listing_create :gestionnaires,
|
||||
admin.gestionnaires,
|
||||
|
|
|
@ -2,7 +2,7 @@ require 'spec_helper'
|
|||
|
||||
describe 'backoffice/dossiers/index.html.haml', type: :view do
|
||||
let(:administrateur) { create(:administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateur: administrateur) }
|
||||
let(:gestionnaire) { create(:gestionnaire, administrateurs: [administrateur]) }
|
||||
|
||||
let!(:procedure) { create(:procedure, administrateur: administrateur) }
|
||||
|
||||
|
@ -10,6 +10,10 @@ describe 'backoffice/dossiers/index.html.haml', type: :view do
|
|||
let!(:decorate_dossier_replied) { create(:dossier, procedure: procedure, nom_projet: 'projet replied', state: 'replied').decorate }
|
||||
let!(:decorate_dossier_closed) { create(:dossier, procedure: procedure, nom_projet: 'projet closed', state: 'closed').decorate }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: procedure
|
||||
end
|
||||
|
||||
describe 'on tab a_traiter' do
|
||||
before do
|
||||
assign(:dossiers, (smart_listing_create :dossiers,
|
||||
|
|
|
@ -11,11 +11,15 @@ describe 'backoffice/procedure_filter/index.html.haml', type: :view do
|
|||
|
||||
context 'when gestionnaire have already check procedure' do
|
||||
let(:gestionnaire) { create(:gestionnaire,
|
||||
administrateur: administrateur,
|
||||
administrateurs: [administrateur],
|
||||
procedure_filter: [administrateur.procedures.first.id,
|
||||
administrateur.procedures.last.id]) }
|
||||
|
||||
before do
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: administrateur.procedures.first
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: administrateur.procedures.second
|
||||
create :assign_to, gestionnaire: gestionnaire, procedure: administrateur.procedures.last
|
||||
|
||||
sign_in gestionnaire
|
||||
|
||||
assign(:gestionnaire, gestionnaire)
|
||||
|
|
Loading…
Reference in a new issue