FEATURE: allows published pages to be public (#10053)

This commit is contained in:
Joffrey JAFFEUX
2020-06-17 12:42:20 +02:00
committed by GitHub
parent 7d289a4f3e
commit 9da3a7f436
14 changed files with 196 additions and 30 deletions

View File

@ -5,6 +5,7 @@ class PublishedPagesController < ApplicationController
skip_before_action :preload_json
skip_before_action :check_xhr, :verify_authenticity_token, only: [:show]
before_action :ensure_publish_enabled
before_action :redirect_to_login_if_required, except: [:show]
def show
params.require(:slug)
@ -12,7 +13,22 @@ class PublishedPagesController < ApplicationController
pp = PublishedPage.find_by(slug: params[:slug])
raise Discourse::NotFound unless pp
guardian.ensure_can_see!(pp.topic)
return if enforce_login_required!
if !pp.public
begin
guardian.ensure_can_see!(pp.topic)
rescue Discourse::InvalidAccess => e
return rescue_discourse_actions(
:invalid_access,
403,
include_ember: false,
custom_message: e.custom_message,
group: e.group
)
end
end
@topic = pp.topic
@canonical_url = @topic.url
@ -37,7 +53,15 @@ class PublishedPagesController < ApplicationController
end
def upsert
result, pp = PublishedPage.publish!(current_user, fetch_topic, params[:published_page][:slug].strip)
pp_params = params.require(:published_page)
result, pp = PublishedPage.publish!(
current_user,
fetch_topic,
pp_params[:slug].strip,
pp_params.permit(:public)
)
json_result(pp, serializer: PublishedPageSerializer) { result }
end
@ -68,4 +92,13 @@ private
raise Discourse::NotFound unless SiteSetting.enable_page_publishing?
end
def enforce_login_required!
if SiteSetting.login_required? &&
!current_user &&
!SiteSetting.show_published_pages_login_required? &&
redirect_to_login
true
end
end
end