Commit Graph

150 Commits

Author SHA1 Message Date
evazion
4439293bf1 newrelic: fix newrelic starting without license key.
Fix an issue where the New Relic agent always started in the production
environment, even when a license key wasn't configured.

Also make the New Relic agent log to stdout instead of log/newrelic_agent.log.
2021-05-24 21:58:01 -05:00
evazion
a062c040cb saved searches: fail gracefully when Redis is disabled.
Just make saved searches return nothing when Redis is disabled.
2021-03-30 05:35:42 -05:00
evazion
803efe8501 Don't use secure cookes on non-HTTPS deployments.
Fixes not being able to login or signup when running in production mode
on a non-HTTPS site.
2021-03-30 03:58:34 -05:00
evazion
12436c4aa9 Fix IpAddressType autoload warning.
Fix Rails complaining about IpAddressType not being reloaded by hot
reloading:

    DEPRECATION WARNING: Initialization autoloaded the constant IpAddressType.

    Being able to do this is deprecated. Autoloading during initialization is going
    to be an error condition in future versions of Rails.

    Reloading does not reboot the application, and therefore code executed during
    initialization does not run again. So, if you reload IpAddressType, for example,
    the expected changes won't be reflected in that stale Class object.

    This autoloaded constant has been unloaded.

    In order to autoload safely at boot time, please wrap your code in a reloader
    callback this way:

        Rails.application.reloader.to_prepare do
        # Autoload classes and modules needed at boot time here.
        end

    That block runs when the application boots, and every time there is a reload.
    For historical reasons, it may run twice, so it has to be idempotent.

    Check the "Autoloading and Reloading Constants" guide to learn more about how
    Rails autoloads and reloads.
2021-03-29 03:01:02 -05:00
evazion
b79bd8407f Remove FalseClass#to_i core extension.
Remove a monkey patch that added a `to_i` method to `FalseClass` so that
`false.to_i` returned 0. This is legacy code that shouldn't still be in
use anywhere. It doesn't really work anyway, because `true.to_i` isn't
defined.
2021-03-11 17:34:05 -06:00
evazion
35a0c6b11f Fix #4736: Display network prefix length (if present) in API key IP whitelist. 2021-03-01 02:38:18 -06:00
evazion
cde76e66f6 forms: fix form validation error messages.
* Fix it so that all edit forms show an error banner if the form
  has validation errors. Previously forms had to manually call
  `error_messages_for`, which not all forms did.

* Fix it so that the full validation error message is shown next to each
  input attribute that had errors. Also update the styling of these
  error messages to look better.
2021-02-22 02:38:26 -06:00
evazion
d18dc573fb artists: fix misnormalization of emoji in other names.
Fix `normalize_whitespace` to not strip zero-width joiner characters
(U+200D). These characters are used in emoji and stripping them breaks
some artist other names that use emoji.
2021-01-10 02:46:20 -06:00
evazion
7762489d7d user upgrades: upgrade to new Stripe checkout system.
This upgrades from the legacy version of Stripe's checkout system to the
new version:

> The legacy version of Checkout presented customers with a modal dialog
> that collected card information, and returned a token or a source to
> your website. In contrast, the new version of Checkout is a smart
> payment page hosted by Stripe that creates payments or subscriptions. It
> supports Apple Pay, Dynamic 3D Secure, and many other features.

Basic overview of the new system:

* We send the user to a checkout page on Stripe.
* Stripe collects payment and sends us a webhook notification when the
  order is complete.
* We receive the webhook notification and upgrade the user.

Docs:

* https://stripe.com/docs/payments/checkout
* https://stripe.com/docs/payments/checkout/migration#client-products
* https://stripe.com/docs/payments/handling-payment-events
* https://stripe.com/docs/payments/checkout/fulfill-orders
2020-12-24 19:58:29 -06:00
evazion
f3880569e1 rails: update settings to 6.1 defaults.
Most of the new settings aren't relevant to us. We do have to fix some
tests to work around a Rails bug. `assert_enqueued_email_with` uses the
wrong queue, so we have to specify it explicitly. This is fixed in Rails
HEAD but not yet released.
2020-12-21 22:42:50 -06:00
evazion
906430b983 config: add option for customizing session cookie name.
Fixes getting logged out when you visited Testbooru because of
Testbooru's session cookies clobbering Danbooru's session cookies.
2020-12-21 22:42:50 -06:00
evazion
efb836ac02 wikis: normalize Unicode characters in wiki bodies.
* Introduce an abstraction for normalizing attributes. Very loosely
  modeled after https://github.com/fnando/normalize_attributes.
* Normalize wiki bodies to Unicode NFC form.
* Normalize Unicode space characters in wiki bodies (strip zero width
  spaces, normalize line endings to CRLF, normalize Unicode spaces to
  ASCII spaces).
* Trim spaces from the start and end of wiki page bodies. This may cause
  wiki page diffs to show spaces being removed even when the user didn't
  explicitly remove the spaces themselves.
