Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MGF-595-feat(new_field): entreprise / internship_offer: contact_phone #354

Merged
merged 11 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/dashboard/internship_offers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def internship_offer_builder

def internship_offer_params
params.require(:internship_offer)
.permit(:academy, :aasm_state, :city,
.permit(:academy, :aasm_state, :city, :contact_phone,
:department, :description, :employer_chosen_name, :employer_id,
:employer_name, :employer_type, :entreprise_chosen_full_address,
:entreprise_city,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def entreprise_params
:entreprise_chosen_full_address,
:entreprise_coordinates_longitude,
:entreprise_coordinates_latitude,
:contact_phone,
:entreprise_coordinates,
:internship_occupation_id,
:internship_address_manual_enter,
Expand Down
1 change: 1 addition & 0 deletions app/controllers/dashboard/stepper/plannings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def edit
end

# process update following a back to step 2
# should never be used
def update
raise 'expected to be never used '
authorize! :update, @planning
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/users_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def phone_pattern
'^\+?(\d{2,3}\s?)?(\d{2}\s?){3,4}\d{2}$'
end

def field_phone_pattern
'\A\+?(\d{2,3}\s?)?(\d{2}\s?){3,4}\d{2}\z'
end

def mail_pattern
'^[a-z0-9._%+\\-]+@[a-z0-9.\\-]+\.[a-z]{2,}$'
end
Expand Down
1 change: 1 addition & 0 deletions app/libs/builders/internship_offer_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def preprocess_entreprise_to_params(entreprise)
entreprise_full_address: entreprise.entreprise_full_address,
entreprise_chosen_full_address: entreprise.entreprise_chosen_full_address,
entreprise_coordinates: entreprise.entreprise_coordinates,
contact_phone: entreprise.contact_phone,
workspace_conditions: entreprise.workspace_conditions,
workspace_accessibility: entreprise.workspace_accessibility,
internship_address_manual_enter: entreprise.internship_address_manual_enter
Expand Down
12 changes: 0 additions & 12 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,25 +209,13 @@ def as_employers_like(user:)
end
can %i[create see_tutor], InternshipOffer
can %i[read update discard publish], InternshipOffer, employer_id: user.team_members_ids
# legacy_abilities for stepper
# can %i[create], InternshipOfferInfo
# can %i[create], HostingInfo
# can %i[create], PracticalInfo
# can %i[create], Organisation
# new_abilities for stepper
can %i[create], InternshipOccupation
can %i[create], Entreprise do |entreprise|
entreprise.internship_occupation.employer_id == user.id
end
can %i[create], Planning do |planning|
planning.entreprise.internship_occupation.employer_id == user.id
end
# legacy_abilities for stepper
# can %i[update edit renew], InternshipOfferInfo, employer_id: user.team_members_ids
# can %i[update edit renew], HostingInfo, employer_id: user.team_members_ids
# can %i[update edit renew], PracticalInfo, employer_id: user.team_members_ids
# can %i[update edit], Organisation, employer_id: user.team_members_ids
# new_abilities for stepper
can %i[update edit renew], InternshipOccupation, employer_id: user.team_members_ids
can %i[update edit renew], Entreprise do |entreprise|
entreprise.internship_occupation.employer_id.in?(user.team_members_ids)
Expand Down
3 changes: 3 additions & 0 deletions app/models/entreprise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class Entreprise < ApplicationRecord
validates :entreprise_full_address,
length: { minimum: 8, maximum: 200 },
presence: true
validates :contact_phone,
format: { with: Regexp.new(ApplicationController.helpers.field_phone_pattern),
message: 'Le numéro de téléphone doit être composé de 10 chiffres' }

def entreprise_coordinates=(geolocation)
case geolocation
Expand Down
2 changes: 1 addition & 1 deletion app/models/internship_offer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class InternshipOffer < ApplicationRecord
DUPLICATE_WHITE_LIST = %w[type title sector_id max_candidates description
employer_name street zipcode city department entreprise_coordinates
employer_chosen_name all_year_long period grade_ids week_ids
entreprise_full_address internship_offer_area_id
entreprise_full_address internship_offer_area_id contact_phone
is_public group school_id coordinates first_date last_date
siret internship_address_manual_enter lunch_break daily_hours
weekly_hours rep qpv].freeze
Expand Down
4 changes: 4 additions & 0 deletions app/models/internship_offers/weekly_framed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class WeeklyFramed < InternshipOffer
validates :street,
:city,
presence: true
validates :contact_phone,
format: { with: Regexp.new(ApplicationController.helpers.field_phone_pattern),
message: 'Le numéro de téléphone doit être composé de 10 chiffres' },
unless: :from_api?

validates :max_candidates,
numericality: { only_integer: true,
Expand Down
27 changes: 21 additions & 6 deletions app/views/dashboard/stepper/entreprises/_form_fields.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,29 @@
span.fr-icon-info-fill.text-blue-info aria-hidden="true"
small.text-blue-info.fr-mx-1w
| L’adresse du siège peut être différente de l’adresse où se déroulera le stage.

div class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}"
.col-12
- label = "Numéro de téléphone du dépositaire *"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

je croyais qu'on retirait les * et qu'on mettait juste optionnel, le cas échéant.

- hint = "Ce numéro ne sera pas communiqué aux candidats."
= render 'inputs/dsfr_input_field',
field: :contact_phone,
f: form,
label: label,
required: true,
title: label,
object: form.object,
hint: hint,
pattern: phone_pattern,
maxlength: 20,
value: resource&.contact_phone

.row class="fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}"
.col-12
.fr-h6
| Les informations liées à votre environnement de travail
.small
| Afin de mieux informer les élèves, nous vous proposons de préciser brièvement et si vous le souhaitez les conditions d’accueil dans vos locaux en répondant à ces deux questions
div data-controller="character-count" data-character-count-max-value="1000" class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}"
div data-controller="character-count" data-character-count-max-value="1000" class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}"
.col-12
= form.label :workspace_conditions, class: 'fr-label' do
= "Décrivez l'environnement de travail dans lequel l'élève va évoluer (open space, niveau sonore, luminosité…)"
Expand All @@ -166,13 +181,13 @@
| 0/1000 caractères
.fr-message.fr-message--error.d-none data-character-count-target="error"
| Le texte ne doit pas dépasser 1000 caractères
div data-controller="character-count" data-character-count-max-value="1000" class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}"
div data-controller="character-count" data-character-count-max-value="1000" class="row fr-mt-3w bloc-tooggle #{form.object.persisted? ? '' : 'd-none'}"
.col-12
= form.label :workspace_accessibility, class: 'fr-label' do
= "Parlez-nous de l’accessibilité du poste (déplacement dans les locaux, informations sonores et/ou visuelles, présence d’un ascenseur…)"
= form.text_area :workspace_accessibility,
class: 'fr-input',
rows: 3,
= form.text_area :workspace_accessibility,
class: 'fr-input',
rows: 3,
maxlength: 1000,
data: {:'character_count_target' => "input", :'action' => "input->character-count#updateCounter"}
.fr-messages-group aria-live="polite"
Expand Down
3 changes: 2 additions & 1 deletion app/views/dashboard/stepper/plannings/edit.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@
submit_button: true ,
model: model,
method: method,
url: url
url: url,
duplication: false
5 changes: 5 additions & 0 deletions db/migrate/20241204173244_add_employer_phone_to_entreprise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddEmployerPhoneToEntreprise < ActiveRecord::Migration[7.1]
def change
add_column :entreprises, :contact_phone, :string, limit: 20
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class EntreprisesControllerTest < ActionDispatch::IntegrationTest
entreprise_chosen_full_address: 'Testo in Paris',
entreprise_coordinates_longitude: '2.35',
entreprise_coordinates_latitude: '48.85',
contact_phone: '0123456789',
is_public: false,
sector_id: sector.id,
workspace_conditions: 'Environnement de travail',
Expand Down
1 change: 1 addition & 0 deletions test/factories/entreprises.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
entreprise_full_address { FFaker::AddressFR.full_address }
entreprise_chosen_full_address { FFaker::AddressFR.full_address }
entreprise_coordinates { Coordinates.paris }
contact_phone { FFaker::PhoneNumberFR.phone_number }
workspace_conditions { FFaker::Lorem.paragraph }
workspace_accessibility { FFaker::Lorem.paragraph }

