5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-14 23:01:41 +00:00

Merge branch 'borrar-articulos' into kefir

This commit is contained in:
f 2019-05-30 14:34:12 -03:00
commit 468eb93ec7
No known key found for this signature in database
GPG key ID: 2AE5A13E321F953D
7 changed files with 60 additions and 4 deletions

View file

@ -109,6 +109,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

View file

@ -17,7 +17,7 @@ require 'jekyll/utils'
class Post
attr_accessor :content, :front_matter
attr_reader :post, :site, :errors, :old_post, :lang, :template,
:template_fields
:template_fields, :collection
REJECT_FROM_DATA = %w[excerpt].freeze
# datos que no tienen que terminar en el front matter
@ -378,6 +378,18 @@ class Post
@template ||= template_from_layout
end
# Eliminar el artículo del repositorio y de la lista de artículos del
# sitio
def destroy
FileUtils.rm_f path
site.posts_for(collection).delete_if do |post|
post.path == path
end
true
end
private
# Completa el front_matter a partir de las variables de otro post que

View file

@ -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
#

View file

@ -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')

View file

@ -255,3 +255,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?

View file

@ -262,3 +262,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?

View file

@ -28,4 +28,17 @@ class PostTest < ActiveSupport::TestCase
test 'Es obvio que un post recién cargado es válido' do
assert @post.valid?
end
test 'El post se puede borrar' do
path = @post.path
assert @post.destroy
assert_not File.exist?(path)
post = @site.posts_for(@post.collection).find do |p|
p.path == @post.path
end
assert_not post
end
end