diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index 26fef7f0a..7d5e4834f 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -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 diff --git a/app/models/category.rb b/app/models/category.rb index d88c3d46f..bb915ad1d 100644 --- a/app/models/category.rb +++ b/app/models/category.rb @@ -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 diff --git a/app/views/categories/category_post_types.html.erb b/app/views/categories/category_post_types.html.erb index 808630027..c9d53c8d9 100644 --- a/app/views/categories/category_post_types.html.erb +++ b/app/views/categories/category_post_types.html.erb @@ -1,8 +1,17 @@ -

- <%= link_to edit_category_path(@category) do %> - « Back to category edit - <% end %> -

+<%# + View for managing allowed category post types + + Parameters: + params[:no_return] : whether to suppress the return link +%> + +<% unless params[:no_return] == '1' %> +

+ <%= link_to edit_category_path(@category) do %> + « Back to category edit + <% end %> +

+<% end %>

Allowed post types for <%= @category.name %>

Only post types listed here are allowed to be posted in this category. Not all will be displayed as available options diff --git a/app/views/categories/post_types.html.erb b/app/views/categories/post_types.html.erb index 3b594b327..3ab6bd43f 100644 --- a/app/views/categories/post_types.html.erb +++ b/app/views/categories/post_types.html.erb @@ -1,6 +1,12 @@ -

What kind of post?

+<% 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.' +%> + +

<%= header_title %>

- This category has more than one type of post available. Pick a post type to get started. + <%= header_subtitle %>

<% @post_types.each do |pt| %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index c7f6a9665..e658ad977 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -282,9 +282,16 @@ $(() => { <% end %> <% end %>
- <%= 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 %>