2020-12-21 20:47:50 -06:00
evazion
6849a3d68b Update app files to Rails 6.1 defaults. 2020-12-19 00:26:27 -06:00
evazion
2c1da660fd tags: allow tag abbreviations in searches and during tagging.
Expand the tag abbreviation system introduced in b0be8ae45 so that it
works in searches and when tagging posts, not just in autocomplete.

For example, you can tag a post with /evth and it will add the tag
eyebrows_visible_through_hair. You can search for /evth and it will
search for the tag eyebrows_visible_through_hair.

Some more examples:

* /ops is short for one-piece_swimsuit
* /hooe is short for hair_over_one_eye
* /saol is short for standing_on_one_leg
* /tlozbotw is short for the_legend_of_zelda:_breath_of_the_wild

If two tags have the same abbreviation, then the larger tag takes
precedence. For example, /be is short for blue_eyes, not brown_eyes,
because blue_eyes is the bigger tag.

If there is an existing shortcut alias that conflicts with the
abbreviation, then the alias take precedence. For example, /sh is short
for suzumiya_haruhi, not short_hair, because there's an old alias for
/sh -> suzumiya_haruhi.
2020-12-17 23:57:13 -06:00
evazion
3a3d456bd2 html: standardize font sizes and heading tags.
Standardize font sizes and heading tags (<h1>-<h6>) to be more
consistent across the site.

Changes:

* Introduce font size CSS variables and start replacing hardcoded font
  sizes with standard sizes.
* Change header tags to use only one <h1> per page. One <h1> per page is
  recommended for SEO purposes. Usually this is for the page title, like
  in forum threads or wiki pages.
* Standardize on <h2> for section headers in sidebars and <h3> for
  smaller subsection headers. Don't use <h4>-<h6>.
* In DText, make h1-h4 headers all the same size. Standard wiki style is
  to ignore h1-h3 and start at h4.
* In DText, make h4-h6 the same size as the h1-h3 tags outside of DText.
* In the tag list, change the <h1> and <h2> tag category headers to <h3>.
* Make usernames in comments and forum posts smaller. Also change the
  <h4> tag for the commenter name to <div class="author-name">.
* Make the tag list, paginator, and nav menu smaller on mobile.
* Change h1#app-name-header to a#app-name-header.
2020-07-23 17:34:17 -05:00
evazion
42f0112c38 seo: increase sitemap coverage.
Rework sitemaps to provide more coverage of the site. We want every
important page on the site - including every post, tag, and wiki page -
to be indexed by Google. We do this by generating sitemaps and sitemap
indexes that contain links to every important page on the site.
2020-07-10 00:18:30 -05:00
evazion
048bc7faf5 Revert "simple form: enable HTML5 maxlength validations."
This incorrectly added maxlength=4 to parent id fields.

This reverts commit 5e23861bea.
2020-06-30 13:03:51 -05:00
evazion
804a2ef9a5 Fix #4535: Comment edit forms contain duplicate IDs.
Prefix comment form IDs with `post_<id>_comment_<id>` to ensure
uniqueness.
2020-06-26 14:57:19 -05:00
evazion
5e23861bea simple form: enable HTML5 maxlength validations.
Makes it so that models that have maximum length validations will add
maxlength attributes to form fields. This includes flag reasons, appeal
reasons, and forum topic titles.

Partially fixes #4519 (Add "n/m characters remaining" character counter to the appeal reason).

https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/maxlength
2020-06-25 16:28:18 -05:00
evazion
883856d4af simple form: refactor DText form fields to use SimpleForm.
* Refactors DText form fields to use a custom SimpleForm input instead
  of manually generated html. This fixes it so that DText fields use the
  same markup as normal SimpleForm fields, which lets us apply browser
  maxlength validations to DText input fields.

* Fixes autocomplete for @-mentions only working in comments and forum posts.
  Now @-mention autocomplete works in all DText fields, including dmails.
  Known bug: it applies in artist commentary fields when it shouldn't.
2020-06-25 16:28:09 -05:00
evazion
fccdcbe7cc simple form: regenerate config with new defaults.
Regenerated with `bin/rails generate simple_form:install`.
2020-06-25 16:28:09 -05:00
evazion
a4efeb2260 gems: drop Mechanize, HTTParty, and Sinatra gems. 2020-06-21 15:13:42 -05:00
evazion
a181e6d0db Fix #1898: Include alias predicates in non-empty Tags search.
Make searches on the /tags index includes aliases too. Show matching
aliases like this:

   Name: gray*

   ? 75098 grey_hair <- gray_hair
   ? 35345 grey_eyes <- gray_eyes
