Skip to content

Commit

Permalink
Merge branch 'active-storage-integration' of github.com:bichinger/alc…
Browse files Browse the repository at this point in the history
…hemy_cms into active-storage-integration

* 'active-storage-integration' of github.com:bichinger/alchemy_cms:
  v5.0.0
  Do not convert JPEG images into JPG (AlchemyCMS#1904)
  Do not enable image cropper if file is missing (AlchemyCMS#1903)
  Always show original image as zoomed image (AlchemyCMS#1902)
  Rename Attachment#urlname into slug (AlchemyCMS#1848)
  Deprecate toolbar helper
  Bump version to 5.0.0.rc2
  Fix tag-list height
  Fix vertical position of site name in page tab
  Allow editing sites
  Fix missing help_text_text translations
  • Loading branch information
bichinger-stm committed Jul 17, 2020
2 parents 6b5fd8b + 0e21090 commit 2baa33f
Show file tree
Hide file tree
Showing 26 changed files with 162 additions and 77 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## 5.0.0 (unreleased)
## 5.0.0 (2020-07-17)

- Do not convert JPEG images into JPG [#1904](https://github.com/AlchemyCMS/alchemy_cms/pull/1904) ([tvdeyen](https://github.com/tvdeyen))
- Do not enable image cropper if file is missing [#1903](https://github.com/AlchemyCMS/alchemy_cms/pull/1903) ([tvdeyen](https://github.com/tvdeyen))
- Always show original image as zoomed image [#1902](https://github.com/AlchemyCMS/alchemy_cms/pull/1902) ([tvdeyen](https://github.com/tvdeyen))
- Rename Attachment#urlname into slug [#1848](https://github.com/AlchemyCMS/alchemy_cms/pull/1848) ([tvdeyen](https://github.com/tvdeyen))
- Deprecate toolbar helper ([tvdeyen](https://github.com/tvdeyen))
- Deprecate redirect_to_public_child ([tvdeyen](https://github.com/tvdeyen))
- Add --auto-accept option to installer ([tvdeyen](https://github.com/tvdeyen))
- Move all installer code into install generator ([tvdeyen](https://github.com/tvdeyen))
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/alchemy/navigation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,6 @@
color: $muted-text-color;
margin-right: $default-margin;
font-size: $small-font-size;
line-height: 31px;
}
}
4 changes: 2 additions & 2 deletions app/assets/stylesheets/alchemy/tags.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
padding-bottom: 138px;

&.filtered {
padding-bottom: 164px;
padding-bottom: 178px;
}

&.with_filter_bar {
padding-bottom: 218px;

&.filtered {
padding-bottom: 244px;
padding-bottom: 256px;
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/alchemy/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def destroy

def link
@attachments = Attachment.all.collect { |f|
[f.name, download_attachment_path(id: f.id, name: f.urlname)]
[f.name, download_attachment_path(id: f.id, name: f.slug)]
}
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/alchemy/admin/base_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ def toolbar(options = {})
end
end

deprecate toolbar: "Please use `content_for(:toolbar)` instead", deprecator: Alchemy::Deprecation

# (internal) Used by upload form
def new_asset_path_with_session_information(asset_type)
session_key = Rails.application.config.session_options[:key]
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/alchemy/url_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def show_page_path_params(page, optional_params = {})

# Returns the path for downloading an alchemy attachment
def download_alchemy_attachment_path(attachment)
alchemy.download_attachment_path(attachment, attachment.urlname)
alchemy.download_attachment_path(attachment, attachment.slug)
end

# Returns the url for downloading an alchemy attachment
def download_alchemy_attachment_url(attachment)
alchemy.download_attachment_url(attachment, attachment.urlname)
alchemy.download_attachment_url(attachment, attachment.slug)
end

# Returns the full url containing host, page and anchor for the given element
Expand Down
5 changes: 4 additions & 1 deletion app/models/alchemy/attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,13 @@ def to_jq_upload
end

# An url save filename without format suffix
def urlname
def slug
CGI.escape(file_name.gsub(/\.#{extension}$/, "").tr(".", " "))
end

alias_method :urlname, :slug
deprecate urlname: :slug, deprecator: Alchemy::Deprecation

# Checks if the attachment is restricted, because it is attached on restricted pages only
def restricted?
pages.any? && pages.not_restricted.blank?
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/essence_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def attachment_url

routes.download_attachment_path(
id: attachment.id,
name: attachment.urlname,
name: attachment.slug,
format: attachment.suffix,
)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/alchemy/essence_picture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def allow_image_cropping?
picture.can_be_cropped_to(
content.settings[:size],
content.settings[:upsample],
)
) && !!picture.image_file
end

def crop_values_present?
Expand Down
6 changes: 4 additions & 2 deletions app/models/alchemy/picture/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ def encoded_image(image, options = {})

encoding_options = []

if target_format =~ /jpe?g/
convert_format = target_format != image_file_format.sub("jpeg", "jpg")

if target_format =~ /jpe?g/ && convert_format
quality = options[:quality] || Config.get(:output_image_jpg_quality)
encoding_options << "-quality #{quality}"
end
Expand All @@ -80,7 +82,7 @@ def encoded_image(image, options = {})
encoding_options << "-flatten"
end

convertion_needed = target_format != image_file_format || encoding_options.present?
convertion_needed = convert_format || encoding_options.present?

if has_convertible_format? && convertion_needed
image = image.encode(target_format, encoding_options.join(" "))
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/pictures/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="zoomed-picture-background">
<%= image_tag @picture.url(format: @picture.image_file_format) %>
<%= image_tag @picture.url %>
</div>

<div class="picture-overlay-navigation">
Expand Down
43 changes: 21 additions & 22 deletions app/views/alchemy/admin/resources/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
<% label_title = Alchemy.t("Create #{resource_name}", default: Alchemy.t('Create')) %>

<% toolbar(
buttons: [
{
icon: :plus,
label: label_title,
url: new_resource_path,
<% content_for(:toolbar) do %>
<%= toolbar_button(
icon: :plus,
label: label_title,
url: new_resource_path,
title: label_title,
hotkey: 'alt+n',
dialog_options: {
title: label_title,
hotkey: 'alt+n',
dialog_options: {
title: label_title,
size: resource_window_size
},
if_permitted_to: [:create, resource_model]
size: resource_window_size
},
{
icon: 'download',
url: resource_url_proxy.url_for(action: 'index', format: 'csv', q: search_filter_params[:q], sort: params[:sort]),
label: Alchemy.t(:download_csv),
title: Alchemy.t(:download_csv),
dialog: false,
if_permitted_to: [:index, resource_model]
}
]
) %>
if_permitted_to: [:create, resource_model]
) %>
<%= toolbar_button(
icon: :download,
url: resource_url_proxy.url_for(action: 'index', format: 'csv', q: search_filter_params[:q], sort: params[:sort]),
label: Alchemy.t(:download_csv),
title: Alchemy.t(:download_csv),
dialog: false,
if_permitted_to: [:index, resource_model]
) %>
<%= render 'alchemy/admin/partials/search_form' %>
<% end %>

<div id="archive_all" class="resources-table-wrapper<%= ' with_tag_filter' if resource_has_tags || resource_has_filters %>">
<%= render 'alchemy/admin/resources/table_header' %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/alchemy/admin/sites/_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<%= alchemy_form_for site, url: alchemy.admin_sites_path(site, search_filter_params) do |f| %>
<%= f.input :host, hint: resource_handler.help_text_for(name: :host).html_safe %>
<%= alchemy_form_for site, url: resource_path(site, search_filter_params) do |f| %>
<%= f.input :host, hint: resource_handler.help_text_for(name: :host)&.html_safe %>
<%= f.input :name %>
<%= f.input :public %>
<%= f.input :aliases, hint: resource_handler.help_text_for(name: :aliases), input_html: {rows: 4} %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/alchemy/essences/_essence_file_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
attachment.name,
alchemy.download_attachment_path(
attachment,
name: attachment.urlname,
name: attachment.slug,
format: attachment.suffix
),
{
Expand Down
4 changes: 2 additions & 2 deletions lib/alchemy/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ def engine_name
@module_definition && @module_definition["engine_name"]
end

# Returns a help text for resource's form
# Returns a help text for resource's form or nil if no help text is available
#
# === Example:
#
Expand All @@ -223,7 +223,7 @@ def engine_name
def help_text_for(attribute)
::I18n.translate!(attribute[:name], scope: [:alchemy, :resource_help_texts, resource_name])
rescue ::I18n::MissingTranslationData
false
nil
end

# Return attributes that should be viewable but not editable.
Expand Down
2 changes: 1 addition & 1 deletion lib/alchemy/version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module Alchemy
VERSION = "5.0.0.rc1"
VERSION = "5.0.0"

def self.version
VERSION
Expand Down
3 changes: 3 additions & 0 deletions spec/dummy/config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ en:
essence_text: This content type (Essence) represents a simple line of text
default_content_texts:
welcome: Welcome to my site
resource_help_texts:
party:
name: Party
19 changes: 19 additions & 0 deletions spec/features/admin/site_editing_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "Site editing feature", type: :system do
before { authorize_user(:as_admin) }

it "can create a new page" do
visit alchemy.new_admin_site_path
fill_in "site_host", with: "api.example.com"
fill_in "site_name", with: "API Site"
click_button "Save"
expect(page).to have_content "You need at least one language to work with. Please create one below."
visit alchemy.edit_admin_site_path(Alchemy::Site.first)
fill_in "Aliases", with: "api.localhost"
click_button "Save"
expect(page).to have_content "api.localhost"
end
end
Binary file added spec/fixtures/image4.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 9 additions & 9 deletions spec/helpers/alchemy/url_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module Alchemy

context "with addiitonal parameters" do
subject(:show_page_path_params) do
helper.show_page_path_params(page, {query: "test"})
helper.show_page_path_params(page, { query: "test" })
end

it "returns a Hash with urlname, no locale and query parameter" do
Expand All @@ -52,7 +52,7 @@ module Alchemy

context "with additional parameters" do
subject(:show_page_path_params) do
helper.show_page_path_params(page, {query: "test"})
helper.show_page_path_params(page, { query: "test" })
end

it "returns a Hash with urlname, locale and query parameter" do
Expand All @@ -74,7 +74,7 @@ module Alchemy
end

it "should return the correct relative path string with additional parameters" do
expect(helper.show_alchemy_page_path(page, {query: "test"})).to \
expect(helper.show_alchemy_page_path(page, { query: "test" })).to \
eq("/#{page.language_code}/testpage?query=test")
end
end
Expand All @@ -89,7 +89,7 @@ module Alchemy
end

it "should return the correct relative path string with additional parameter" do
expect(helper.show_alchemy_page_path(page, {query: "test"})).to \
expect(helper.show_alchemy_page_path(page, { query: "test" })).to \
eq("/testpage?query=test")
end
end
Expand All @@ -107,7 +107,7 @@ module Alchemy
end

it "should return the correct url string with additional parameters" do
expect(helper.show_alchemy_page_url(page, {query: "test"})).to \
expect(helper.show_alchemy_page_url(page, { query: "test" })).to \
eq("http://#{helper.request.host}/#{page.language_code}/testpage?query=test")
end
end
Expand All @@ -123,24 +123,24 @@ module Alchemy
end

it "should return the correct url string with additional parameter" do
expect(helper.show_alchemy_page_url(page, {query: "test"})).to \
expect(helper.show_alchemy_page_url(page, { query: "test" })).to \
eq("http://#{helper.request.host}/testpage?query=test")
end
end
end
end

context "attachment path helpers" do
let(:attachment) { mock_model(Attachment, urlname: "test-attachment.pdf") }
let(:attachment) { mock_model(Attachment, slug: "test-attachment.pdf") }

it "should return the correct relative path to download an attachment" do
expect(helper.download_alchemy_attachment_path(attachment)).to \
eq("/attachment/#{attachment.id}/download/#{attachment.urlname}")
eq("/attachment/#{attachment.id}/download/#{attachment.slug}")
end

it "should return the correct url to download an attachment" do
expect(helper.download_alchemy_attachment_url(attachment)).to \
eq("http://#{helper.request.host}/attachment/#{attachment.id}/download/#{attachment.urlname}")
eq("http://#{helper.request.host}/attachment/#{attachment.id}/download/#{attachment.slug}")
end
end

Expand Down
9 changes: 9 additions & 0 deletions spec/libraries/resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,14 @@ module Alchemy
expect(resource.in_engine?).to eq(true)
end
end

describe "#help_text_for" do
it "should return a text as string for an attribute" do
expect(resource.help_text_for(name: :name)).to eq("Party")
end
it "should return nil for a nonexistent attribute" do
expect(resource.help_text_for(name: :nonexistent_attribute_dummy)).to be_nil
end
end
end
end
8 changes: 4 additions & 4 deletions spec/models/alchemy/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,22 @@ module Alchemy
describe "urlname sanitizing" do
it "escapes unsafe url characters" do
attachment.file_name = "f#%&cking cute kitten pic.png"
expect(attachment.urlname).to eq("f%23%25%26cking+cute+kitten+pic")
expect(attachment.slug).to eq("f%23%25%26cking+cute+kitten+pic")
end

it "removes format suffix from end of file name" do
attachment.file_name = "pic.png.png"
expect(attachment.urlname).to eq("pic+png")
expect(attachment.slug).to eq("pic+png")
end

it "converts dots into escaped spaces" do
attachment.file_name = "cute.kitten.pic.png"
expect(attachment.urlname).to eq("cute+kitten+pic")
expect(attachment.slug).to eq("cute+kitten+pic")
end

it "escapes umlauts in the name" do
attachment.file_name = "süßes katzenbild.png"
expect(attachment.urlname).to eq("s%C3%BC%C3%9Fes+katzenbild")
expect(attachment.slug).to eq("s%C3%BC%C3%9Fes+katzenbild")
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/models/alchemy/essence_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module Alchemy
subject { essence.attachment_url }

it "returns the download attachment url." do
is_expected.to match(/\/attachment\/#{attachment.id}\/download\/#{attachment.urlname}\.#{attachment.suffix}/)
is_expected.to match(/\/attachment\/#{attachment.id}\/download\/#{attachment.slug}\.#{attachment.suffix}/)
end

context "without attachment assigned" do
Expand Down
Loading

0 comments on commit 2baa33f

Please sign in to comment.