Adding logic to hide Create Post on empty dashboard (#17149)

* Adding logic to hide Create Post on empty dashboard

As implemented, folks won't see this page if they can't create a post.
However, as our implementation drifts, we should continue to apply the
same policy.

See forem/forem#16999 for the conditional logic that redirects users.

* Adding a hack to fix a unit test
This commit is contained in:
Jeremy Friesen 2022-04-11 13:52:35 -04:00 committed by GitHub
parent f6d7d431b5
commit e2618c50f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -59,7 +59,9 @@
<%= image_tag(image_url, class: "sloan mb-7", alt: "Mascot image") %>
<% end %>
<p class="mb-6"><%= t("views.dashboard.posts.empty.desc") %></p>
<p><a href="/new" class="crayons-btn crayons-btn--l"><%= t("views.dashboard.posts.empty.new") %></a></p>
<% if policy(Article).create? %>
<p><a href="/new" class="crayons-btn crayons-btn--l"><%= t("views.dashboard.posts.empty.new") %></a></p>
<% end %>
</div>
</div>
<% end %>

View file

@ -8,6 +8,12 @@ RSpec.describe "dashboards/show", type: :view do
allow(Images::Optimizer).to receive(:imgproxy_enabled?).and_return(true)
allow(Settings::General).to receive(:mascot_image_url).and_return("https://i.imgur.com/fKYKgo4.png")
# These three lines are required for assisting the view in handling a policy.
# This issue highlights a continued problem: https://github.com/varvet/pundit/issues/163
view.extend(Pundit::Authorization)
policy = instance_double(ArticlePolicy, create?: true)
allow(view).to receive(:policy).and_return(policy)
end
context "when using Imgproxy" do