Skip to content

Commit

Permalink
Disable page publish button if language is not yet public
Browse files Browse the repository at this point in the history
In order to tell people that they should publish the language before
publishing the page we disable the publish button with a nice little
notice.
  • Loading branch information
tvdeyen committed Feb 8, 2021
1 parent 1d5b84f commit 86e7223
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
4 changes: 0 additions & 4 deletions app/assets/stylesheets/alchemy/buttons.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ input.button {

&[disabled] {
cursor: not-allowed;

& + label {
display: none;
}
}
}

Expand Down
32 changes: 22 additions & 10 deletions app/views/alchemy/admin/pages/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,35 @@
<% end %>
<label><%= Alchemy.t(:page_properties) %></label>
</div>
<% if can?(:publish, @page) %>
<div class="button_with_label">
<%= form_tag alchemy.publish_admin_page_path(@page), id: 'publish_page_form' do %>
<%= button_tag class: 'icon_button', title: Alchemy.t(:explain_publishing) do %>
<%= render_icon('cloud-upload-alt') %>
<% end %>
<label><%= Alchemy.t("Publish page") %></label>
<div class="button_with_label">
<%= form_tag alchemy.publish_admin_page_path(@page), id: 'publish_page_form' do %>
<%= button_tag class: 'icon_button', disabled: cannot?(:publish, @page) do %>
<%= render_icon('cloud-upload-alt') %>
<% end %>
</div>
<% end %>
<label>
<% if @page.language.public? %>
<%= Alchemy.t(:explain_publishing) %>
<% elsif @page.editable_by?(current_alchemy_user) %>
<%= Alchemy.t(:publish_page_language_not_public) %>
<% else %>
<%= Alchemy.t(:publish_page_not_allowed) %>
<% end %>
</label>
<% end %>
</div>
<% unless @page.layoutpage? %>
<div class="button_with_label">
<%= form_tag alchemy.visit_admin_page_path(@page), id: 'visit_page_form' do %>
<%= button_tag class: 'icon_button', disabled: !@page.public? do %>
<%= render_icon('external-link-alt') %>
<% end %>
<label><%= Alchemy.t("Visit page") %></label>
<label>
<% if @page.public? %>
<%= Alchemy.t("Visit page") %>
<% else %>
<%= Alchemy.t(:cannot_visit_unpublic_page) %>
<% end %>
</label>
<% end %>
</div>
<% end %>
Expand Down
6 changes: 4 additions & 2 deletions config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ en:
"Please log in": "Please log in."
"Please seperate the tags with commata": "* Please seperate the tags with commas."
"Properties": "Properties"
"Publish page": "Publish page"
"Read the License": "Read the License"
"Redirects to": "Redirects to"
"Reload Preview": "Reload Preview"
Expand Down Expand Up @@ -334,6 +333,7 @@ en:
big_thumbnails: "Big thumbnails"
cancel: "cancel"
cannot_delete_picture_notice: "Cannot delete Picture %{name}, because it's still in use."
cannot_visit_unpublic_page: "Publish page before visiting it."
choose_file_to_link: "Please choose a file to link"
"clear clipboard": "clear clipboard"
click_to_show_all: "Click to show all again."
Expand Down Expand Up @@ -390,7 +390,7 @@ en:
element_saved: "Saved element."
enter_external_link: "Please enter the URL you want to link with"
explain_cropping: "<p>Move the frame and change its size with the mouse or arrow keys to adjust the image mask. Click on \"apply\" when you are satisfied with your selection.</p><p>If you want to return to the original centered image mask like it was defined in the layout, click \"reset\" and \"apply\" afterwards.</p>"
explain_publishing: "Publish the page and remove the cached version from the server."
explain_publishing: "Publish current page content"
explain_sitemap_dragndrop_sorting: "Tip: Drag the pages at the icon in order to sort them."
explain_unlocking: "Leave page and unlock it for other users."
external_link_notice_1: "Please enter the complete url with http:// or a similar protocol."
Expand Down Expand Up @@ -535,6 +535,8 @@ en:
'1024': '1024px (iPad - Landscape)'
'1280': '1280px (Desktop)'
preview_url: Preview
publish_page_language_not_public: Cannot publish page if language is not public
publish_page_not_allowed: You have not the permission to publish this page
recently_uploaded_only: 'Recently uploaded only'
"regular method": "Regular method"
remove: "Remove"
Expand Down
6 changes: 5 additions & 1 deletion lib/alchemy/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,12 @@ def alchemy_editor_rules
can([
:create,
:destroy,
:publish,
], Alchemy::Page) { |p| p.editable_by?(@user) }
end

can(:publish, Alchemy::Page) do |page|
page.language.public? && page.editable_by?(@user)
end

can :manage, Alchemy::Picture
can :manage, Alchemy::Attachment
Expand Down
2 changes: 1 addition & 1 deletion spec/features/admin/page_editing_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

it "cannot publish page." do
visit alchemy.edit_admin_page_path(a_page)
expect(page).to_not have_selector("#publish_page_form")
expect(page).to have_selector("#publish_page_form button[disabled]")
end

describe "the preview frame", :js do
Expand Down
18 changes: 16 additions & 2 deletions spec/libraries/permissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,22 @@
is_expected.to be_able_to(:switch_language, Alchemy::Page)
end

it "can publish pages" do
is_expected.to be_able_to(:publish, Alchemy::Page)
context "if page language is public" do
let(:language) { create(:alchemy_language, :german, public: true) }
let(:page) { create(:alchemy_page, language: language) }

it "can publish pages" do
is_expected.to be_able_to(:publish, page)
end
end

context "if page language is not public" do
let(:language) { create(:alchemy_language, :german, public: false) }
let(:page) { create(:alchemy_page, language: language) }

it "cannot publish pages" do
is_expected.to_not be_able_to(:publish, page)
end
end

it "can manage attachments" do
Expand Down

0 comments on commit 86e7223

Please sign in to comment.