Skip to content

Commit

Permalink
Redirect community pages without /communities in request
Browse files Browse the repository at this point in the history
  • Loading branch information
camillevilla committed Oct 18, 2022
1 parent 0e7d9e2 commit 3c23e32
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/controllers/page_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class PageController < ApplicationController
def show
page_slug = params[:page_slug] ? params[:page_slug] : 'home'
@page = Page.includes(:page_group).find_by(slug: page_slug.downcase, page_groups: {slug: params[:page_group_friendly_id].downcase})
page_group = @page.page_group
@page_components = @page.page_components
get_map_components(@page_components)
@path_parts = request.path.split('/')
Expand All @@ -14,7 +15,9 @@ def show
@news_items_components = {}
@news_items_ids = []
collect_paginated_components(@page_components)
unless @page.published
if page_group.is_community? && !request.url.include?('/communities')
redirect_to("/communities/#{page_group.slug}/#{page_slug}")
elsif !@page.published
redirect_to(root_path) if current_user.nil? || !current_user.has_role?(:admin)
end
respond_to do |format|
Expand Down

0 comments on commit 3c23e32

Please sign in to comment.