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'