Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ def rss_feed
end

def post_types
@post_types = @category.post_types.where(is_top_level: true)
@post_types = @category.top_level_post_types
if @post_types.one?
redirect_to new_category_post_path(post_type: @post_types.first, category: @category)
elsif @post_types.empty? && current_user&.admin?
redirect_to edit_category_post_types_path(@category, no_return: '1')
end
end

Expand Down
4 changes: 4 additions & 0 deletions app/models/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def public?
trust_level <= 0
end

def top_level_post_types
post_types.where(is_top_level: true)
end

def new_posts_for?(user)
key = "#{community_id}/#{user.id}/#{id}/last_visit"
Rails.cache.fetch key, expires_in: 5.minutes do
Expand Down
19 changes: 14 additions & 5 deletions app/views/categories/category_post_types.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
<p class="has-font-size-caption">
<%= link_to edit_category_path(@category) do %>
&laquo; Back to category edit
<% end %>
</p>
<%#
View for managing allowed category post types

Parameters:
params[:no_return] : whether to suppress the return link
%>

<% unless params[:no_return] == '1' %>
<p class="has-font-size-caption">
<%= link_to edit_category_path(@category) do %>
&laquo; Back to category edit
<% end %>
</p>
<% end %>
<h1>Allowed post types for <%= @category.name %></h1>
<p class="has-font-size-caption">
Only post types listed here are allowed to be posted in this category. Not all will be displayed as available options
Expand Down
10 changes: 8 additions & 2 deletions app/views/categories/post_types.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<h1>What kind of post?</h1>
<% header_title = @post_types.any? ? 'What kind of post?' : 'No allowed post types'
header_subtitle = @post_types.any? \
? 'This category has more than one type of post available. Pick a post type to get started.'
: 'This category does not have any post types available.'
%>

<h1><%= header_title %></h1>
<p class="has-font-size-larger has-color-tertiary-500">
This category has more than one type of post available. Pick a post type to get started.
<%= header_subtitle %>
</p>

<% @post_types.each do |pt| %>
Expand Down
13 changes: 10 additions & 3 deletions app/views/layouts/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,16 @@ $(() => {
<% end %>
<% end %>
<div class="category-header--nav-separator"></div>
<%= link_to category_post_types_path(current_cat.id),
class: 'category-header--nav-item is-button' do %>
<%= current_cat.button_text.present? ? current_cat.button_text : 'Create Post' %>
<% button_text = current_cat.button_text.present? ? current_cat.button_text : 'Create Post' %>
<% if current_cat&.top_level_post_types.any? || admin? %>
<%= link_to category_post_types_path(current_cat.id),
class: "category-header--nav-item is-button" do %>
<%= button_text %>
<% end %>
<% else %>
<%= button_tag button_text, class: "button is-muted is-outlined",
disabled: true,
title: "The category doesn't have any allowed post types" %>
<% end %>
</div>
</div>
Expand Down