Merge pull request #2794 from betagouv/delete-invite-gestionnaires
Delete invite gestionnaires
This commit is contained in:
commit
552468e6d9
17 changed files with 33 additions and 64 deletions
|
@ -5,7 +5,7 @@ class InvitesController < ApplicationController
|
|||
email = params[:invite_email].downcase
|
||||
dossier = current_user.dossiers.find(params[:dossier_id])
|
||||
|
||||
invite = InviteUser.create(
|
||||
invite = Invite.create(
|
||||
dossier: dossier,
|
||||
user: User.find_by(email: email),
|
||||
email: email,
|
||||
|
|
|
@ -35,7 +35,7 @@ class Commentaire < ApplicationRecord
|
|||
|
||||
def notify
|
||||
dossier_user_email = dossier.user.email
|
||||
invited_users_emails = dossier.invites_user.pluck(:email).to_a
|
||||
invited_users_emails = dossier.invites.pluck(:email).to_a
|
||||
|
||||
# - If the email is the contact email, the commentaire is a copy
|
||||
# of an automated notification email we sent to a user, so do nothing.
|
||||
|
|
|
@ -24,8 +24,6 @@ class Dossier < ApplicationRecord
|
|||
has_many :cadastres, dependent: :destroy
|
||||
has_many :commentaires, dependent: :destroy
|
||||
has_many :invites, dependent: :destroy
|
||||
has_many :invites_user, class_name: 'InviteUser', dependent: :destroy
|
||||
has_many :invites_gestionnaires, class_name: 'InviteGestionnaire', dependent: :destroy
|
||||
has_many :follows
|
||||
has_many :followers_gestionnaires, through: :follows, source: :gestionnaire
|
||||
has_many :avis, dependent: :destroy
|
||||
|
@ -160,7 +158,7 @@ class Dossier < ApplicationRecord
|
|||
end
|
||||
|
||||
def invite_for_user(user)
|
||||
invites_user.find_by(user_id: user.id)
|
||||
invites.find_by(user_id: user.id)
|
||||
end
|
||||
|
||||
def can_be_en_construction?
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
class InviteGestionnaire < Invite
|
||||
end
|
|
@ -1,2 +0,0 @@
|
|||
class InviteUser < Invite
|
||||
end
|
|
@ -10,8 +10,7 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
:received_at,
|
||||
:processed_at,
|
||||
:motivation,
|
||||
:instructeurs,
|
||||
:invites
|
||||
:instructeurs
|
||||
|
||||
has_one :individual
|
||||
has_one :entreprise
|
||||
|
@ -62,10 +61,6 @@ class DossierSerializer < ActiveModel::Serializer
|
|||
object.followers_gestionnaires.pluck(:email)
|
||||
end
|
||||
|
||||
def invites
|
||||
object.invites_gestionnaires.pluck(:email)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_geometry(dossier)
|
||||
|
|
5
db/migrate/20181010070424_remove_type_from_invites.rb
Normal file
5
db/migrate/20181010070424_remove_type_from_invites.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
class RemoveTypeFromInvites < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
remove_column :invites, :type
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2018_10_02_164310) do
|
||||
ActiveRecord::Schema.define(version: 2018_10_10_070424) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -384,7 +384,6 @@ ActiveRecord::Schema.define(version: 2018_10_02_164310) do
|
|||
t.string "email_sender"
|
||||
t.integer "dossier_id"
|
||||
t.integer "user_id"
|
||||
t.string "type", default: "InviteGestionnaire"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
|
|
@ -139,7 +139,7 @@ describe API::V1::DossiersController do
|
|||
let!(:dossier) { Timecop.freeze(date_creation) { create(:dossier, :with_entreprise, procedure: procedure, motivation: "Motivation") } }
|
||||
let(:dossier_id) { dossier.id }
|
||||
let(:body) { JSON.parse(retour.body, symbolize_names: true) }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs, :invites] }
|
||||
let(:field_list) { [:id, :created_at, :updated_at, :archived, :individual, :entreprise, :etablissement, :cerfa, :types_de_piece_justificative, :pieces_justificatives, :champs, :champs_private, :commentaires, :state, :simplified_state, :initiated_at, :processed_at, :received_at, :motivation, :email, :instructeurs] }
|
||||
subject { body[:dossier] }
|
||||
|
||||
it 'return REST code 200', :show_in_doc do
|
||||
|
|
|
@ -44,7 +44,7 @@ describe InvitesController, type: :controller do
|
|||
sign_in(user)
|
||||
end
|
||||
|
||||
it { expect { subject }.to change(InviteUser, :count).by(1) }
|
||||
it { expect { subject }.to change(Invite, :count).by(1) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -54,7 +54,7 @@ describe InvitesController, type: :controller do
|
|||
|
||||
shared_examples_for "he can not create a invite" do
|
||||
it { expect { subject }.to raise_error(ActiveRecord::RecordNotFound) }
|
||||
it { expect { subject rescue nil }.to change(InviteUser, :count).by(0) }
|
||||
it { expect { subject rescue nil }.to change(Invite, :count).by(0) }
|
||||
end
|
||||
|
||||
context 'when user has no access to dossier' do
|
||||
|
@ -73,7 +73,7 @@ describe InvitesController, type: :controller do
|
|||
dossier.update(user: signed_in_profile)
|
||||
end
|
||||
|
||||
it { expect { subject }.to change(InviteUser, :count).by(1) }
|
||||
it { expect { subject }.to change(Invite, :count).by(1) }
|
||||
|
||||
it "redirects to the previous URL" do
|
||||
expect(subject).to redirect_to("/dossiers/#{dossier.id}/brouillon")
|
||||
|
|
|
@ -50,13 +50,13 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when an invite asks for a dossier where they were invited' do
|
||||
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
|
||||
before { create(:invite, dossier: asked_dossier, user: user) }
|
||||
|
||||
it_behaves_like 'redirects and flashes'
|
||||
end
|
||||
|
||||
context 'when an invite asks for another dossier' do
|
||||
before { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
|
||||
before { create(:invite, dossier: create(:dossier), user: user) }
|
||||
|
||||
it_behaves_like 'redirects and flashes'
|
||||
end
|
||||
|
@ -84,13 +84,13 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when an invite asks for a dossier where they were invited' do
|
||||
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
|
||||
before { create(:invite, dossier: asked_dossier, user: user) }
|
||||
|
||||
it_behaves_like 'does not redirect nor flash'
|
||||
end
|
||||
|
||||
context 'when an invite asks for another dossier' do
|
||||
before { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
|
||||
before { create(:invite, dossier: create(:dossier), user: user) }
|
||||
|
||||
it_behaves_like 'redirects and flashes'
|
||||
end
|
||||
|
@ -123,14 +123,14 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when an invite save the draft for a dossier where they where invited' do
|
||||
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
|
||||
before { create(:invite, dossier: asked_dossier, user: user) }
|
||||
let(:draft) { true }
|
||||
|
||||
it_behaves_like 'does not redirect nor flash'
|
||||
end
|
||||
|
||||
context 'when an invite submit a dossier where they where invited' do
|
||||
before { create(:invite, dossier: asked_dossier, user: user, type: 'InviteUser') }
|
||||
before { create(:invite, dossier: asked_dossier, user: user) }
|
||||
let(:draft) { false }
|
||||
|
||||
it_behaves_like 'redirects and flashes'
|
||||
|
@ -370,7 +370,7 @@ describe NewUser::DossiersController, type: :controller do
|
|||
|
||||
context 'when the user has an invitation but is not the owner' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:invite) { create(:invite, dossier: dossier, user: user, type: 'InviteUser') }
|
||||
let!(:invite) { create(:invite, dossier: dossier, user: user) }
|
||||
|
||||
context 'and the invite saves a draft' do
|
||||
let(:payload) { submit_payload.merge(save_draft: true) }
|
||||
|
@ -493,7 +493,7 @@ describe NewUser::DossiersController, type: :controller do
|
|||
|
||||
context 'when the user has an invitation but is not the owner' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:invite) { create(:invite, dossier: dossier, user: user, type: 'InviteUser') }
|
||||
let!(:invite) { create(:invite, dossier: dossier, user: user) }
|
||||
|
||||
before do
|
||||
dossier.en_construction!
|
||||
|
@ -525,7 +525,7 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
|
||||
context 'when the user only have some dossiers invites' do
|
||||
let!(:invite) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
|
||||
let!(:invite) { create(:invite, dossier: create(:dossier), user: user) }
|
||||
|
||||
before { get(:index) }
|
||||
|
||||
|
@ -535,7 +535,7 @@ describe NewUser::DossiersController, type: :controller do
|
|||
|
||||
context 'when the user has both' do
|
||||
let!(:own_dossier) { create(:dossier, user: user) }
|
||||
let!(:invite) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
|
||||
let!(:invite) { create(:invite, dossier: create(:dossier), user: user) }
|
||||
|
||||
context 'and there is no current_tab param' do
|
||||
before { get(:index) }
|
||||
|
@ -560,8 +560,8 @@ describe NewUser::DossiersController, type: :controller do
|
|||
before do
|
||||
Timecop.freeze(4.days.ago) { create(:dossier, user: user) }
|
||||
Timecop.freeze(2.days.ago) { create(:dossier, user: user) }
|
||||
Timecop.freeze(4.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
|
||||
Timecop.freeze(2.days.ago) { create(:invite, dossier: create(:dossier), user: user, type: 'InviteUser') }
|
||||
Timecop.freeze(4.days.ago) { create(:invite, dossier: create(:dossier), user: user) }
|
||||
Timecop.freeze(2.days.ago) { create(:invite, dossier: create(:dossier), user: user) }
|
||||
get(:index)
|
||||
end
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ RSpec.describe Users::CarteController, type: :controller do
|
|||
let(:adresse) { etablissement.geo_adresse }
|
||||
|
||||
before do
|
||||
create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email, type: 'InviteUser'
|
||||
create :invite, dossier: dossier, user: invite_by_user, email: invite_by_user.email
|
||||
|
||||
sign_in user
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ describe UsersController, type: :controller do
|
|||
|
||||
context 'when user is invite by the owner' do
|
||||
before do
|
||||
create :invite, email: invite_user.email, dossier: dossier, user: invite_user, type: 'InviteUser'
|
||||
create :invite, email: invite_user.email, dossier: dossier, user: invite_user
|
||||
sign_in invite_user
|
||||
end
|
||||
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
FactoryBot.define do
|
||||
factory :invite_user do
|
||||
email { 'plop@octo.com' }
|
||||
|
||||
after(:build) do |invite, _evaluator|
|
||||
if invite.dossier.nil?
|
||||
invite.dossier = create(:dossier)
|
||||
end
|
||||
|
||||
if invite.user.present?
|
||||
invite.email = invite.user.email
|
||||
end
|
||||
end
|
||||
|
||||
trait :with_user do
|
||||
after(:build) do |invite, _evaluator|
|
||||
if invite.user.nil?
|
||||
invite.user = create(:user)
|
||||
invite.email = invite.user.email
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,7 +5,7 @@ feature 'Invitations' do
|
|||
let(:owner) { create(:user) }
|
||||
let(:invited_user) { create(:user, email: 'user_invite@exemple.fr') }
|
||||
let(:procedure) { create(:simple_procedure) }
|
||||
let(:invite) { create(:invite_user, user: invited_user, dossier: dossier) }
|
||||
let(:invite) { create(:invite, user: invited_user, dossier: dossier) }
|
||||
|
||||
context 'when the dossier is a brouillon' do
|
||||
let!(:dossier) { create(:dossier, :for_individual, state: Dossier.states.fetch(:brouillon), user: owner, procedure: procedure) }
|
||||
|
@ -26,7 +26,7 @@ feature 'Invitations' do
|
|||
end
|
||||
|
||||
context 'when inviting someone without an existing account' do
|
||||
let(:invite) { create(:invite_user, dossier: dossier, user: nil) }
|
||||
let(:invite) { create(:invite, dossier: dossier, user: nil) }
|
||||
let(:user_password) { 'l33tus3r' }
|
||||
|
||||
scenario 'an invited user can register using the registration link sent in the invitation email' do
|
||||
|
|
|
@ -33,7 +33,7 @@ RSpec.describe CommentaireHelper, type: :helper do
|
|||
|
||||
describe '.commentaire_is_from_guest' do
|
||||
let(:dossier) { create(:dossier) }
|
||||
let!(:guest) { create(:invite_user, dossier: dossier) }
|
||||
let!(:guest) { create(:invite, dossier: dossier) }
|
||||
|
||||
subject { commentaire_is_from_guest(commentaire) }
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ describe User, type: :model do
|
|||
|
||||
context 'when user was invited by user' do
|
||||
before do
|
||||
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
|
||||
create(:invite, dossier: dossier, user: invite_user)
|
||||
end
|
||||
|
||||
let(:user) { invite_user }
|
||||
|
@ -116,7 +116,7 @@ describe User, type: :model do
|
|||
|
||||
context 'when user was invited by user' do
|
||||
before do
|
||||
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
|
||||
create(:invite, dossier: dossier, user: invite_user)
|
||||
end
|
||||
|
||||
let(:user) { invite_user }
|
||||
|
|
Loading…
Reference in a new issue