Skip to content

Commit ca8a63d

Browse files
authored
Merge pull request #3388 from AlchemyCMS/permit-show-admin-page
Fix admin page preview permissions
2 parents 2d148f4 + 9456b60 commit ca8a63d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

app/controllers/alchemy/admin/pages_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def tree
7272
# Used by page preview iframe in Page#edit view.
7373
#
7474
def show
75+
authorize! :edit_content, @page
76+
7577
Current.preview_page = @page
7678
# Setting the locale to pages language, so the page content has it's correct translations.
7779
::I18n.locale = @page.language.locale

spec/requests/alchemy/admin/pages_controller_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ module Alchemy
1212
get admin_pages_path
1313
expect(request).to redirect_to(Alchemy.login_path)
1414
end
15+
16+
it "can not access page preview of a public page" do
17+
page = create(:alchemy_page, :public)
18+
get admin_page_path(page)
19+
expect(request).to redirect_to(Alchemy.login_path)
20+
end
1521
end
1622

1723
context "a member" do
@@ -21,6 +27,12 @@ module Alchemy
2127
get admin_pages_path
2228
expect(request).to redirect_to(root_path)
2329
end
30+
31+
it "can not access page preview of a public page" do
32+
page = create(:alchemy_page, :public)
33+
get admin_page_path(page)
34+
expect(request).to redirect_to("/")
35+
end
2436
end
2537

2638
context "with logged in editor user" do
@@ -274,6 +286,11 @@ module Alchemy
274286
let(:language) { create(:alchemy_language, locale: "nl") }
275287
let!(:page) { create(:alchemy_page, language: language) }
276288

289+
it "can be accessed" do
290+
get admin_page_path(page)
291+
expect(response).to be_successful
292+
end
293+
277294
it "should assign @preview_mode with true" do
278295
get admin_page_path(page)
279296
expect(assigns(:preview_mode)).to eq(true)

0 commit comments

Comments
 (0)