Don't show manage link in the action-space for a scheduled article (#18278)

* Don't show manage link in the action-space for a scheduled article

* Fixed Article#scheduled? for articles with empty published_at
This commit is contained in:
Anna Buianova 2022-08-08 15:14:11 +03:00 committed by GitHub
parent f1df37f431
commit cab9b754b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View file

@ -13,7 +13,9 @@ function addRelevantButtonsToArticle(user) {
articleContainer.dataset.buttonsInitialized !== 'true'
) {
let actions = [];
const published = JSON.parse(articleContainer.dataset.published);
const scheduled = JSON.parse(articleContainer.dataset.scheduled);
if (parseInt(articleContainer.dataset.authorId, 10) === user.id) {
actions.push(
@ -25,9 +27,9 @@ function addRelevantButtonsToArticle(user) {
clickToEditButton.style.display = 'inline-block';
}
if (published === true) {
if (published === true && !scheduled) {
actions.push(
`<a class="crayons-btn crayons-btn--s crayons-btn--ghost px-2" href="${articleContainer.dataset.path}/manage" rel="nofollow">Manage</a>`,
`<a class="crayons-btn crayons-btn--s crayons-btn--ghost px-2" id ="article-action-space-manage" href="${articleContainer.dataset.path}/manage" rel="nofollow">Manage</a>`,
);
}

View file

@ -443,7 +443,7 @@ class Article < ApplicationRecord
end
def scheduled?
published_at.future?
published_at? && published_at.future?
end
def search_id

View file

@ -90,6 +90,7 @@
data-pin-path="<%= stories_feed_pinned_article_path %>"
data-pinned-article-id="<%= @pinned_article_id %>"
data-published="<%= @article.published? %>"
data-scheduled="<%= @article.scheduled? %>"
<%= @article.pinned? ? "data-pinned" : " " %>>
<header class="crayons-article__header" id="main-title">
<% if @article.video.present? %>

View file

@ -150,6 +150,11 @@ RSpec.describe "Views an article", type: :system do
expect(edit_link.matches_style?(display: "inline-block")).to be true
end
it "doesn't show the article manage link, even for the author", js: true do
visit scheduled_article_path
expect(page).to have_no_link("article-action-space-manage")
end
it "doesn't show an article edit link for the non-authorized user" do
sign_out user
sign_in create(:user)