diff --git a/app/assets/stylesheets/new_design/avis_sign_up.scss b/app/assets/stylesheets/new_design/avis_sign_up.scss new file mode 100644 index 000000000..10d6d64ee --- /dev/null +++ b/app/assets/stylesheets/new_design/avis_sign_up.scss @@ -0,0 +1,92 @@ +@import "typography"; +@import "colors"; + +.avis-sign-up { + display: flex; + + .left, + .right { + width: 50%; + padding: 60px 86px; + } + + .left { + p { + margin: auto; + max-width: 410px; + text-align: center; + } + + .description { + font-size: 30px; + line-height: 1.3; + } + + .dossier { + font-size: 18px; + font-weight: bold; + margin-top: 15px; + } + } + + .right { + background-color: $light-grey; + + h1 { + font-size: 36px; + font-weight: bold; + margin-bottom: 60px; + } + + form { + max-width: 420px; + } + + label, + input { + display: block; + width: 100%; + } + + label { + font-size: 14px; + line-height: 1.57; + margin: 24px 0 8px; + } + + input { + border: solid 1px $border-grey; + border-radius: 4px; + height: 56px; + padding: 0 15px; + font-family: Muli; + font-size: 14px; + + &:disabled { + background-color: $border-grey; + } + } + + button { + display: inline-block; + height: 60px; + line-height: 60px; + border: none; + border-radius: 60px; + background-color: $blue; + color: #FFFFFF; + font-size: 16px; + font-weight: bold; + text-align: center; + width: 100%; + margin: 55px 0; + + &:hover { + color: #FFFFFF; + text-decoration: none; + background-color: $light-blue; + cursor: pointer; + } + } + } +} diff --git a/app/controllers/backoffice/avis_controller.rb b/app/controllers/backoffice/avis_controller.rb index 2bd8a23b9..50cab0e5d 100644 --- a/app/controllers/backoffice/avis_controller.rb +++ b/app/controllers/backoffice/avis_controller.rb @@ -1,6 +1,7 @@ class Backoffice::AvisController < ApplicationController - before_action :authenticate_gestionnaire! + before_action :authenticate_gestionnaire!, except: [:sign_up] + before_action :check_avis_exists_and_email_belongs_to_avis, only: [:sign_up] def create avis = Avis.new(create_params) @@ -25,6 +26,13 @@ class Backoffice::AvisController < ApplicationController redirect_to backoffice_dossier_path(avis.dossier_id) end + def sign_up + @email = params[:email] + @dossier = Avis.includes(:dossier).find(params[:id]).dossier + + render layout: 'new_application' + end + private def dossier @@ -43,4 +51,9 @@ class Backoffice::AvisController < ApplicationController params.require(:avis).permit(:answer) end + def check_avis_exists_and_email_belongs_to_avis + if !Avis.avis_exists_and_email_belongs_to_avis?(params[:id], params[:email]) + redirect_to url_for(root_path) + end + end end diff --git a/app/models/avis.rb b/app/models/avis.rb index 248d0c130..afc6ec285 100644 --- a/app/models/avis.rb +++ b/app/models/avis.rb @@ -20,4 +20,9 @@ class Avis < ApplicationRecord def self.link_avis_to_gestionnaire(gestionnaire) Avis.where(email: gestionnaire.email).update_all(email: nil, gestionnaire_id: gestionnaire.id) end + + def self.avis_exists_and_email_belongs_to_avis?(avis_id, email) + avis = Avis.find_by(id: avis_id) + avis.present? && avis.email == email + end end diff --git a/app/views/backoffice/avis/sign_up.html.haml b/app/views/backoffice/avis/sign_up.html.haml new file mode 100644 index 000000000..c02191ce7 --- /dev/null +++ b/app/views/backoffice/avis/sign_up.html.haml @@ -0,0 +1,15 @@ +.avis-sign-up + .left + %p.description= @dossier.procedure.libelle + %p.dossier Dossier n°#{@dossier.id} + .right + %h1 Créez-vous un compte + + = form_for(Gestionnaire.new, url: { controller: 'backoffice/avis', action: :create_gestionnaire }, method: :post) do |f| + = f.label :email, 'Email' + = f.email_field :email, value: @email, disabled: true + + = f.label :password, 'Mot de passe' + = f.password_field :password, autofocus: true, required: true, placeholder: '8 caractères minimum' + + %button Créer un compte diff --git a/config/routes.rb b/config/routes.rb index 16fadf98d..3911fd3a1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -30,6 +30,8 @@ Rails.application.routes.draw do put '/gestionnaires' => 'gestionnaires/registrations#update', :as => 'gestionnaires_registration' end + get 'avis/:id/sign_up/email/:email' => 'backoffice/avis#sign_up', constraints: { email: /.*/ }, as: 'avis_sign_up' + devise_scope :administrateur do get '/administrateurs/sign_in/demo' => 'administrateurs/sessions#demo' end diff --git a/spec/controllers/backoffice/avis_controller_spec.rb b/spec/controllers/backoffice/avis_controller_spec.rb index d3731e63c..055fb8be8 100644 --- a/spec/controllers/backoffice/avis_controller_spec.rb +++ b/spec/controllers/backoffice/avis_controller_spec.rb @@ -66,4 +66,30 @@ describe Backoffice::AvisController, type: :controller do end end + describe '.sign_up' do + let(:invited_email) { 'invited@avis.com' } + let(:dossier) { create(:dossier) } + let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + let(:invitations_email) { true } + + before do + expect(Avis).to receive(:avis_exists_and_email_belongs_to_avis?) + .with(avis.id.to_s, invited_email) + .and_return(invitations_email) + get :sign_up, params: { id: avis.id, email: invited_email } + end + + context 'when the email belongs to the invitation' do + it { expect(subject.status).to eq(200) } + it { expect(assigns(:email)).to eq(invited_email) } + it { expect(assigns(:dossier)).to eq(dossier) } + end + + context 'when the email does not belong to the invitation' do + let(:invitations_email) { false } + + it { is_expected.to redirect_to root_path } + end + end + end diff --git a/spec/models/avis_spec.rb b/spec/models/avis_spec.rb index f870d9e79..47a39c82e 100644 --- a/spec/models/avis_spec.rb +++ b/spec/models/avis_spec.rb @@ -51,4 +51,33 @@ RSpec.describe Avis, type: :model do it { expect(avis2.gestionnaire).to eq(gestionnaire) } end end + + describe '.avis_exists_and_email_belongs_to_avis' do + let(:dossier) { create(:dossier) } + let(:invited_email) { 'invited@avis.com' } + let!(:avis) { Avis.create(email: invited_email, dossier: dossier) } + + subject { Avis.avis_exists_and_email_belongs_to_avis?(avis_id, email) } + + context 'when the avis is unknown' do + let(:avis_id) { 666 } + let(:email) { 'unknown@mystery.com' } + + it { is_expected.to be false } + end + + context 'when the avis is known' do + let(:avis_id) { avis.id } + + context 'when the email belongs to the invitation' do + let(:email) { invited_email } + it { is_expected.to be true } + end + + context 'when the email is unknown' do + let(:email) { 'unknown@mystery.com' } + it { is_expected.to be false } + end + end + end end