From bae77d8c6960ba702f4ea4d2dc0a39ba3cec3335 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 30 May 2019 14:33:51 -0300 Subject: [PATCH] eliminar desde el panel --- app/controllers/posts_controller.rb | 13 +++++++++++++ app/policies/post_policy.rb | 6 ++++++ app/views/posts/index.haml | 14 +++++++++++--- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 5 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 2b9ad02..ffb268b 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -104,6 +104,19 @@ class PostsController < ApplicationController end end + # Eliminar artículos + def destroy + @site = find_site + @lang = find_lang(@site) + @post = find_post(@site) + + authorize @post + + @post.destroy + + redirect_to site_posts_path(@site, category: session[:category], lang: @lang) + end + private # Solo permitir cambiar estos atributos de cada articulo diff --git a/app/policies/post_policy.rb b/app/policies/post_policy.rb index 9af48ea..579560d 100644 --- a/app/policies/post_policy.rb +++ b/app/policies/post_policy.rb @@ -34,6 +34,12 @@ class PostPolicy < SuttyPolicy usuaria? || post.author == usuarix.email end + # Solo las usuarias pueden eliminar artículos. Lxs invitadxs pueden + # borrar sus propios artículos + def destroy? + update? + end + class Scope < SuttyPolicy::Scope # Las usuarias pueden ver todos los posts # diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index aeef09b..606b392 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -118,8 +118,16 @@ %br %td= post.date.strftime('%F') - %td= link_to t('posts.edit'), - edit_site_post_path(@site, post, lang: @lang), - class: 'btn btn-info' + %td + - if policy(post).edit? + = link_to t('posts.edit'), + edit_site_post_path(@site, post, lang: @lang), + class: 'btn btn-info' + - if policy(post).destroy? + = link_to t('posts.destroy'), + site_post_path(@site, post, lang: @lang), + class: 'btn btn-danger', + method: :delete, + data: { confirm: t('posts.confirm_destroy') } - else %h2= t('posts.none') diff --git a/config/locales/en.yml b/config/locales/en.yml index ec393c5..8a36e47 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -254,3 +254,5 @@ en: invalid_help: It looks like the form is incomplete. Check the red-colored fields to complete it. sending_help: Saving, please wait... blank: Nothing + destroy: Delete + confirm_destroy: Are you sure? diff --git a/config/locales/es.yml b/config/locales/es.yml index 2b93429..d985d39 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -261,3 +261,5 @@ es: invalid_help: Parece que el formulario no está completo. Verifica los campos marcados en rojo para completarlo. sending_help: Guardando, por favor espera... blank: En blanco + destroy: Borrar + confirm_destroy: ¿Estás segurx?