Skip to content

Commit

Permalink
Upgrade schema evolution
Browse files Browse the repository at this point in the history
  • Loading branch information
clairezed committed Dec 12, 2024
1 parent 15a8152 commit 89fe60f
Show file tree
Hide file tree
Showing 34 changed files with 367 additions and 273 deletions.
11 changes: 4 additions & 7 deletions app/admin/landing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
div t('active_admin.regional_theme') if l.has_regional_themes?
end

column :display_partner_url
actions dropdown: true do |l|
item t('active_admin.landings.update_iframe_360_button'), update_iframe_360_admin_landing_path(l), method: :put
end
Expand All @@ -75,7 +74,6 @@
row :archived_at
row(:layout) { |landing| human_attribute_status_tag landing, :layout }
row(:integration) { |landing| human_attribute_status_tag landing, :integration }
row :display_partner_url
end
end

Expand All @@ -86,7 +84,7 @@

attributes_table title: I18n.t("landings.landings.admin.iframe_and_api_fields") do
row :institution
row :partner_url
row :url_path
end

attributes_table title: I18n.t("landings.landings.admin.iframe_fields") do
Expand Down Expand Up @@ -119,8 +117,8 @@
:layout,
:emphasis, :home_description,
:meta_title, :meta_description,
:integration, :institution_id, :partner_url, :display_partner_url,
:iframe_category, :custom_css, :display_pde_partnership_mention,
:integration, :institution_id, :url_path,
:iframe_category, :custom_css,
landing_joint_themes_attributes: landing_joint_themes_attributes

form title: :title do |f|
Expand All @@ -129,7 +127,6 @@
f.input :slug
f.input :layout, as: :select, collection: Landing.human_attribute_values(:layout).invert
f.input :integration, as: :select, collection: Landing.human_attribute_values(:integration).invert
f.input :display_partner_url
end

f.inputs I18n.t("activerecord.attributes.landing.featured_on_home") do
Expand All @@ -139,7 +136,7 @@

f.inputs I18n.t("landings.landings.admin.iframe_and_api_fields") do
f.input :institution, as: :ajax_select, data: { url: :admin_institutions_path, search_fields: [:name] }
f.input :partner_url
f.input :url_path
end

f.inputs I18n.t("landings.landings.admin.iframe_fields") do
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/api/v1/landings/landings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def search
errors = [{ source: I18n.t('api_pde.query_parameters'), message: I18n.t('api_pde.errors.unrecognized') }]
render_error_payload(errors: errors, status: 400)
else
landing = base_scope.find_by!(partner_url: search_params[:url])
render json: landing, serializer: serializer, meta: { total_themes: landing.landing_themes.size }
cooperation = Cooperation.find_by!(root_url: search_params[:url])
landings = base_scope.joins(:cooperation).where(cooperation: cooperation)
render json: landings, each_serializer: serializer, meta: { total_results: landings.size }
end
end

Expand Down
6 changes: 3 additions & 3 deletions app/helpers/solicitation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def display_region(region, territory_params)

def display_solicitation_attribute(solicitation, attribute)
if attribute == :provenance_detail && solicitation.campaign == 'entreprendre'
link_to solicitation.send(attribute), partner_url(solicitation), title: "#{to_new_window_title(t('needs.show.origin_source_title'))}", target: '_blank', rel: 'noopener'
link_to solicitation.send(attribute), partner_url(solicitation, full: true), title: "#{to_new_window_title(t('needs.show.origin_source_title'))}", target: '_blank', rel: 'noopener'
else
solicitation.send(attribute)
end
Expand All @@ -80,11 +80,11 @@ def partner_title(solicitation)
end
end

def partner_url(solicitation)
def partner_url(solicitation, full: false)
return if solicitation.nil?
return solicitation.origin_url if solicitation.origin_url.present?
return "https://entreprendre.service-public.fr/vosdroits/#{solicitation.kwd}" if (solicitation.campaign == 'entreprendre' && solicitation.kwd.present?)
solicitation.landing.partner_url
full ? solicitation.landing.partner_full_url : solicitation.landing.partner_url
end

private
Expand Down
21 changes: 11 additions & 10 deletions app/models/cooperation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#
# Table name: cooperations
#
# id :bigint(8) not null, primary key
# display_url :boolean default(FALSE)
# mtm_campaign :string
# name :string
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# institution_id :bigint(8) not null
# id :bigint(8) not null, primary key
# display_pde_partnership_mention :boolean default(FALSE)
# display_url :boolean default(FALSE)
# mtm_campaign :string
# name :string
# root_url :string
# created_at :datetime not null
# updated_at :datetime not null
# institution_id :bigint(8) not null
#
# Indexes
#
Expand All @@ -23,8 +24,8 @@ class Cooperation < ApplicationRecord
## Associations
#
belongs_to :institution, inverse_of: :cooperations
has_many :landings, dependent: :restrict_with_exception
has_many :solicitations, dependent: :restrict_with_exception
has_many :landings, dependent: :restrict_with_exception, inverse_of: :cooperation
has_many :solicitations, dependent: :restrict_with_exception, inverse_of: :cooperation

