Added published date as editable in admin articles list/show (#11124)
* Added published date as editable in admin articles list/show * Added requests spec for articles published date update
This commit is contained in:
parent
cb27662e8a
commit
2ee5ea69bd
5 changed files with 44 additions and 19 deletions
|
|
@ -39,15 +39,7 @@ module Admin
|
|||
|
||||
def update
|
||||
article = Article.find(params[:id])
|
||||
article.featured = article_params[:featured].to_s == "true"
|
||||
article.approved = article_params[:approved].to_s == "true"
|
||||
article.email_digest_eligible = article_params[:email_digest_eligible].to_s == "true"
|
||||
article.boosted_additional_articles = article_params[:boosted_additional_articles].to_s == "true"
|
||||
article.boosted_dev_digest_email = article_params[:boosted_dev_digest_email].to_s == "true"
|
||||
article.user_id = article_params[:user_id].to_i if article_params[:user_id].present?
|
||||
article.update(article_params)
|
||||
article.co_author_ids = article_params[:co_author_ids]&.split(",")&.map(&:strip)
|
||||
if article.save
|
||||
if article.update(article_params)
|
||||
flash[:success] = "Article saved!"
|
||||
else
|
||||
flash[:danger] = article.errors_as_sentence
|
||||
|
|
@ -135,8 +127,9 @@ module Admin
|
|||
main_image_background_hex_color
|
||||
featured_number
|
||||
user_id
|
||||
co_author_ids
|
||||
last_buffered]
|
||||
co_author_ids_list
|
||||
last_buffered
|
||||
published_at]
|
||||
params.require(:article).permit(allowed_params)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -379,6 +379,10 @@ class Article < ApplicationRecord
|
|||
spaminess_rating: BlackBox.calculate_spaminess(self))
|
||||
end
|
||||
|
||||
def co_author_ids_list=(list_of_co_author_ids)
|
||||
self.co_author_ids = list_of_co_author_ids.split(",").map(&:strip)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def search_score
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@
|
|||
<img src="<%= cloud_cover_url(article.main_image) %>" style="width:100%;max-width:380px;border-radius:8px;background:<%= article.main_image_background_hex_color %>;" alt="cover image" /><br />
|
||||
</div>
|
||||
<% end %>
|
||||
<%= form_with url: admin_article_path(article.id), local: true do |f| %>
|
||||
<%= form_with url: admin_article_path(article.id), model: article, local: true do |f| %>
|
||||
<div class="form-group">
|
||||
<input name="utf8" type="hidden" value="✓">
|
||||
<input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />
|
||||
|
|
@ -86,28 +86,35 @@
|
|||
value="<%= article.user_id %>">
|
||||
</div>
|
||||
<div class="form-group col">
|
||||
<label for="co_author_ids_<%= article.id %>">Co-Author IDs (comma separated):</label>
|
||||
<input id="co_author_ids_<%= article.id %>" class="form-control" size="6" name="article[co_author_ids]"
|
||||
<label for="co_author_ids_list_<%= article.id %>">Co-Author IDs (comma separated):</label>
|
||||
<input id="co_author_ids_list_<%= article.id %>" class="form-control" size="6" name="article[co_author_ids_list]"
|
||||
value="<%= article.co_author_ids&.join(", ") %>">
|
||||
</div>
|
||||
</div>
|
||||
<% if article.published? %>
|
||||
<div class="row">
|
||||
<div class="form-group col">
|
||||
<label for="published_at_<%= article.id %>">Published at:</label>
|
||||
<%= f.datetime_select :published_at, required: true, include_blank: true, include_seconds: true, class: "form-control" %> UTC
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="row">
|
||||
<div class="form-check col">
|
||||
<input name="article[featured]" type="checkbox" <%= "checked" if article.featured %> id="featured-<%= article.id %>">
|
||||
<%= f.check_box :featured, id: "featured-#{article.id}" %>
|
||||
<label for="featured-<%= article.id %>">Featured</label>
|
||||
</div>
|
||||
<div class="form-check col">
|
||||
<input name="article[approved]" type="checkbox" <%= "checked" if article.approved %> id="approved-<%= article.id %>">
|
||||
<%= f.check_box :approved, id: "approved-#{article.id}" %>
|
||||
<label for="approved-<%= article.id %>">Approved</label>
|
||||
</div>
|
||||
<div class="form-check col">
|
||||
<input name="article[boosted_additional_articles]" type="checkbox"
|
||||
<%= "checked" if article.boosted_additional_articles %> id="boosted_additional_articles-<%= article.id %>">
|
||||
<%= f.check_box :boosted_additional_articles, id: "boosted_additional_articles-#{article.id}" %>
|
||||
<label for="boosted_additional_articles-<%= article.id %>">Boosted</label>
|
||||
</div>
|
||||
<% unless article.last_buffered %>
|
||||
<div class="form-check col">
|
||||
<input name="article[last_buffered]" value="<%= Time.current %>" type="checkbox" id="last_buffered-<%= article.id %>">
|
||||
<%= f.check_box :last_buffered, id: "last_buffered-#{article.id}" %>
|
||||
<label for="last_buffered-<%= article.id %>">Mark as buffered</label>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -961,4 +961,13 @@ RSpec.describe Article, type: :model do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "co_author_ids_list=" do
|
||||
it "correctly sets co author ids from a comma separated list of ids" do
|
||||
co_author1 = create(:user)
|
||||
co_author2 = create(:user)
|
||||
article.co_author_ids_list = "#{co_author1.id}, #{co_author2.id}"
|
||||
expect(article.co_author_ids).to match_array([co_author1.id, co_author2.id])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -40,5 +40,17 @@ RSpec.describe "/admin/articles", type: :request do
|
|||
patch "/admin/articles/#{article.id}", params: { article: { featured: true } }
|
||||
end.to change { article.reload.featured }.to(true)
|
||||
end
|
||||
|
||||
it "allows an Admin to update the published at datetime for an article" do
|
||||
updated_published_at = article.published_at - 5.hours
|
||||
expect do
|
||||
patch "/admin/articles/#{article.id}", params: { article: { "published_at(1i)": updated_published_at.year,
|
||||
"published_at(2i)": updated_published_at.month,
|
||||
"published_at(3i)": updated_published_at.day,
|
||||
"published_at(4i)": updated_published_at.hour,
|
||||
"published_at(5i)": updated_published_at.min,
|
||||
"published_at(6i)": updated_published_at.sec } }
|
||||
end.to change { article.reload.published_at }.to(DateTime.parse(updated_published_at.to_s))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue