Skip to content

Commit

Permalink
Merge pull request AlchemyCMS#1868 from tvdeyen/remove-attach-to-menu
Browse files Browse the repository at this point in the history
Remove Page#visible
tvdeyen authored Jun 5, 2020
2 parents 9a19906 + e815878 commit 71bf393
Showing 29 changed files with 103 additions and 318 deletions.
6 changes: 5 additions & 1 deletion app/assets/stylesheets/alchemy/sitemap.scss
Original file line number Diff line number Diff line change
@@ -197,6 +197,10 @@ $sitemap-url-xlarge-width: 350px;

.page_status {
display: inline-block;

.alchemy-dialog & {
display: block;
}
}

#sitemap_heading {
@@ -226,7 +230,7 @@ $sitemap-url-xlarge-width: 350px;

.page_status {
padding-left: 2 * $default-padding;
margin-right: 214px;
margin-right: 188px;
margin-left: auto;

@media screen and (min-width: $large-screen-break-point) {
12 changes: 1 addition & 11 deletions app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
@@ -291,24 +291,14 @@ def create_tree(items, rootpage)
# This function will add a node's own slug into their ancestor's path
# in order to create the full URL of a node
#
# NOTE: Invisible pages are not part of the full path of their children
#
# @param [String]
# The node's ancestors path
# @param [Hash]
# A children node
#
def process_url(ancestors_path, item)
default_urlname = (ancestors_path.blank? ? "" : "#{ancestors_path}/") + item["slug"].to_s

pair = { my_urlname: default_urlname, children_path: default_urlname }

if item["visible"] == false
# children ignore an ancestor in their path if invisible
pair[:children_path] = ancestors_path
end

pair
{ my_urlname: default_urlname, children_path: default_urlname }
end

def load_page
21 changes: 0 additions & 21 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
@@ -17,7 +17,6 @@
# rgt :integer
# parent_id :integer
# depth :integer
# visible :boolean default(FALSE)
# locked_by :integer
# restricted :boolean default(FALSE)
# robot_index :boolean default(TRUE)
@@ -44,7 +43,6 @@ class Page < BaseRecord

DEFAULT_ATTRIBUTES_FOR_COPY = {
autogenerate_elements: false,
visible: false,
public_on: nil,
public_until: nil,
locked_at: nil,
@@ -78,7 +76,6 @@ class Page < BaseRecord
:tag_list,
:title,
:urlname,
:visible,
:layoutpage,
:menu_id,
]
@@ -138,9 +135,6 @@ class Page < BaseRecord
after_update :create_legacy_url,
if: :saved_change_to_urlname?

after_update :attach_to_menu!,
if: :should_attach_to_menu?

after_update -> { nodes.update_all(updated_at: Time.current) }

# Concerns
@@ -152,8 +146,6 @@ class Page < BaseRecord
# site_name accessor
delegate :name, to: :site, prefix: true, allow_nil: true

attr_accessor :menu_id

# Class methods
#
class << self
@@ -545,18 +537,5 @@ def create_legacy_url
def set_published_at
self.published_at = Time.current
end

def attach_to_menu!
node = Alchemy::Node.find_by!(id: menu_id, language_id: language_id)
node.children.create!(
language_id: language_id,
page_id: id,
name: name,
)
end

def should_attach_to_menu?
menu_id.present? && nodes.none?
end
end
end
1 change: 0 additions & 1 deletion app/models/alchemy/page/fixed_attributes.rb
Original file line number Diff line number Diff line change
@@ -15,7 +15,6 @@ module Alchemy
# fixed_attributes:
# - public_on: nil
# - public_until: nil
# - visible: false
#
class Page::FixedAttributes
attr_reader :page
50 changes: 12 additions & 38 deletions app/models/alchemy/page/page_naming.rb
Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ module Page::PageNaming
if: -> { title.blank? }

after_update :update_descendants_urlnames,
if: :should_update_descendants_urlnames?
if: :saved_change_to_urlname?

after_move :update_urlname!
end
@@ -35,7 +35,7 @@ def renamed?
# Makes a slug of all ancestors urlnames including mine and delimit them be slash.
# So the whole path is stored as urlname in the database.
def update_urlname!
new_urlname = nested_url_name(slug)
new_urlname = nested_url_name
if urlname != new_urlname
legacy_urls.create(urlname: urlname)
update_column(:urlname, new_urlname)
@@ -47,25 +47,8 @@ def slug
urlname.to_s.split("/").last
end

# Returns an array of visible/non-language_root ancestors.
def visible_ancestors
return [] unless parent

if new_record?
parent.visible_ancestors.tap do |base|
base.push(parent) if parent.visible?
end
else
ancestors.visible.contentpages.where(language_root: nil).to_a
end
end

private

def should_update_descendants_urlnames?
saved_change_to_urlname? || saved_change_to_visible?
end

def update_descendants_urlnames
reload
descendants.each(&:update_urlname!)
@@ -75,7 +58,7 @@ def update_descendants_urlnames
# Either from name, or if present, from urlname.
# The urlname contains the whole path including parent urlnames.
def set_urlname
self[:urlname] = nested_url_name(slug)
self[:urlname] = nested_url_name
end

def set_title
@@ -87,26 +70,17 @@ def set_title
# Names shorter than 3 will be filled up with dashes,
# so it does not collidate with the language code.
#
def convert_url_name(value)
url_name = convert_to_urlname(value.blank? ? name : value)
if url_name.length < 3
("-" * (3 - url_name.length)) + url_name
else
url_name
end
end

def nested_url_name(value)
(ancestor_slugs << convert_url_name(value)).join("/")
def converted_url_name
url_name = convert_to_urlname(slug.blank? ? name : slug)
url_name.rjust(3, "-")
end

# Slugs of all visible/non-language_root ancestors.
# Returns [], if there is no parent, the parent is
# the root page itself.
def ancestor_slugs
return [] if parent.nil?

visible_ancestors.map(&:slug).compact
def nested_url_name
if parent&.language_root?
converted_url_name
else
[parent&.urlname, converted_url_name].compact.join("/")
end
end
end
end
1 change: 0 additions & 1 deletion app/models/alchemy/page/page_natures.rb
Original file line number Diff line number Diff line change
@@ -61,7 +61,6 @@ def locked?
def status
{
public: public?,
visible: visible?,
locked: locked?,
restricted: restricted?,
}
4 changes: 0 additions & 4 deletions app/models/alchemy/page/page_scopes.rb
Original file line number Diff line number Diff line change
@@ -32,10 +32,6 @@ module Page::PageScopes
#
scope :not_locked, -> { where(locked_at: nil, locked_by: nil) }

# All visible pages
#
scope :visible, -> { where(visible: true) }

# All not restricted pages
#
scope :not_restricted, -> { where(restricted: false) }
2 changes: 0 additions & 2 deletions app/serializers/alchemy/page_tree_serializer.rb
Original file line number Diff line number Diff line change
@@ -53,7 +53,6 @@ def page_hash(page, has_children, level, folded)
id: page.id,
name: page.name,
public: page.public?,
visible: page.visible?,
restricted: page.restricted?,
page_layout: page.page_layout,
slug: page.slug,
@@ -105,7 +104,6 @@ def page_permissions(page, ability)
def page_status_titles(page)
{
public: page.status_title(:public),
visible: page.status_title(:visible),
restricted: page.status_title(:restricted),
}
end
1 change: 0 additions & 1 deletion app/views/alchemy/admin/pages/_form.html.erb
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
<div class="control_group">
<%= render 'alchemy/admin/pages/publication_fields' %>
<%= page_status_checkbox(@page, :restricted) %>
<%= render 'alchemy/admin/pages/menu_fields', f: f %>
<% if configuration(:sitemap)['show_flag'] %>
<%= page_status_checkbox(@page, :sitemap) %>
<% end %>
33 changes: 0 additions & 33 deletions app/views/alchemy/admin/pages/_menu_fields.html.erb

This file was deleted.

6 changes: 1 addition & 5 deletions app/views/alchemy/admin/pages/_page.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<li id="page_{{id}}" class="page_level_{{level}} {{page_layout}}" data-slug="{{slug}}" data-restricted="{{restricted}}" data-visible="{{visible}}">
<li id="page_{{id}}" class="page_level_{{level}} {{page_layout}}" data-slug="{{slug}}" data-restricted="{{restricted}}">
<div class="sitemap_page{{#if locked}} locked{{/if}}" name="{{name}}">
<div class="sitemap_left_images<% if @sorting %>{{#unless root}} handle{{/unless}}<% end %>">
<% unless @sorting %>
@@ -150,10 +150,6 @@
<i class="icon fas fa-fw fa-compass {{#unless public}}disabled{{/unless}}" data-fa-transform="shrink-2"></i>
<span class="hint-bubble">{{status_titles.public}}</span>
</span>
<span class="page_status with-hint">
<i class="icon fas fa-fw fa-eye {{#unless visible}}disabled{{/unless}}" data-fa-transform="shrink-2"></i>
<span class="hint-bubble">{{status_titles.visible}}</span>
</span>
<span class="page_status with-hint">
<i class="icon fas fa-fw fa-lock {{#unless restricted}}disabled{{/unless}}" data-fa-transform="shrink-2"></i>
<span class="hint-bubble">{{status_titles.restricted}}</span>
4 changes: 0 additions & 4 deletions app/views/alchemy/admin/pages/_page_infos.html.erb
Original file line number Diff line number Diff line change
@@ -2,10 +2,6 @@
<%= render_icon(:compass, transform: 'shrink-2', class: @page.public? ? nil : 'disabled') %>
<span class="hint-bubble"><%= page.status_title(:public) %></span>
</span>
<span class="page_status with-hint">
<%= render_icon(:eye, transform: 'shrink-2', class: @page.visible? ? nil : 'disabled') %>
<span class="hint-bubble"><%= page.status_title(:visible) %></span>
</span>
<span class="page_status with-hint">
<%= render_icon(:lock, transform: 'shrink-2', class: @page.restricted? ? nil : 'disabled') %>
<span class="hint-bubble"><%= page.status_title(:restricted) %></span>
4 changes: 0 additions & 4 deletions app/views/alchemy/admin/pages/info.html.erb
Original file line number Diff line number Diff line change
@@ -24,10 +24,6 @@
<%= render_icon(:compass, transform: 'shrink-2', class: @page.public? ? nil : 'disabled') %>
<%= @page.status_title(:public) %>
</span>
<span class="page_status">
<%= render_icon(:eye, transform: 'shrink-2', class: @page.visible? ? nil : 'disabled') %>
<%= @page.status_title(:visible) %>
</span>
<span class="page_status">
<%= render_icon(:lock, transform: 'shrink-2', class: @page.restricted? ? nil : 'disabled') %>
<%= @page.status_title(:restricted) %>
2 changes: 1 addition & 1 deletion config/alchemy/config.yml
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ auto_logout_time: 30

# === Redirect Options
#
# redirect_to_public_child [Boolean] # Alchemy redirects to the first public child page found, if a page is not visible.
# redirect_to_public_child [Boolean] # Alchemy redirects to the first public child page found, if a page is not public.
#
redirect_to_public_child: true

5 changes: 0 additions & 5 deletions config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
@@ -481,9 +481,6 @@ en:
page_published: "Published page"
page_restricted: "restricted"
page_states:
visible:
"true": "Page is visible in navigation."
"false": "Page is not visible in navigation."
public:
"true": "Page is published."
"false": "Page is unpublished."
@@ -578,7 +575,6 @@ en:
button_label: Upload image(s)
upload_success: "Picture %{name} uploaded successfully"
upload_failure: "Error while uploading %{name}: %{error}"
visible: "visible"
want_to_create_new_language: "Do you want to create a new empty language tree?"
want_to_make_copy_of_existing_language: "Do you want to copy an existing language tree?"
"We need at least one default.": "A default language must exist."
@@ -826,7 +822,6 @@ en:
updated_at: "Updated at"
urlname: "URL-Path"
slug: "Slug"
visible: "visible in navigation"
alchemy/picture:
image_file_name: "Filename"
image_file_height: "Height"
24 changes: 24 additions & 0 deletions db/migrate/20200519073500_remove_visible_from_alchemy_pages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true
class RemoveVisibleFromAlchemyPages < ActiveRecord::Migration[5.2]
class LocalPage < ActiveRecord::Base
self.table_name = "alchemy_pages"

scope :invisible, -> { where(visible: [false, nil]) }
scope :contentpages, -> { where(layoutpage: [false, nil]) }
end

def up
if LocalPage.invisible.contentpages.where.not(parent_id: nil).any?
abort "You have invisible pages in your database! " \
"Please re-structure your page tree before running this migration. " \
"You might also downgrade to Alchemy 4.6 and " \
"run the `alchemy:upgrade:4.6:restructure_page_tree` rake task."
end

remove_column :alchemy_pages, :visible
end

def down
add_column :alchemy_pages, :visible, :boolean, default: false
end
end
4 changes: 2 additions & 2 deletions lib/alchemy/permissions.rb
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ def initialize(user)
module GuestUser
def alchemy_guest_user_rules
can([:show, :download], Alchemy::Attachment) { |a| !a.restricted? }
can :see, Alchemy::Page, restricted: false, visible: true
can :see, Alchemy::Page, restricted: false

can :read, Alchemy::Content, Alchemy::Content.available.not_restricted do |c|
c.public? && !c.restricted? && !c.trashed?
@@ -64,7 +64,7 @@ def alchemy_member_rules

# Resources
can [:show, :download], Alchemy::Attachment
can :see, Alchemy::Page, restricted: true, visible: true
can :see, Alchemy::Page, restricted: true

can :read, Alchemy::Content, Alchemy::Content.available do |c|
c.public? && !c.trashed?
6 changes: 3 additions & 3 deletions spec/controllers/alchemy/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -256,9 +256,9 @@ module Alchemy
describe "url nesting" do
render_views

let(:catalog) { create(:alchemy_page, :public, name: "Catalog", urlname: "catalog", parent: default_language_root, language: default_language, visible: true) }
let(:products) { create(:alchemy_page, :public, name: "Products", urlname: "products", parent: catalog, language: default_language, visible: true) }
let(:product) { create(:alchemy_page, :public, name: "Screwdriver", urlname: "screwdriver", parent: products, language: default_language, autogenerate_elements: true, visible: true) }
let(:catalog) { create(:alchemy_page, :public, name: "Catalog", urlname: "catalog", parent: default_language_root, language: default_language) }
let(:products) { create(:alchemy_page, :public, name: "Products", urlname: "products", parent: catalog, language: default_language) }
let(:product) { create(:alchemy_page, :public, name: "Screwdriver", urlname: "screwdriver", parent: products, language: default_language, autogenerate_elements: true) }

before do
allow(Alchemy.user_class).to receive(:admins).and_return(OpenStruct.new(count: 1))
1 change: 0 additions & 1 deletion spec/dummy/config/alchemy/page_layouts.yml
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
page_layout: readonly
public_on: ~
public_until: ~
visible: false
restricted: false
name: false
urlname: false
3 changes: 1 addition & 2 deletions spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_05_14_091507) do
ActiveRecord::Schema.define(version: 2020_05_19_073500) do

create_table "alchemy_attachments", force: :cascade do |t|
t.string "name"
@@ -216,7 +216,6 @@
t.integer "rgt"
t.integer "parent_id"
t.integer "depth"
t.boolean "visible", default: false
t.integer "locked_by"
t.boolean "restricted", default: false
t.boolean "robot_index", default: true
2 changes: 1 addition & 1 deletion spec/features/admin/dashboard_spec.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
end

describe "Locked pages summary" do
let(:a_page) { create(:alchemy_page, :public, visible: true) }
let(:a_page) { create(:alchemy_page, :public) }

it "should initially show no pages are locked" do
visit admin_dashboard_path
2 changes: 1 addition & 1 deletion spec/features/admin/page_editing_feature_spec.rb
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@
end

context "as admin" do
let(:a_page) { create(:alchemy_page, :public, visible: true) }
let(:a_page) { create(:alchemy_page, :public) }

before { authorize_user(:as_admin) }

8 changes: 4 additions & 4 deletions spec/features/page_feature_spec.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
end

let(:public_page) do
create(:alchemy_page, :public, visible: true, name: "Page 1")
create(:alchemy_page, :public, name: "Page 1")
end

let(:public_child) do
@@ -139,12 +139,12 @@
describe "navigation rendering" do
context "with menu available" do
let(:menu) { create(:alchemy_node, menu_type: "main_menu") }
let(:page1) { create(:alchemy_page, :public, visible: true, name: "Page 1") }
let(:page2) { create(:alchemy_page, :public, visible: true, name: "Page 2") }
let(:page1) { create(:alchemy_page, :public, name: "Page 1") }
let(:page2) { create(:alchemy_page, :public, name: "Page 2") }
let!(:node1) { create(:alchemy_node, page: page1, parent: menu) }
let!(:node2) { create(:alchemy_node, page: page2, parent: menu) }

it "should show the navigation with all visible pages" do
it "should show the navigation with all pages" do
visit "/"
within("nav ul") do
expect(page).to have_selector('li a[href="/page-1"], li a[href="/page-2"]')
13 changes: 5 additions & 8 deletions spec/features/page_redirects_spec.rb
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
end

let(:public_page) do
create(:alchemy_page, :public, visible: true, name: "Page 1")
create(:alchemy_page, :public, name: "Page 1")
end

let(:public_child) do
@@ -89,7 +89,6 @@
before do
public_page.update(
public_on: nil,
visible: false,
name: "Not Public",
urlname: "",
)
@@ -98,7 +97,7 @@

it "redirects to public child" do
visit "/not-public"
expect(page.current_path).to eq("/public-child")
expect(page.current_path).to eq("/not-public/public-child")
end

context "with only unpublished pages in page tree" do
@@ -117,7 +116,7 @@
it "redirects to public child with prefixed locale" do
allow(::I18n).to receive(:default_locale).and_return(:de)
visit "/not-public"
expect(page.current_path).to eq("/en/public-child")
expect(page.current_path).to eq("/en/not-public/public-child")
end
end
end
@@ -138,7 +137,6 @@
before do
default_language_root.update(
public_on: nil,
visible: false,
name: "Not Public",
urlname: "",
)
@@ -245,7 +243,6 @@
context "redirects to public child" do
before do
public_page.update(
visible: false,
public_on: nil,
name: "Not Public",
urlname: "",
@@ -255,12 +252,12 @@

it "if requested page is unpublished" do
visit "/not-public"
expect(page.current_path).to eq("/public-child")
expect(page.current_path).to eq("/not-public/public-child")
end

it "with normal url, if requested url has nested language code and is not public" do
visit "/en/not-public"
expect(page.current_path).to eq("/public-child")
expect(page.current_path).to eq("/not-public/public-child")
end
end

11 changes: 3 additions & 8 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -90,8 +90,8 @@ module Alchemy
end

describe "#render_breadcrumb" do
let(:parent) { create(:alchemy_page, :public, visible: true) }
let(:page) { create(:alchemy_page, :public, parent_id: parent.id, visible: true) }
let(:parent) { create(:alchemy_page, :public) }
let(:page) { create(:alchemy_page, :public, parent_id: parent.id) }
let(:user) { nil }

before do
@@ -126,12 +126,7 @@ module Alchemy
end
end

it "should render a breadcrumb of visible pages only" do
page.update_columns(visible: false, urlname: "a-invisible-page", name: "A Invisible Page", title: "A Invisible Page")
expect(helper.render_breadcrumb(page: page)).not_to match(/A Invisible Page/)
end

it "should render a breadcrumb of visible and unpublished pages" do
it "should render a breadcrumb of unpublished pages" do
page.update_columns(public_on: nil, urlname: "a-unpublic-page", name: "A Unpublic Page", title: "A Unpublic Page")
expect(helper.render_breadcrumb(page: page)).to match(/A Unpublic Page/)
end
52 changes: 20 additions & 32 deletions spec/libraries/permissions_spec.rb
Original file line number Diff line number Diff line change
@@ -6,21 +6,18 @@
describe Alchemy::Permissions do
subject { ability }

let(:ability) { Alchemy::Permissions.new(user) }
let(:attachment) { mock_model(Alchemy::Attachment, restricted?: false) }
let(:restricted_attachment) { mock_model(Alchemy::Attachment, restricted?: true) }
let(:picture) { mock_model(Alchemy::Picture, restricted?: false) }
let(:restricted_picture) { mock_model(Alchemy::Picture, restricted?: true) }
let(:public_page) { build_stubbed(:alchemy_page, :public, restricted: false) }
let(:unpublic_page) { build_stubbed(:alchemy_page) }
let(:visible_page) { build_stubbed(:alchemy_page, restricted: false, visible: true) }
let(:not_visible_page) { build_stubbed(:alchemy_page, :public, restricted: false, visible: false) }
let(:restricted_page) { build_stubbed(:alchemy_page, :public, restricted: true) }
let(:visible_restricted_page) { build_stubbed(:alchemy_page, visible: true, restricted: true) }
let(:published_element) { mock_model(Alchemy::Element, restricted?: false, public?: true, trashed?: false) }
let(:restricted_element) { mock_model(Alchemy::Element, restricted?: true, public?: true, trashed?: false) }
let(:published_content) { mock_model(Alchemy::Content, restricted?: false, public?: true, trashed?: false) }
let(:restricted_content) { mock_model(Alchemy::Content, restricted?: true, public?: true, trashed?: false) }
let(:ability) { Alchemy::Permissions.new(user) }
let(:attachment) { mock_model(Alchemy::Attachment, restricted?: false) }
let(:restricted_attachment) { mock_model(Alchemy::Attachment, restricted?: true) }
let(:picture) { mock_model(Alchemy::Picture, restricted?: false) }
let(:restricted_picture) { mock_model(Alchemy::Picture, restricted?: true) }
let(:public_page) { build_stubbed(:alchemy_page, :public, restricted: false) }
let(:unpublic_page) { build_stubbed(:alchemy_page) }
let(:restricted_page) { build_stubbed(:alchemy_page, :public, restricted: true) }
let(:published_element) { mock_model(Alchemy::Element, restricted?: false, public?: true, trashed?: false) }
let(:restricted_element) { mock_model(Alchemy::Element, restricted?: true, public?: true, trashed?: false) }
let(:published_content) { mock_model(Alchemy::Content, restricted?: false, public?: true, trashed?: false) }
let(:restricted_content) { mock_model(Alchemy::Content, restricted?: true, public?: true, trashed?: false) }

context "A guest user" do
let(:user) { nil }
@@ -42,9 +39,9 @@
is_expected.not_to be_able_to(:index, restricted_page)
end

it "can only see visible not restricted pages" do
is_expected.to be_able_to(:see, visible_page)
is_expected.not_to be_able_to(:see, not_visible_page)
it "can only see public not restricted pages" do
is_expected.to be_able_to(:see, public_page)
is_expected.not_to be_able_to(:see, restricted_page)
end

it "can only see public not restricted elements" do
@@ -82,13 +79,8 @@
is_expected.to be_able_to(:index, restricted_page)
end

it "can see visible restricted pages" do
is_expected.to be_able_to(:see, visible_page)
is_expected.to be_able_to(:see, visible_restricted_page)
end

it "can not see invisible pages" do
is_expected.not_to be_able_to(:see, not_visible_page)
it "can see restricted pages" do
is_expected.to be_able_to(:see, restricted_page)
end

it "can see public restricted elements" do
@@ -192,10 +184,6 @@
is_expected.to be_able_to(:publish, Alchemy::Page)
end

it "can not see invisible pages" do
is_expected.not_to be_able_to(:see, not_visible_page)
end

it "can clear the trash" do
is_expected.to be_able_to(:clear, :trash)
end
@@ -232,9 +220,9 @@
context "A logged in user without a role" do
let(:user) { mock_model(Alchemy.user_class, alchemy_roles: []) }

it "can only see visible not restricted pages (like the guest role)" do
is_expected.to be_able_to(:see, visible_page)
is_expected.not_to be_able_to(:see, not_visible_page)
it "can only see public not restricted pages (like the guest role)" do
is_expected.to be_able_to(:see, public_page)
is_expected.not_to be_able_to(:see, restricted_page)
end
end
end
105 changes: 9 additions & 96 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ module Alchemy
end

context "with another parent" do
let(:other_parent) { create(:alchemy_page, visible: true) }
let(:other_parent) { create(:alchemy_page) }

it "should be valid" do
contentpage.urlname = "existing_twice"
@@ -161,9 +161,9 @@ module Alchemy
end

context "after_move" do
let(:parent_1) { create(:alchemy_page, name: "Parent 1", visible: true) }
let(:parent_2) { create(:alchemy_page, name: "Parent 2", visible: true) }
let(:page) { create(:alchemy_page, parent: parent_1, name: "Page", visible: true) }
let(:parent_1) { create(:alchemy_page, name: "Parent 1") }
let(:parent_2) { create(:alchemy_page, name: "Parent 2") }
let(:page) { create(:alchemy_page, parent: parent_1, name: "Page") }

it "updates the urlname" do
expect(page.urlname).to eq("parent-1/page")
@@ -387,14 +387,6 @@ module Alchemy
expect(subject.name).to eq("#{page.name} (Copy)")
end

context "a visible page" do
let(:page) { create(:alchemy_page, name: "Source", visible: true) }

it "the copy should not be visible" do
expect(subject.visible).to be(false)
end
end

context "a public page" do
let(:page) { create(:alchemy_page, :public, name: "Source", public_until: Time.current) }

@@ -611,14 +603,6 @@ module Alchemy
end
end

describe ".visible" do
let!(:visible) { create(:alchemy_page, :public, visible: true) }

it "should return visible pages" do
expect(Page.visible.to_a).to eq([visible])
end
end

# InstanceMethods (a-z)

describe "#available_element_definitions" do
@@ -1554,11 +1538,9 @@ module Alchemy
end

context "urlname updating" do
let(:parentparent) { create(:alchemy_page, name: "parentparent", visible: true) }
let(:parent) { create(:alchemy_page, parent: parentparent, name: "parent", visible: true) }
let(:page) { create(:alchemy_page, parent: parent, name: "page", visible: true) }
let(:invisible) { create(:alchemy_page, parent: page, name: "invisible", visible: false) }
let(:contact) { create(:alchemy_page, parent: invisible, name: "contact", visible: true) }
let(:parentparent) { create(:alchemy_page, name: "parentparent") }
let(:parent) { create(:alchemy_page, parent: parentparent, name: "parent") }
let(:page) { create(:alchemy_page, parent: parent, name: "page") }
let(:language_root) { parentparent.parent }

it "should store all parents urlnames delimited by slash" do
@@ -1569,22 +1551,6 @@ module Alchemy
expect(page.urlname).not_to match(/startseite/)
end

it "should not include invisible pages" do
expect(contact.urlname).not_to match(/invisible/)
end

context "with an invisible parent" do
before { parent.update_attribute(:visible, false) }

it "does not change if set_urlname is called" do
expect { page.send(:set_urlname) }.not_to change { page.urlname }
end

it "does not change if update_urlname! is called" do
expect { page.update_urlname! }.not_to change { page.urlname }
end
end

context "after changing page's urlname" do
it "updates urlnames of descendants" do
page
@@ -1601,16 +1567,6 @@ module Alchemy
expect(page.legacy_urls.pluck(:urlname)).to include("parentparent/parent/page")
end
end

context "after updating my visibility" do
it "should update urlnames of descendants" do
page
parentparent.visible = false
parentparent.save!
page.reload
expect(page.urlname).to eq("parent/page")
end
end
end

describe "#update_node!" do
@@ -1712,12 +1668,12 @@ module Alchemy

context "page status methods" do
let(:page) do
build(:alchemy_page, :public, visible: true, restricted: false)
build(:alchemy_page, :public, restricted: false)
end

describe "#status" do
it "returns a combined status hash" do
expect(page.status).to eq({ public: true, visible: true, restricted: false, locked: false })
expect(page.status).to eq({ public: true, restricted: false, locked: false })
end
end

@@ -1726,10 +1682,6 @@ module Alchemy
expect(page.status_title(:public)).to eq("Page is published.")
end

it "returns a translated status string for visible status" do
expect(page.status_title(:visible)).to eq("Page is visible in navigation.")
end

it "returns a translated status string for locked status" do
expect(page.status_title(:locked)).to eq("")
end
@@ -1991,45 +1943,6 @@ module Alchemy
end
end

describe "#attach_to_menu!" do
let(:page) { create(:alchemy_page) }

context "if menu_id is set" do
let(:root_node) { create(:alchemy_node) }

before do
page.menu_id = root_node.id
end

context "and no nodes are present yet" do
it "attaches to menu" do
expect { page.save }.to change { page.nodes.count }.from(0).to(1)
end
end

context "and nodes are already present" do
let!(:page_node) { create(:alchemy_node, page: page) }

it "does not attach to menu" do
expect { page.save }.not_to change { page.nodes.count }
end
end
end

context "if menu_id is not set" do
it "does not attach to menu" do
expect { page.save }.not_to change { page.nodes.count }
end
end

context "if menu_id is empty" do
it "does not raise error" do
page.menu_id = ""
expect { page.save }.not_to raise_error
end
end
end

describe "#nodes" do
let(:page) { create(:alchemy_page) }
let(:node) { create(:alchemy_node, page: page, updated_at: 1.hour.ago) }
37 changes: 9 additions & 28 deletions spec/requests/alchemy/admin/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -88,9 +88,9 @@ module Alchemy

describe "#tree" do
let(:user) { create(:alchemy_dummy_user, :as_editor) }
let(:page_1) { create(:alchemy_page, visible: true, name: "one") }
let(:page_2) { create(:alchemy_page, visible: true, name: "two", parent_id: page_1.id) }
let(:page_3) { create(:alchemy_page, visible: true, name: "three", parent_id: page_2.id) }
let(:page_1) { create(:alchemy_page, name: "one") }
let(:page_2) { create(:alchemy_page, name: "two", parent_id: page_1.id) }
let(:page_3) { create(:alchemy_page, name: "three", parent_id: page_2.id) }
let!(:pages) { [page_1, page_2, page_3] }

subject :get_tree do
@@ -309,12 +309,12 @@ module Alchemy
end

describe "#order" do
let(:page_1) { create(:alchemy_page, visible: true) }
let(:page_2) { create(:alchemy_page, visible: true) }
let(:page_3) { create(:alchemy_page, visible: true) }
let(:page_item_1) { { id: page_1.id, slug: page_1.slug, restricted: false, visible: page_1.visible?, children: [page_item_2] } }
let(:page_item_2) { { id: page_2.id, slug: page_2.slug, restricted: false, visible: page_2.visible?, children: [page_item_3] } }
let(:page_item_3) { { id: page_3.id, slug: page_3.slug, restricted: false, visible: page_3.visible? } }
let(:page_1) { create(:alchemy_page) }
let(:page_2) { create(:alchemy_page) }
let(:page_3) { create(:alchemy_page) }
let(:page_item_1) { { id: page_1.id, slug: page_1.slug, restricted: false, children: [page_item_2] } }
let(:page_item_2) { { id: page_2.id, slug: page_2.slug, restricted: false, children: [page_item_3] } }
let(:page_item_3) { { id: page_3.id, slug: page_3.slug, restricted: false } }
let(:set_of_pages) { [page_item_1] }

it "stores the new order" do
@@ -331,25 +331,6 @@ module Alchemy
expect(page_3.urlname).to eq("#{page_1.slug}/#{page_2.slug}/#{page_3.slug}")
end

context "with invisible page in tree" do
let(:page_item_2) do
{
id: page_2.id,
slug: page_2.slug,
children: [page_item_3],
visible: false,
}
end

it "does not use this pages slug in urlnames of descendants" do
post order_admin_pages_path(set: set_of_pages.to_json), xhr: true
[page_1, page_2, page_3].map(&:reload)
expect(page_1.urlname).to eq(page_1.slug.to_s)
expect(page_2.urlname).to eq("#{page_1.slug}/#{page_2.slug}")
expect(page_3.urlname).to eq("#{page_1.slug}/#{page_3.slug}")
end
end

context "with restricted page in tree" do
let(:page_2) { create(:alchemy_page, restricted: true) }
let(:page_item_2) do

0 comments on commit 71bf393

Please sign in to comment.