Commit Graph

348 Commits

Author SHA1 Message Date
Sean Doyle f9c51ec385 Rename text_area to textarea
Follow-up to [#52432][]
Related to [#52430][]

Helpers like `text_area_tag` construct [textarea][] elements. This
commit renames all view helper and form builder methods to replace
occurrences of `text_area` with `textarea`.

In the same style, this commit also renames the `rich_text`-prefixed
helpers to utilize a `textarea` suffix instead of the existing
`text_area` suffix.

To preserve backwards compatibility, this commit defines aliases for the
existing `text_area` format.

[#52432]: https://github.com/rails/rails/pull/52432
[#52430]: https://github.com/rails/rails/issues/52430
[textarea]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
2024-07-31 18:53:02 +02:00
David Heinemeier Hansson f973075aa4
Drop default permissions policy initializer (#52341)
It is too rarely used to warrant such a prominent placement in the
default structure.
2024-07-16 14:41:16 +02:00
Rafael Mendonça França d6316963ef
Merge pull request #52093 from p8/actiontext/fix-remote-image-preview
Only sanitize `content` attribute when present in attachments
2024-06-12 14:21:38 -04:00
Rafael Mendonça França 860f23c0b7
Merge pull request #52108 from fresh-eggs/7-2-stable
[`7-2-stable` Backport] Fix action-text-attachment HTML escaping regression test
2024-06-12 18:20:48 +00:00
Petrik 52c21f9066 Only sanitize `content` attribute when present in attachments
When the `content` attribute is set for Action Text attachments, Trix
shows this content.

1ac6d40d36 introduced sanitizing the
`content` attribute of ActionText::Attachable::ContentAttachment.
However, it would also set the `content` attribute when it isn't
present. Instead of showing the image preview, Trix would use the
empty `content` attribute resulting in missing previews for images.
2024-06-12 13:21:55 +02:00
Zack Deveau e215bf3360
Sanitize ActionText HTML ContentAttachment in Trix edit view
[CVE-2024-32464]
Instances of ActionText::Attachable::ContentAttachment included
within a rich_text_area tag could potentially contain unsanitized
HTML. This could lead to a potential cross site scripting issue
within the Trix editor.

This change enforces existing sanitization routines on
ActionText::Attachable::ContentAttachment attachments.
2024-06-04 10:08:12 -07:00
Rafael Mendonça França aa84eeb6f8
Depend on activestorage 8.0.0-alpha
We need to match the same behavior as the one that we are developing.
2024-05-31 23:04:54 +00:00
Rafael Mendonça França c6a980a551
Revert "Match actiontest sprockets files with the latest changes in Rails 7.2"
This reverts commit 025a83e58b.
2024-05-31 22:11:33 +00:00
Rafael Mendonça França 025a83e58b
Match actiontest sprockets files with the latest changes in Rails 7.2 2024-05-31 18:55:56 +00:00
Rafael Mendonça França 7ee34d9efb
Enable Rails minitest plugin in our rake tasks 2024-05-23 16:16:37 +00:00
Rafael Mendonça França 161d98dec2
Merge branch 'rm-trix' 2024-05-16 19:26:43 +00:00
Rafael Mendonça França f3f2773c52
Upgrade Trix to 2.1.1 to fix [CVE-2024-34341][1]
[1]: https://github.com/basecamp/trix/security/advisories/GHSA-qjqp-xr96-cj99
2024-05-16 19:25:47 +00:00
Rafael Mendonça França bf59d363fb
Clean CHANGELOG for 8.0 2024-05-13 16:55:52 +00:00
Rafael Mendonça França 37fd0e7fe4
Development of Rails 8.0 starts now
🎉
2024-05-13 16:45:20 +00:00
Rafael Mendonça França 113ca9e3d4
Merge pull request #51285 from tsvallender/ensure_image_processing_installed_trix
Ensure image_processing is installed with Trix
2024-05-02 18:06:07 -03:00
fatkodima 702638291c
Fix tests without assertions in the framework 2024-04-30 23:29:30 +00:00
Trevor Vallender 259b08b088 Ensure image_processing is installed with Trix
Currently if the Gemfile does not contain a commented out line for
image_processing, or the line uses single, not double quotes,
image_processing will not be installed and Trix will not be able to
correctly handle image attachments.

This ensures image_processing _is_ installed in those circumstances.
2024-03-08 12:46:36 +00:00
Rafael Mendonça França ce636e9f9f
Action Text documentation in now in Markdown 2024-01-25 20:47:14 +00:00
Petrik de Heus 3c3df4cea3
Merge pull request #50762 from p8/actiontext/document-associations-and-scopes
Document some ActionText methods [ci-skip]
2024-01-25 20:57:58 +01:00
Hartley McGuire 1ecac5b8d3
./tools/rdoc-to-md --only=actiontext -a 2024-01-24 19:08:44 -05:00
Petrik 8565f45100 Use relative includes of README's in documentation [ci-skip]
The Rails documentation uses the `:include:` directive to inline the
README of the framework into the main documentation page. As the
README's aren't in the root directory from where SDoc is run we need to
add the framework path to the include:

    # :include: activesupport/README.md

This results in a warning when installing the gems as generating the rdoc for the gem is run from the gem/framework root:

    Couldn't find file to include 'activesupport/README.rdoc' from lib/active_support.rb

The `:include:` RDoc directive supports includes relative to the current
file as well:

    # :include: ../README.md

This makes sure it works for the Rails API docs and the separate gems.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2024-01-18 10:39:15 +01:00
Petrik 3b49e47ce8 Use `includes` instead of `eager_load` for `with_all_rich_text`
`eager_load` performs a single query using a `LEFT OUTER JOIN` to load
the associations. Loading the associations in a join can result in many
rows that contain redundant data and it performs poorly at scale.

With `includes` a separate query is performed for each association,
unless a join is required by conditions.

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-01-16 22:06:19 +01:00
Petrik 35ecdefc14 Document some ActionText methods [ci-skip] 2024-01-15 22:21:53 +01:00
Hans Schnedlitz 482330d156
Do not generate pidfile in production environments (#50644)
* Remove pidfile in production

* Update changelog

* Update activestorage/test/dummy/config/puma.rb

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>

* Update template and other dummy files

---------

Co-authored-by: Rafael Mendonça França <rafael@franca.dev>
2024-01-08 14:47:25 -05:00
Jonathan Hefner 3bbf21c343 Use verb form of "fallback"
"Fallback" is a noun, whereas "fall back" is a verb.
2024-01-07 17:27:23 -06:00
Zacharias Knudsen c67e9dfe19
Ensure installed migrations comply with `rubocop-rails-omakase`
Adds space inside array literal brackets in ActiveStorage/ActionText migrations.

The new `rubocop-rails-omakase` enables `Layout/SpaceInsideArrayLiteralBrackets`,
which failed on the migrations created when installing ActiveStorage and ActionText.
2024-01-04 08:53:23 +01:00
Rafael Mendonça França 9d18dc8505
Remove all code to work with Ruby < 3.1 2024-01-03 19:02:31 +00:00
Rafael Mendonça França 664eb0dfc4
Merge pull request #50473 from seanpdoyle/action-text-content-pattern-matching
Delegate `ActionText::Content#deconstruct` to Nokogiri
2024-01-03 12:31:22 -05:00
Jean Boussier 6ba2fdb2fe Bump the required Ruby version to 3.1.0
Until now, Rails only droped compatibility with older
rubies on new majors, but I propose to change this policy
because it causes us to either keep compatibility with long
EOLed rubies or to bump the Rails major more often, and to
drop multiple Ruby versions at once when we bump the major.

In my opinion it's a bad alignments of incentives. And we'd
be much better to just drop support in new minors whenever they
go EOL (so 3 years).

Also Ruby being an upstream dependency, it's not even
a semver violation AFAICT.

Since Rails 7.2 isn't planned before a few months, we
can already drop Ruby 3.0 as it will be EOL in March.
2023-12-31 08:54:03 +01:00
Sean Doyle 2e15010d56 Delegate `ActionText::Content#deconstruct` to Nokogiri
Since `ActionText::Content` wraps an `ActionText::Fragment`, and
`ActionText::Fragment` wraps a `Nokogiri::XML::DocumentFragment`, then
`ActionText::Content` should be able to rely on the newer Ruby pattern
matching introduced by [nokogiri@1.16.0][] (mainly the
[DocumentFragment#deconstruct][] method):

```ruby
content = ActionText::Content.new <<~HTML
  <h1>Hello, world</h1>

  <div>The body</div>
HTML

content => [h1, div]

assert_pattern { h1 => { content: "Hello, world" } }
assert_pattern { div => { content: "The body" } }
```

The implementation change relies on delegating from `Content` to
`Fragment`, and from `Fragment` to `DocumentFragment#elements` (to
deliberately exclude text nodes).

[nokogiri@1.16.0]: https://nokogiri.org/CHANGELOG.html?h=pattern
[DocumentFragment#deconstruct]: https://nokogiri.org/rdoc/Nokogiri/XML/DocumentFragment.html?h=deconstruct#method-i-deconstruct
2023-12-28 09:19:18 -05:00
zzak 16ff9afb2e
Merge pull request #50275 from seanpdoyle/polymorphic-rename
Provide guidance for renaming classes in polymorphic associations [ci skip]
2023-12-25 08:01:15 +09:00
fatkodima f48bbff32c Expose `assert_queries_match` and `assert_no_queries_match` assertions 2023-12-21 01:30:16 +02:00
Jean Boussier 3881518c47
Merge pull request #50281 from p8/activerecord/assert-queries
Expose `assert_queries` and `assert_no_queries` assertions
2023-12-12 00:29:45 +01:00
Petrik 8392c54e73 Expose `assert_queries` and `assert_no_queries` assertions
To assert the expected number of queries are made, Rails internally uses
`assert_queries` and `assert_no_queries`. These assertions can be
useful in applications as well.

By extracting these assertions to a module, the assertions can be
included where required.
These assertions are added to `ActiveSupport::TestCase` when
ActiveRecord is defined.

ActiveStorage, ActionView and ActionText are using this module now as
well, instead of duplicating the implementation.
The internal ActiveRecord::TestCase, used for testing ActiveRecord,
implements these assertions as well. However, these are slighlty more
advanced/complex and use the SQLCounter class. To keep things simple,
for now this implementation isn't used.
2023-12-11 12:31:16 +01:00
Chedli Bourguiba c3b821e6d8 Take AR affixes into account for Action Text database models 2023-12-09 11:05:52 +01:00
Sean Doyle 0d8b3f09af Provide guidance for renaming classes in polymorphic associations [ci skip]
Add guidance to the Association Basics and `.belongs_to` method
documentation to encourage the renaming of a model's Ruby class to
coincide with updates to the existing data in the database.

Since Action Text and Active Storage rely on polymorphic associations,
add similar warnings to their guides.

Co-authored-by: Petrik de Heus <petrik@deheus.net>
Co-authored-by: Stephen Hanson <s.hanson5@gmail.com>
Co-authored-by: zzak <zzakscott@gmail.com>
2023-12-08 09:19:21 -05:00
Sean Doyle 16c28d0a09 Add test coverage for `rich_text_area` helper
Follow-up to [#50252][]

Similar to the reliance on a `FormBuilder` in the helper methods
documentation examples, the template test coverage for `#rich_text_area`
relied on invocations through a `FormBuilder` instance.

This commit adds explicit coverage for calling the `#rich_text_area`
helper method directly with both an `object_name` and `method_name`
positional arguments.

[#50252]: https://github.com/rails/rails/pull/50252
2023-12-03 14:53:44 -05:00
Sean Doyle 638c9d5722 Action Text `rich_text_area` code samples [ci skip]
The API documentation for the `rich_text_area` Action View helper
demonstrates how to invoke the helper through a `FormBuilder` instance,
instead of through the `ActionView::Base` instance.

This commit removes the `form.` prefix, and includes examples of calling
the method with an `object_name` positional argument.
2023-12-03 11:40:55 -05:00
Max Notarangelo 185c19c5ae fix typo in production initializer generator
And put "info" in quotes.
2023-11-16 15:00:07 -08:00
Matias Grunberg 2dbcb3df33 fix using actiontext.js in sprocket
actiontext.js is compiled as ESM bundle instead of UMD bundle.
This leads to issues when trying to use ActionText with sprockets because the ESM bundle declares variables like they are scoped to the file but sprockets will see them as scoped globally.
This is a problem, in particular, if you want to mix actiontext with
turbo-rails.

The problem got introduced in https://github.com/rails/rails/pull/46447.
I traced valid compilation back to
https://github.com/rails/rails/pull/42895.

This commit mimic changes made in
https://github.com/rails/rails/pull/42895 to ActiveStorage:
   Retains app/assets/javascripts/actiontext.js as a UMD package for backwards compatibility with
   bundling in the asset pipeline, but also adds app/assets/javascripts/actiontext.esm.js for use
   with ESM via importmap in the browser.
2023-11-07 00:36:53 -03:00
Jonathan Hefner 4dcd6ba8d3 Update .gitattributes for generated JavaScript [ci-skip]
This adds `linguist-generated` and `linguist-vendored` attributes where
appropriate to suppress the files in diffs and exclude the files from
the project's language stats on GitHub.

See https://github.com/github/linguist for more information.
2023-11-05 15:48:08 -06:00
Jonathan Hefner a93771cb0d Add JavascriptPackageTest for Action Text
This mirrors the existing `JavascriptPackageTest` tests for UJS, Action
Cable, and Active Storage.
2023-11-05 15:28:14 -06:00
Adrian Hirt f0a03bd899 Remove `config.public_file_server.enabled` from generators
Remove the option `config.public_file_server.enabled` from the generators for all environments, as the value is the same in all environments.

Co-authored-by: Jonathan Hefner <jonathan@hefner.pro>
2023-11-03 11:34:37 -05:00
Sean Doyle 591d88aef4 Document Action Text Sanitization
Add documentation for `ActionText::RichText#to_s` and
`ActionText::Content#to_s` that demonstrates Action Text's ability to
sanitize and scrub its content.

Co-authored-by: Mike Dalessio <mike.dalessio@gmail.com>
Co-authored-by: Petrik de Heus <petrik@deheus.net>
2023-10-30 17:49:13 -04:00
Jonathan Hefner dd428f1ef1 Present config.public_file_server.enabled as opt-out
Follow-up to #47137.

Since `config.public_file_server.enabled` is true by default, this
commit changes the `config/environments/production.rb` template to
present the setting as an opt-out.
2023-10-30 11:54:26 -05:00
Rafael Mendonça França 403447d061
Use version of importmap that support loading outside of an app
We are using it in a few scripts, and we were doing workarounds
to be able to use outside an Rails application.

Now the workaround is gone.
2023-10-27 20:23:42 +00:00
Rafael Mendonça França d0ed4c8ecc
Update actiontext JavaScript 2023-10-27 13:50:49 +00:00
Hartley McGuire c93a989635
Fix using trix in sprockets
When Trix was [updated][1] from 1.3.1 to 2.0.4, the ESM bundle of 2.0.4
was used instead of the UMD bundle (the vendored 1.3.1 file used the
UMD bundle). This leads to issues when trying to use Trix with sprockets
because the ESM bundle declares variables like they are scoped to the
file but sprockets will see them as scoped globally.

This commit fixes the issue by replacing the Trix ESM bundle with the
UMD bundle (and upgrades it from 2.0.4 to 2.0.7). Additionally, a Rake
task has been added similar to one previously [added][2] to the guides
for automatic vendoring using Importmap::Packager.

[1]: fab1b522cd
[2]: a42863f514
2023-10-25 00:25:35 -04:00
Nikita Vasilevsky 19f8ab2e7d
[Tests only] Enable `Minitest/AssertPredicate` rule 2023-10-13 19:26:47 +00:00
Hartley McGuire 2146aade71
Remove webpack as runtime dep of Action Text
This appears to have been erroneously [added][1] when the Trix
dependency was updated.

[1]: 48b8285f4d
2023-10-05 07:50:57 -04:00