has_many :cooperation_themes, dependent: :destroy, inverse_of: :cooperation
has_many :themes, through: :cooperation_themes, inverse_of: :cooperations
Expand Down
5 changes: 3 additions & 2 deletions app/models/institution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ class Institution < ApplicationRecord
#
has_many :antennes, -> { not_deleted }, inverse_of: :institution
has_many :institutions_subjects, dependent: :destroy, inverse_of: :institution, after_add: :update_antennes_referencement_coverage, after_remove: :update_antennes_referencement_coverage
has_many :landings, inverse_of: :institution
has_many :solicitations, inverse_of: :institution
has_and_belongs_to_many :categories # Une institution peut avoir plusieurs categories a la fois, donc une enum serait trop limitante
has_one :logo, as: :logoable, dependent: :destroy, inverse_of: :logoable

has_many :cooperations, dependent: :destroy, inverse_of: :institution
has_many :solicitations, through: :cooperations, inverse_of: :cooperation
has_many :landings, through: :cooperations, inverse_of: :cooperation

has_many :facilities, inverse_of: :opco
has_many :subject_answer_groupings, dependent: :destroy, inverse_of: :institution
Expand Down
17 changes: 11 additions & 6 deletions app/models/landing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
# layout :integer default("multiple_steps")
# meta_description :string
# meta_title :string
# partner_url :string
# slug :string not null
# title :string
# url_path :string
# created_at :datetime not null
# updated_at :datetime not null
# cooperation_id :bigint(8)
Expand Down Expand Up @@ -64,10 +64,8 @@ class Landing < ApplicationRecord
has_many :landing_subjects, through: :landing_themes, inverse_of: :landing_theme
has_many :subjects, through: :landing_subjects, inverse_of: :landings

# TODO : supprimer institution, lié maintenant à cooperation ?
belongs_to :institution, inverse_of: :landings, optional: true
belongs_to :cooperation, inverse_of: :landings, optional: true
# has_one :institution, through: :cooperation, inverse_of: :landings
has_one :institution, through: :cooperation, inverse_of: :landings

has_many :solicitations, inverse_of: :landing
has_many :diagnoses, through: :solicitations, inverse_of: :landing
Expand All @@ -83,7 +81,6 @@ class Landing < ApplicationRecord
## Validation
#
validates :slug, presence: true, uniqueness: true
validates :partner_url, presence: true, if: -> { iframe? || api? }

## Scopes
#
Expand Down Expand Up @@ -129,11 +126,19 @@ def update_iframe_360
end
end

def partner_url
cooperation&.root_url
end

def partner_full_url
[cooperation&.root_url, url_path].compact.join
end

def self.ransackable_attributes(auth_object = nil)
[
"archived", "archived_at", "created_at", "custom_css", "display_pde_partnership_mention", "emphasis",
"home_description", "id", "id_value", "iframe_category", "institution_id", "integration", "layout",
"meta_description", "meta_title", "partner_url", "slug", "title", "updated_at"
"meta_description", "meta_title", "url_path", "slug", "title", "updated_at"
]
end

Expand Down
7 changes: 3 additions & 4 deletions app/models/solicitation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ class Solicitation < ApplicationRecord

## Associations
#
belongs_to :cooperation, inverse_of: :solicitations, optional: true
belongs_to :landing, inverse_of: :solicitations, optional: true
belongs_to :cooperation, inverse_of: :solicitations, optional: true
has_one :institution, through: :cooperation, source: :institution, inverse_of: :cooperations

belongs_to :landing_subject, inverse_of: :solicitations, optional: true
has_one :landing_theme, through: :landing_subject, source: :landing_theme, inverse_of: :landing_subjects
Expand All @@ -69,8 +70,6 @@ class Solicitation < ApplicationRecord
has_many :company_satisfactions, through: :diagnosis, inverse_of: :solicitation
has_many :needs, through: :diagnosis, inverse_of: :solicitation