2020-02-23 00:29:17 -06:00
evazion
d00308c43d Delegate HSTS to nginx.
Remove the ssl_options config option. Let nginx handle HSTS and
http->https redirects instead. At the rails level, all we need to do is
set the secure cookie flag when https is enabled (which we assume it's
enabled in production).
2020-01-07 11:49:46 -06:00
evazion
432b3e19a9 config: don't use redis when not redis_url not configured. 2019-12-23 15:09:34 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
ddb0e4d3ce config: refactor secret_key_base initialization. 2019-12-13 04:21:04 -06:00
evazion
6382aec85e config: update to Rails 6.0 defaults. 2019-12-13 04:21:04 -06:00
evazion
fc5bce5595 redis: bump timeout settings. 2019-12-13 03:13:17 -06:00
evazion
ea15b525f8 config: clean up filter_parameters initializer. 2019-12-13 03:05:46 -06:00
evazion
a4e587aa6a config: refactor email settings.
* Add `Danbooru.config.mail_delivery_method` option.
* Remove `Danbooru.config.aws_ses_enabled?` option.
* Replace `Danbooru.config.aws_ses_options` with `Danbooru.config.mail_settings`.
2019-12-13 03:00:12 -06:00
evazion
3e37869768 rails: disable asset pipeline.
Disable the assets pipeline (Sprockets). Sprockets errors out now after
upgrading to Sprockets 4 because of missing config files. We don't use
it any more after switching to Webpack, so we can disable it entirely.

Also disable a few more Rails features that we don't use (ActiveStorage,
ActionCable, ActionMailbox, ActionText).
2019-10-14 13:50:31 -05:00
evazion
93dd952949 pagination: refactor to avoid counting pages in API.
Previously the page-based (numbered) paginator would always count the
total_pages, even in API calls when it wasn't needed. This could be very
slow in some cases. Refactor so that total_pages isn't calculated unless
it's called.

While we're at it, refactor to condense all the sequential vs. numbered
pagination logic into one module. This incidentally fixes a couple more
bugs:

* "page=b0" returned all pages rather than nothing.
* Bad parameters like "page=blaha123" and "page=a123blah" were accepted.
2019-10-07 22:01:37 -05:00
evazion
efca48ee96 Set SameSite=Lax on session cookies.
https://web.dev/samesite-cookies-explained
2019-09-09 11:51:01 -05:00
evazion
312606bf98 Fix #4137: Share cookies across subdomains 2019-09-09 11:51:01 -05:00
evazion
d0f060d8eb api: refactor api attribute declarations.
Replace the `method_attributes` and `hidden_attributes` methods with
`api_attributes`. `api_attributes` can be used as a class macro:

    # include only the given attributes.
    api_attributes :id, :created_at, :creator_name, ...

    # include all default attributes plus the `creator_name` method.
    api_attributes including: [:creator_name]

or as an instance method:

    def api_attributes
       [:id, :created_at, :creator_name, ...]
    end

By default, all attributes are included except for IP addresses and
tsvector columns.
2019-09-08 23:28:02 -05:00
evazion
1bb1b147ea Fix autoloading deprecation warning in delayed job initializer.
DEPRECATION WARNING: Initialization autoloaded the constants
    Danbooru::Paginator and Danbooru::Paginator::ActiveRecordExtension.

    Being able to do this is deprecated. Autoloading during
    initialization is going to be an error condition in future versions
    of Rails.

    Reloading does not reboot the application, and therefore code
    executed during initialization does not run again. So, if you reload
    Danbooru::Paginator, for example, the expected changes won't be
    reflected in that stale Module object.

    `config.autoloader` is set to `classic`. These autoloaded constants
    would have been unloaded if `config.autoloader` had been set to
    `:zeitwerk`.

    Please, check the "Autoloading and Reloading Constants" guide for
    solutions.
2019-09-01 13:10:37 -05:00
evazion
0cf9f845d0 newrelic: fix tracking of api auth failure errors.
Fixes user params not being recorded on SessionLoader::AuthenticationFailed errors.
2019-08-27 21:19:56 -05:00
evazion
2c3ecf7ea4 Kill utf8=✓ param. 2019-08-27 18:13:30 -05:00
evazion
3f86a60457 Upgrade to Rails 6.0.0. 2019-08-27 18:13:30 -05:00
evazion
dfe2b831a3 cache: replace memcache with redis.
Drop memcache. Use redis for all caching instead.
2019-08-22 23:15:34 -05:00
evazion
2e407fa476 rails: update defaults from 5.1 to 5.2.
protect_from_forgery removed from because it's now on by default.

ref: https://edgeguides.rubyonrails.org/configuring.html
2019-08-22 22:09:05 -05:00
evazion
f268293105 delayed jobs: log to stdout.
Log to stdout because we now run workers under systemd and we want
errors to go to the journal, not to log/production.log.
2019-08-12 13:38:45 -05:00
evazion
ef68d42dbe Drop unused query tracer code + term-ansicolor gem. 2019-08-07 22:11:07 -05:00
evazion
b9bb5467b8 Fix #4117: Use memcache for fragment caching. 2019-08-04 21:10:57 -05:00
Albert Yi
fdd7582fb0 add support for upload preprocessing 2018-06-14 17:52:41 -07:00
Albert Yi
d047d04de6 switch from secret_token to secret_key_base 2018-05-15 15:34:53 -07:00
Albert Yi
72f319ccf3 rename lambda references to use shorthand syntax 2018-05-10 11:18:02 -07:00
Albert Yi
3c894eaf86 increase timeout for pixiv api connections 2018-05-10 09:49:46 -07:00
Albert Yi
c658e7d22a add comments for mechanize patch 2018-05-09 16:51:12 -07:00