Skip to content
Snippets Groups Projects
Commit e09cba58 authored by Arnaud Levy's avatar Arnaud Levy
Browse files

Duplicate posts

parent 21dbd105
No related branches found
No related tags found
No related merge requests found
......@@ -87,6 +87,11 @@ class Admin::Communication::Websites::PostsController < Admin::Communication::We
end
end
def duplicate
redirect_to [:admin, @post.duplicate],
notice: t('admin.successfully_duplicated_html', model: @post.to_s)
end
def destroy
@post.destroy_and_sync
redirect_to admin_communication_website_posts_url, notice: t('admin.successfully_destroyed_html', model: @post.to_s)
......
......@@ -145,6 +145,20 @@ class Communication::Website::Post < ApplicationRecord
"#{Static.remove_trailing_slash website.url}#{Static.clean_path current_permalink_in_website(website).path}"
end
def duplicate
post = self.dup
post.published = false
post.published_at = nil
post.save
blocks.ordered.each do |block|
b = block.duplicate
b.about = post
b.position = block.position
b.save
end
post
end
def translated_author
@translated_author ||= author.find_or_translate!(language)
end
......
......@@ -53,6 +53,7 @@
<% content_for :action_bar_left do %>
<%= destroy_link @post %>
<%= duplicate_link @post %>
<%= static_link static_admin_communication_website_post_path(@post) %>
<% end %>
......
......@@ -40,6 +40,7 @@ namespace :communication do
member do
get :static
get :preview
post :duplicate
end
end
resources :menus, controller: 'websites/menus', path: '/:lang/menus' do
......
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