From 451bdc36e050bb0724b06378befd0d7806e8722b Mon Sep 17 00:00:00 2001 From: f Date: Fri, 28 Sep 2018 14:35:40 -0300 Subject: [PATCH] los posts tiene autoria --- app/controllers/posts_controller.rb | 8 ++++++++ app/views/posts/_form.haml | 11 +++++++++++ config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 4 files changed, 23 insertions(+) diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 225e3c40..3a48aa20 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -45,6 +45,9 @@ class PostsController < ApplicationController @post = Post.new(site: @site, lang: @lang, template: @template) @post.update_attributes(repair_nested_params(post_params)) + # El author no se modifica + @post.update_attributes({author: current_user.username}) + if @post.save redirect_to site_posts_path(@site, lang: @lang) else @@ -69,6 +72,11 @@ class PostsController < ApplicationController @post.update_attributes(repair_nested_params(post_params)) + # Solo las usuarias pueden modificar la autoría + if current_user.is_a? Usuaria + @post.update_attributes({author: params[:post][:author]}) + end + if @post.save redirect_to site_posts_path(@site, category: session[:category], lang: @lang) else diff --git a/app/views/posts/_form.haml b/app/views/posts/_form.haml index edd4d73e..13b1804f 100644 --- a/app/views/posts/_form.haml +++ b/app/views/posts/_form.haml @@ -19,6 +19,17 @@ = hidden_field_tag 'template', params[:template] .form-group = submit_tag t('posts.save'), class: 'btn btn-success submit-post' + - if current_user.is_a? Usuaria + .form-group + = label_tag 'post_author', t('posts.author') + - todxs = (@site.usuarias + @site.invitadxs).map(&:username) + = select_tag 'post[author]', + options_for_select(todxs, @post.author), + { class: 'form-control select2', + data: { tags: true, + placeholder: t('posts.select.placeholder'), + 'allow-clear': true } } + %small.text-muted.form-text= t('posts.author_help') - if @post.has_field? :dir .form-group = label_tag 'post_dir', t('posts.dir') diff --git a/config/locales/en.yml b/config/locales/en.yml index 8be8106d..1b45dd3c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -173,6 +173,8 @@ en: index: 'Posts' edit: 'Edit' save: 'Save' + author: 'Author' + author_help: 'You can change the authorship of the post. If your site accepts guests, changing the authorship to an e-mail address will allow them to edit the post.' date: 'Publication date' date_help: 'This changes the articles order!' title: 'Title' diff --git a/config/locales/es.yml b/config/locales/es.yml index f392465f..859a1131 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -171,6 +171,8 @@ es: index: 'Artículos' edit: 'Editar' save: 'Guardar' + author: 'Autorx' + author_help: 'Puedes cambiar la autoría del artículo aquí. Si el sitio acepta invitadxs, poner la dirección de correo de alguien aquí le permite editarlo.' date: 'Fecha de publicación' date_help: '¡Esto cambia el orden de los artículos!' title: 'Título'