Expand Down
2 changes: 1 addition & 1 deletion test/factories/internship_offers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
planning { create(:planning, entreprise: entreprise) }
sequence(:title) { |n| "Stage de 2de - #{n}" }
description { 'Lorem ipsum dolor' }
# contact_phone { '+330612345678' }
contact_phone { '+330612345678' }
max_candidates { 1 }
blocked_weeks_count { 0 }
sector { create(:sector) }
Expand Down
1 change: 1 addition & 0 deletions test/models/entreprise_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class EntrepriseTest < ActiveSupport::TestCase
entreprise.entreprise_coordinates = { latitude: 48.8566, longitude: 2.3522 }
assert_equal 2.3522, entreprise.entreprise_coordinates.longitude
assert_equal 48.8566, entreprise.entreprise_coordinates.latitude
assert entreprise.contact_phone.gsub(' ', '').match?(/0\d{9}/)
end

test 'tutor partially filled form fails gracefully' do
Expand Down
1 change: 1 addition & 0 deletions test/support/entreprise_form_filler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def fill_in_entreprise_form(group: nil, sector: nil)
assert_equal 'COMMUNE DE SAINT OUEN L AUMONE', find('input#entreprise_employer_name', visible: true).value.strip
fill_in "Indiquez le nom de l'enseigne de l'établissement d'accueil, si elle diffère de la raison sociale",
with: 'Mairie de Saint-Ouen-l’Aumône'
fill_in 'Numéro de téléphone du dépositaire *', with: '0130131313'
end

