Skip to content
Snippets Groups Projects
Unverified Commit c49d6a15 authored by Arnaud Levy's avatar Arnaud Levy Committed by GitHub
Browse files

Merge pull request #1360 from noesya/redirects

Gestion des redirections dans le cadre d'un plan de migration
parents 8715ad04 0f72390b
No related branches found
No related tags found
No related merge requests found
.offcanvas
&__redirections
@include media-breakpoint-up(md)
width: 50vw !important
\ No newline at end of file
class Admin::Communication::Websites::PermalinksController < Admin::Communication::Websites::ApplicationController
def create
@path = params['communication_website_permalink']['path']
@about = PolymorphicObjectFinder.find(params, :about)
@permalink = @about.add_redirection(@path)
end
end
\ No newline at end of file
......@@ -92,6 +92,17 @@ class Communication::Website::Permalink < ApplicationRecord
raise NotImplementedError
end
def self.clean_path(path)
clean_path = path.dup
# Remove eventual host
clean_path = URI(clean_path).path
# Leading slash for absolute path
clean_path = "/#{clean_path}" unless clean_path.start_with?('/')
# Trailing slash for coherence
clean_path = "#{clean_path}/" unless clean_path.end_with?('/')
clean_path
end
def pattern
language = about.respond_to?(:language) ? about.language : website.default_language
self.class.pattern_in_website(website, language)
......@@ -116,6 +127,10 @@ class Communication::Website::Permalink < ApplicationRecord
end
end
def to_s
"#{path}"
end
protected
def self.required_kinds_in_website(website)
......@@ -152,5 +167,4 @@ class Communication::Website::Permalink < ApplicationRecord
def set_university
self.university_id = website.university_id
end
end
......@@ -29,4 +29,13 @@ module WithPermalink
new_permalink_in_website(website).save_if_needed
end
def add_redirection(path)
clean_path = Communication::Website::Permalink.clean_path(path)
Communication::Website::Permalink.create(
website: website,
about: self,
is_current: false,
path: clean_path
)
end
end
<p>
<a class="action" data-bs-toggle="offcanvas" href="#offcanvasRedirects" role="button" aria-controls="offcanvasRedirects">
<%= t('admin.communication.website.redirects.button') %>
</a>
</p>
<div class="offcanvas offcanvas-end offcanvas__redirections" tabindex="-1" id="offcanvasRedirects" aria-labelledby="Redirections">
<div class="offcanvas-header">
<h2 class="offcanvas-title"><%= t('admin.communication.website.redirects.title') %></h2>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<%= osuny_panel t('admin.communication.website.redirects.current_path'), small: true do %>
<p class="lead">
<%= @page.current_permalink_in_website(@website) %>
</p>
<% end %>
<%= osuny_panel t('admin.communication.website.redirects.previous_paths'), small: true do %>
<table id="previous-permalinks" class="table border-top">
<tbody>
<% @page.previous_permalinks_in_website(@website).each do |link| %>
<tr>
<td><%= link.to_s %></td>
</tr>
<% end %>
</tbody>
</table>
<%= simple_form_for Communication::Website::Permalink.new,
url: admin_communication_website_permalinks_path(
about_type: about.class,
about_id: about.id
),
remote: true do |f| %>
<%= f.input :path, label: t('admin.communication.website.redirects.add_path') %>
<%= f.button :submit, t('add'), class: button_classes %>
<% end %>
<% end %>
</div>
</div>
\ No newline at end of file
......@@ -3,6 +3,7 @@
# @pa t'affole pas, c'est pas encore le cas
%>
<%= osuny_panel t('metadata'), small: true do %>
<p>
<% if @page.is_special_page? %>
<% page_type = t("communication.website.pages.defaults.#{@page.type_key}.title") %>
<% if page_type != @page.to_s %>
......@@ -16,12 +17,12 @@
<% if @page.parent && !@page.parent.is_home? %>
dans
<%= link_to_if can?(:read, @page.parent),
<%= link_to_if can?(:read, @page.parent),
@page.parent,
admin_communication_website_page_path(
website_id: @website.id,
id: @page.parent.id
) %>.
) %>
<% end %>
<% if @page.children.any? %>
......@@ -32,12 +33,13 @@
admin_communication_website_page_path( website_id: @website.id, id: child.id),
class: "#{'draft' unless child.published?}"
}.join(', ') %>.
}.join(', ') %>
<% end %>
<% if @page.full_width %>
<br>
Pleine largeur
en pleine largeur
<% end %>
</p>
<%= render 'admin/application/permalinks/redirects', about: @page %>
<% end %>
document.getElementById('previous-permalinks')
.getElementsByTagName('tbody')[0]
.insertRow()
.insertCell()
.appendChild(
document.createTextNode('<%= @permalink.path %>')
)
......@@ -218,6 +218,8 @@ en:
text: Main page text
title: Title
website: Website
communication/website/permalink:
path: Path
communication/website/post:
author: Author
category: Category
......@@ -268,6 +270,12 @@ en:
publish:
button: Publish
notice: Publication in progress, it should take a few minutes to be online.
redirects:
button: Manage redirects
title: Manage redirects
current_path: Current path
previous_paths: Redirects (old paths)
add_path: Add a redirect
communication:
authors:
one: Author
......
......@@ -218,6 +218,8 @@ fr:
text: Texte principal de la page
title: Titre
website: Site Web
communication/website/permalink:
path: Chemin
communication/website/post:
author: Auteur·rice
category: Catégorie
......@@ -268,6 +270,12 @@ fr:
publish:
button: Publier
notice: Publication en cours, cela devrait prendre quelques minutes pour arriver en ligne.
redirects:
button: Gérer les redirections
title: Gérer les redirections
current_path: Chemin actuel
previous_paths: Redirections (anciens chemins)
add_path: Ajouter une redirection
communication:
authors:
one: Auteur·rice
......
......@@ -14,6 +14,7 @@ namespace :communication do
get 'assets/*path' => 'websites/preview#assets'
resources :dependencies, controller: 'websites/dependencies', only: :index
resources :connections, controller: 'websites/connections', only: [:index, :show]
resources :permalinks, controller: 'websites/permalinks', only: :create
resources :pages, controller: 'websites/pages', path: '/:lang/pages' do
collection do
post :reorder
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment