File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -127,9 +127,11 @@ def rss_feed
127127 end
128128
129129 def post_types
130- @post_types = @category . post_types . where ( is_top_level : true )
130+ @post_types = @category . top_level_post_types
131131 if @post_types . one?
132132 redirect_to new_category_post_path ( post_type : @post_types . first , category : @category )
133+ elsif @post_types . empty? && current_user &.admin?
134+ redirect_to edit_category_post_types_path ( @category , no_return : '1' )
133135 end
134136 end
135137
Original file line number Diff line number Diff line change @@ -22,6 +22,10 @@ def public?
2222 trust_level <= 0
2323 end
2424
25+ def top_level_post_types
26+ post_types . where ( is_top_level : true )
27+ end
28+
2529 def new_posts_for? ( user )
2630 key = "#{ community_id } /#{ user . id } /#{ id } /last_visit"
2731 Rails . cache . fetch key , expires_in : 5 . minutes do
Original file line number Diff line number Diff line change 1- < p class ="has-font-size-caption ">
2- <%= link_to edit_category_path ( @category ) do %>
3- « Back to category edit
4- <% end %>
5- </ p >
1+ <%#
2+ View for managing allowed category post types
3+
4+ Parameters:
5+ params[:no_return] : whether to suppress the return link
6+ %>
7+
8+ <% unless params[:no_return] == '1' %>
9+ <p class ="has-font-size-caption ">
10+ <%= link_to edit_category_path ( @category ) do %>
11+ « Back to category edit
12+ <% end %>
13+ </ p >
14+ <% end %>
615< h1 > Allowed post types for <%= @category . name %> </ h1 >
716< p class ="has-font-size-caption ">
817 Only post types listed here are allowed to be posted in this category. Not all will be displayed as available options
Original file line number Diff line number Diff line change 1- < h1 > What kind of post?</ h1 >
1+ <% header_title = @post_types.any? ? 'What kind of post?' : 'No allowed post types'
2+ header_subtitle = @post_types.any? \
3+ ? 'This category has more than one type of post available. Pick a post type to get started.'
4+ : 'This category does not have any post types available.'
5+ %>
6+
7+ <h1 > <%= header_title %> </ h1 >
28< p class ="has-font-size-larger has-color-tertiary-500 ">
3- This category has more than one type of post available. Pick a post type to get started.
9+ <%= header_subtitle %>
410</ p >
511
612<% @post_types . each do |pt | %>
Original file line number Diff line number Diff line change @@ -282,9 +282,16 @@ $(() => {
282282 <% end %>
283283 <% end %>
284284 < div class ="category-header--nav-separator "> </ div >
285- <%= link_to category_post_types_path ( current_cat . id ) ,
286- class : 'category-header--nav-item is-button' do %>
287- <%= current_cat . button_text . present? ? current_cat . button_text : 'Create Post' %>
285+ <% button_text = current_cat . button_text . present? ? current_cat . button_text : 'Create Post' %>
286+ <% if current_cat &.top_level_post_types . any? || admin? %>
287+ <%= link_to category_post_types_path ( current_cat . id ) ,
288+ class : "category-header--nav-item is-button" do %>
289+ <%= button_text %>
290+ <% end %>
291+ <% else %>
292+ <%= button_tag button_text , class : "button is-muted is-outlined" ,
293+ disabled : true ,
294+ title : "The category doesn't have any allowed post types" %>
288295 <% end %>
289296 </ div >
290297 </ div >
You can’t perform that action at this time.
0 commit comments