Skip to content

Commit

Permalink
Merge pull request #2504 from tvdeyen/fix-tinymce-link
Browse files Browse the repository at this point in the history
Allow authors to link to all pages again
  • Loading branch information
tvdeyen authored Jun 30, 2023
2 parents 4a40764 + dfb17f9 commit a484a31
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 56 deletions.
7 changes: 1 addition & 6 deletions app/assets/javascripts/alchemy/alchemy.link_dialog.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,12 @@ class window.Alchemy.LinkDialog extends Alchemy.Dialog
initPageSelect: ->
pageTemplate = HandlebarsTemplates.page
element_anchor_placeholder = @$element_anchor.attr('placeholder')
if @link_object.dataset.languageId
api_url = "#{Alchemy.routes.api_pages_path}?language_id=#{@link_object.dataset.languageId}"
else
api_url = Alchemy.routes.api_pages_path

@$internal_link.select2
placeholder: Alchemy.t('Search page')
allowClear: true
minimumInputLength: 3
ajax:
url: api_url
url: Alchemy.routes.api_pages_path
datatype: 'json'
quietMillis: 300
data: (term, page) ->
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/alchemy/api/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class Api::PagesController < Api::BaseController
# Returns all pages as json object
#
def index
language = Alchemy::Language.find_by(id: params[:language_id]) || Alchemy::Language.current
@pages = Alchemy::Page.accessible_by(current_ability, :index)
@pages = @pages.where(language: language)
@pages = @pages.includes(*page_includes)
@pages = @pages.ransack(params[:q]).result

Expand Down
1 change: 0 additions & 1 deletion app/views/alchemy/ingredients/shared/_link_tools.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
onclick: 'new Alchemy.LinkDialog(this).open(); return false;',
class: "icon_button#{ingredient_editor.linked? ? ' linked' : ''} link-ingredient",
"data-parent-selector": "[data-ingredient-id='#{ingredient_editor.id}']",
"data-language-id": ingredient_editor.page&.language_id,
title: Alchemy.t(:place_link),
id: "edit_link_#{ingredient_editor.id}"
) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
class: picture_editor.linked? ? "linked" : nil,
title: Alchemy.t(:link_image),
"data-parent-selector": "[data-ingredient-id='#{picture_editor.id}']",
"data-language-id": picture_editor.page&.language_id,
id: "edit_link_#{picture_editor.id}"
} do %>
<span class="disabled" tabindex="-1"><%= render_icon(:link) %></span>
Expand Down
8 changes: 4 additions & 4 deletions lib/alchemy/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def alchemy_guest_user_rules
e.public? && !e.restricted?
end

can :read, Alchemy::Page, Alchemy::Page.published.not_restricted do |p|
p.public? && !p.restricted?
can :read, Alchemy::Page, Alchemy::Page.published.not_restricted.from_current_site do |p|
p.public? && !p.restricted? && p.site == Alchemy::Site.current
end
end
end
Expand All @@ -64,8 +64,8 @@ def alchemy_member_rules
e.public?
end

can :read, Alchemy::Page, Alchemy::Page.published do |p|
p.public?
can :read, Alchemy::Page, Alchemy::Page.published.from_current_site do |p|
p.public? && p.site == Alchemy::Site.current
end
end
end
Expand Down
37 changes: 12 additions & 25 deletions spec/controllers/alchemy/api/pages_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ module Alchemy
let(:language_2) { create(:alchemy_language, site: site_2) }
let!(:site_2_page) { create(:alchemy_page, :public, language: language_2) }
let!(:unpublished_page) { create(:alchemy_page, language: default_language) }
let!(:restricted_page) { create(:alchemy_page, :public, :restricted, language: default_language) }

context "as guest user" do
it "only returns public pages for current site" do
it "only returns published unrestricted pages for current site" do
get :index, format: :json
expect(result["pages"].map { |r| r["id"] }).to match_array([
page.parent_id,
Expand All @@ -97,43 +98,29 @@ module Alchemy
end
end

context "as author user" do
context "as member user" do
before do
authorize_user(build(:alchemy_dummy_user, :as_author))
authorize_user(build(:alchemy_dummy_user))
end

it "returns all pages for current site" do
it "only returns all published pages for current site" do
get :index, format: :json
expect(result["pages"].map { |r| r["id"] }).to match_array([
page.parent_id,
page.id,
unpublished_page.id
restricted_page.id
])
end
end
end

context "with language_id param" do
subject { get :index, params: {format: :json, language_id: try(:language)&.id} }

let!(:default_language_page) { create(:alchemy_page, :public, language: default_language, name: "same-name") }

context "when a language with that id exists" do
let(:language) { create(:alchemy_language, :klingon) }
let!(:default_language_page) { create(:alchemy_page, :public, language: default_language, name: "same-name") }
let!(:klingon_page) { create(:alchemy_page, :public, language: language, name: "same-name") }

it "only returns results from that language" do
subject
expect(result["pages"].map { |r| r["id"] }).to match_array [language.pages.root.id, klingon_page.id]
context "as author user" do
before do
authorize_user(build(:alchemy_dummy_user, :as_author))
end
end

context "when a language with that id does not exist" do
it "uses the default language" do
subject
expect(result["pages"].map { |r| r["id"] }).to include(default_language_page.id)
expect(result["pages"].map { |r| r["language_code"] }).not_to include("kl")
it "returns all pages" do
get :index, format: :json
expect(result["pages"].map { |r| r["id"] }).to match_array(Alchemy::Page.pluck(:id))
end
end
end
Expand Down
17 changes: 0 additions & 17 deletions spec/features/admin/link_overlay_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,6 @@
)
end

it "should only return pages from the language of the page being edited" do
page_in_other_language = create :alchemy_page, :public, language: create(:alchemy_language, language_code: "es", public: true)

visit edit_admin_page_path(page1)

within "#element_#{article.id}" do
fill_in "Intro", with: "Link me"
click_link "Link text"
end

within "#overlay_tab_internal_link" do
expect(page).to have_selector("#s2id_internal_link")
expect { select2(page_in_other_language.name, from: "Page") }.to raise_error(Capybara::ElementNotFound)
expect(find("#internal_link").value).not_to eq page_in_other_language.urlname
end
end

it "should be possible to link a page" do
visit edit_admin_page_path(page1)

Expand Down

0 comments on commit a484a31

Please sign in to comment.