def fill_in_entreprise_manual_form(group: nil, sector: nil)
Expand Down
17 changes: 17 additions & 0 deletions test/support/third_party_test_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,21 @@ def fim_teacher_without_school_userinfo_stub
'rne' => '0590121X'
}.to_json, headers: {})
end

def prismic_stub(body_content)
headers = {
'Accept': 'application/json',
'Accept-Encoding': 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent': 'Ruby'
}
stub_request(:get, "#{ENV.fetch('PRISMIC_URL')}?access_token=#{ENV.fetch('PRISMIC_API_KEY')}")
.with(headers: headers)
.to_return(status: 200, body: body_content, headers: {})
end

def prismic_straight_stub(&block)
PagesController.stub_any_instance(:get_resources, []) do
PagesController.stub_any_instance(:get_faqs, [], &block)
end
end
end
1 change: 1 addition & 0 deletions test/system/dashboard/stepper/manage_entreprises_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class ManageEntreprisesTest < ApplicationSystemTestCase
visit new_dashboard_stepper_entreprise_path(internship_occupation_id: internship_occupation.id)
fill_in_entreprise_manual_form(group:, sector:)
find('p.fr-card__desc[data-write-summary-card-target="employerNameOutput"]', text: 'Mairie de Saint-Ouen-l’Aumône')
fill_in('Numéro de téléphone du dépositaire *', with: '0130131313')
find("button[type='submit']").click
find('#alert-success', text: "Les informations de l'entreprise ont bien été enregistrées")

Expand Down
58 changes: 31 additions & 27 deletions test/system/internship_application_student_flow_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,27 @@ class InternshipApplicationStudentFlowTest < ApplicationSystemTestCase

test 'student with approved application can see employer\'s address' do
skip 'failing test on CI but passing locally' if ENV.fetch('CI') == 'true'
school = create(:school, :with_school_manager)
student = create(:student,
school:,
class_room: create(:class_room, school:))
internship_application = create(
:weekly_internship_application,
:approved,
student:
)
sign_in(student)
visit '/'
visit dashboard_students_internship_applications_path(student, internship_application.internship_offer)
url = dashboard_students_internship_application_path(
student_id: student.id,
uuid: internship_application.uuid
)
assert page.has_selector?("a[href='#{url}']", count: 1)
visit url
find('.row .col-12 .fr-pl-1w.blue-france', text: '1 rue du poulet 75001 Paris')
prismic_straight_stub do
school = create(:school, :with_school_manager)
student = create(:student,
school:,
class_room: create(:class_room, school:))
internship_application = create(
:weekly_internship_application,
:approved,
student:
)
sign_in(student)
visit '/'
visit dashboard_students_internship_applications_path(student, internship_application.internship_offer)
url = dashboard_students_internship_application_path(
student_id: student.id,
id: internship_application.id
)
assert page.has_selector?("a[href='#{url}']", count: 1)
visit url
find('.row .col-12 .fr-pl-1w.blue-france', text: '1 rue du poulet 75001 Paris')
end
end

test 'student with submittted application can not see employer\'s address' do
Expand All @@ -127,13 +129,15 @@ class InternshipApplicationStudentFlowTest < ApplicationSystemTestCase
end

test 'when an employer tries to access application forms, she fails' do
employer = create(:employer)
internship_offer = create(:weekly_internship_offer_2nde)
visit internship_offer_path(internship_offer.id)
first(:link, 'Postuler').click
fill_in('Adresse électronique', with: employer.email)
fill_in('Mot de passe', with: employer.password)
click_button('Se connecter')
assert page.has_selector?('span#alert-text', text: "Vous n'êtes pas autorisé à effectuer cette action.")
prismic_straight_stub do
employer = create(:employer)
internship_offer = create(:weekly_internship_offer_2nde)
visit internship_offer_path(internship_offer.id)
first(:link, 'Postuler').click
fill_in('Adresse électronique', with: employer.email)
fill_in('Mot de passe', with: employer.password)
click_button('Se connecter')
assert page.has_selector?('span#alert-text', text: "Vous n'êtes pas autorisé à effectuer cette action.")
end
end
end
Loading