[#1677] No need to use emails when we have users
This commit is contained in:
parent
a489bbeb44
commit
884c430619
7 changed files with 34 additions and 25 deletions
|
@ -10,9 +10,11 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
dossier = Dossier.find(dossier_id)
|
dossier = Dossier.find(dossier_id)
|
||||||
|
|
||||||
return dossier if dossier.owner?(current_user.email) || dossier.invite_by_user?(current_user.email)
|
if !dossier.owner_or_invite?(current_user)
|
||||||
|
raise ActiveRecord::RecordNotFound
|
||||||
|
end
|
||||||
|
|
||||||
raise ActiveRecord::RecordNotFound
|
dossier
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorized_routes?(controller)
|
def authorized_routes?(controller)
|
||||||
|
|
|
@ -190,12 +190,8 @@ class Dossier < ApplicationRecord
|
||||||
en_instruction? || accepte? || refuse? || sans_suite?
|
en_instruction? || accepte? || refuse? || sans_suite?
|
||||||
end
|
end
|
||||||
|
|
||||||
def owner?(email)
|
def owner_or_invite?(user)
|
||||||
user.email == email
|
self.user == user || invites_user.find_by(user_id: user.id).present?
|
||||||
end
|
|
||||||
|
|
||||||
def invite_by_user?(email)
|
|
||||||
(invites_user.pluck :email).include? email
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_be_en_construction?
|
def can_be_en_construction?
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- if !@facade.dossier.read_only?
|
- if !@facade.dossier.read_only?
|
||||||
- if user_signed_in? && (@facade.dossier.owner?(current_user.email) || @facade.dossier.invite_by_user?(current_user.email))
|
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||||
%a#maj_carte.action{ href: "/users/dossiers/#{@facade.dossier.id}/carte" }
|
%a#maj_carte.action{ href: "/users/dossiers/#{@facade.dossier.id}/carte" }
|
||||||
.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
|
.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
|
||||||
= 'éditer'.upcase
|
= 'éditer'.upcase
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- if !@facade.dossier.read_only?
|
- if !@facade.dossier.read_only?
|
||||||
- if user_signed_in? && (@facade.dossier.owner?(current_user.email) || @facade.dossier.invite_by_user?(current_user.email))
|
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||||
= link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do
|
= link_to modifier_dossier_path(@facade.dossier), class: 'action', id: 'maj_infos' do
|
||||||
#edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
|
#edit-dossier.col-lg-2.col-md-2.col-sm-2.col-xs-2.action
|
||||||
= "éditer".upcase
|
= "éditer".upcase
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
- if !@facade.dossier.read_only?
|
- if !@facade.dossier.read_only?
|
||||||
- if user_signed_in? && (@facade.dossier.owner?(current_user.email) || @facade.dossier.invite_by_user?(current_user.email))
|
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||||
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
|
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
|
||||||
.col-lg-4.col-md-4.col-sm-4.col-xs-4.action
|
.col-lg-4.col-md-4.col-sm-4.col-xs-4.action
|
||||||
%a#maj_pj.action{ "data-target" => "#upload-pj-modal",
|
%a#maj_pj.action{ "data-target" => "#upload-pj-modal",
|
||||||
|
|
|
@ -101,7 +101,7 @@
|
||||||
Pièce non fournie
|
Pièce non fournie
|
||||||
|
|
||||||
- if !@facade.dossier.read_only?
|
- if !@facade.dossier.read_only?
|
||||||
- if user_signed_in? && (@facade.dossier.owner?(current_user.email) || @facade.dossier.invite_by_user?(current_user.email))
|
- if user_signed_in? && (@facade.dossier.owner_or_invite?(current_user))
|
||||||
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
|
- if @facade.procedure.cerfa_flag? || @facade.dossier.types_de_piece_justificative.size > 0
|
||||||
.row
|
.row
|
||||||
.col-xs-4
|
.col-xs-4
|
||||||
|
|
|
@ -404,28 +404,39 @@ describe Dossier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#invite_by_user?' do
|
describe '#owner_or_invite?' do
|
||||||
let(:dossier) { create :dossier }
|
let(:owner) { create(:user) }
|
||||||
let(:invite_user) { create :user, email: user_invite_email }
|
let(:dossier) { create(:dossier, user: owner) }
|
||||||
let(:invite_gestionnaire) { create :user, email: gestionnaire_invite_email }
|
let(:invite_user) { create(:user) }
|
||||||
let(:user_invite_email) { 'plup@plop.com' }
|
let(:invite_gestionnaire) { create(:user) }
|
||||||
let(:gestionnaire_invite_email) { 'plap@plip.com' }
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
create :invite, dossier: dossier, user: invite_user, email: invite_user.email, type: 'InviteUser'
|
create(:invite, dossier: dossier, user: invite_user, type: 'InviteUser')
|
||||||
create :invite, dossier: dossier, user: invite_gestionnaire, email: invite_gestionnaire.email, type: 'InviteGestionnaire'
|
create(:invite, dossier: dossier, user: invite_gestionnaire, type: 'InviteGestionnaire')
|
||||||
end
|
end
|
||||||
|
|
||||||
subject { dossier.invite_by_user? email }
|
subject { dossier.owner_or_invite?(user) }
|
||||||
|
|
||||||
context 'when email is present on invite list' do
|
context 'when user is owner' do
|
||||||
let(:email) { user_invite_email }
|
let(:user) { owner }
|
||||||
|
|
||||||
it { is_expected.to be_truthy }
|
it { is_expected.to be_truthy }
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'when email is present on invite list' do
|
context 'when user was invited by user' do
|
||||||
let(:email) { gestionnaire_invite_email }
|
let(:user) { invite_user }
|
||||||
|
|
||||||
|
it { is_expected.to be_truthy }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user was invited by gestionnaire (legacy, no new invitations happen)' do
|
||||||
|
let(:user) { invite_gestionnaire }
|
||||||
|
|
||||||
|
it { is_expected.to be_falsey }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when user is quidam' do
|
||||||
|
let(:user) { create(:user) }
|
||||||
|
|
||||||
it { is_expected.to be_falsey }
|
it { is_expected.to be_falsey }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue