mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FEATURE: allows published pages to be public (#10053)
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user