# TODO : a supprimer ?
belongs_to :institution, inverse_of: :solicitations, optional: true
has_many :badge_badgeables, as: :badgeable
has_many :badges, through: :badge_badgeables, after_add: :touch_after_badges_update, after_remove: :touch_after_badges_update
has_many :subject_answers, dependent: :destroy, as: :subject_questionable, inverse_of: :subject_questionable, class_name: 'SubjectAnswer::Item'
Expand Down Expand Up @@ -646,7 +645,7 @@ def provenance_title
if from_iframe?
landing.slug
elsif from_api?
landing.partner_url
landing.partner_full_url
elsif from_campaign?
campaign
end
Expand Down
4 changes: 2 additions & 2 deletions app/views/mailers/expert_mailer/notify_company_needs.mjml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<mj-section>
<mj-column>
<mj-text>
<% if @solicitation.present? && @solicitation.landing&.partner_url.present? %>
<p><%= t('.via_partner_html', url: @solicitation.landing.partner_url) %></p>
<% if @solicitation.present? && @solicitation.landing&.partner_full_url.present? %>
<p><%= t('.via_partner_html', url: @solicitation.landing.partner_full_url) %></p>
<% end %>
<p><%= t('mailers.thanks_for_your_trust') %></p>
<p><%= t('mailers.see_you_on_service_html', link_to_root: link_to(t('app_name'), root_url)) %></p>
Expand Down
4 changes: 2 additions & 2 deletions app/views/mailers/expert_mailer/notify_company_needs.text.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

<%= render 'mailers/expert_mailer/need_card', need: @need, visited_at: false %>

<% if @solicitation.present? && @solicitation.landing&.partner_url.present? %>
<%= ActionView::Base.full_sanitizer.sanitize(t('.via_partner_html', url: @solicitation.landing.partner_url)) %>
<% if @solicitation.present? && @solicitation.landing&.partner_full_url.present? %>
<%= ActionView::Base.full_sanitizer.sanitize(t('.via_partner_html', url: @solicitation.landing.partner_full_url)) %>
<% end %>


Expand Down
6 changes: 3 additions & 3 deletions app/views/needs/_match_actions.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
- else
- text = t('.contact_company', company: match.company)
%p.explanations= text
- partner_link = match.solicitation&.landing&.partner_url
- if partner_link.present?
%p.sub-content= t('.deposited_on_partner_website_html', partner_link: link_to(partner_link, partner_link, target: '_blank', rel: 'noopener'))
- partner_full_link = match.solicitation&.landing&.partner_full_url
- if partner_full_link.present?
%p.sub-content= t('.deposited_on_partner_website_html', partner_full_link: link_to(match.solicitation.landing.partner_url, partner_link, target: '_blank', rel: 'noopener'))
= form_with(model: match, url: match_path(match)) do |f|
= f.button :submit, name: :status, value: :quo, class: 'gray-link', id: "cancel-match" do
= t('.cancel_taking_care')
Expand Down
4 changes: 2 additions & 2 deletions app/views/needs/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
%p
%time.date{ datetime: @need.display_time } Le #{I18n.l(@need.display_time, format: :sentence)}
= need_general_context(@need)
- display_partner_url = (@need.solicitation&.landing&.display_partner_url && partner_url(@need.solicitation).present?)
- display_partner_url = (@need.solicitation&.cooperation&.display_url && partner_url(@need.solicitation).present?)
- if @need.subject_answers.any? || display_partner_url
%hr
.need-description__meta.fr-text--sm
Expand All @@ -28,7 +28,7 @@
%p.fr-text--sm
= t('.origin_source')
%br
= link_to partner_title(@need.solicitation), partner_url(@need.solicitation), title: "#{to_new_window_title(t('.origin_source_title'))}", target: '_blank', rel: 'noopener'
= link_to partner_title(@need.solicitation), partner_url(@need.solicitation, full: true), title: "#{to_new_window_title(t('.origin_source_title'))}", target: '_blank', rel: 'noopener'

.fr-col-md-4.order-minus-one.bp-sm
.fr-grid-row.need-metadata
Expand Down
6 changes: 4 additions & 2 deletions config/locales/models.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ fr:
contact:
company: Entreprise
job: Fonction
cooperation:
display_pde_partnership_mention: Afficher le partenariat Conseillers-Entreprises (logo + phrase en bas d’iframe)
display_url: Afficher l’url du partenaire
diagnosis:
content: Commentaire
step: Étape
Expand Down Expand Up @@ -263,8 +266,6 @@ fr:
landing:
api: Api
custom_css: CSS personnalisé
display_partner_url: Afficher l’url de la source
display_pde_partnership_mention: Afficher le partenariat Conseillers-Entreprises (logo + phrase en bas d’iframe)
emphasis: Mettre en avant sur la page d’accueil
featured_on_home: Champs encart page d’accueil
home_description: Description sur la page d’accueil
Expand All @@ -282,6 +283,7 @@ fr:
meta_title: Titre méta
partner_url: Url du site partenaire
slug: Slug
url_path: chemin (fin de l'url) du site partenaire
landing/iframe_categories:
form: formulaire un sujet
integral: 360°
Expand Down
Loading

0 comments on commit 89fe60f

Please sign in to comment.