Commit Graph

10043 Commits

Author SHA1 Message Date
evazion
5962152ee3 wiki pages, artists: fix normalization of other names.
Fix wiki pages and artists to normalize other names more consistently
and correctly.

For wiki pages, we strip leading / trailing / repeated underscores to
fix user typos, and we normalize to NFKC form to make search more consistent.

For artists, we allow leading / trailing / repeated underscores because
some artist names have these, and we normalize to NFC form because some
artists have weird names that would be lost by NFKC form. This does make
search less consistent.
2021-01-10 02:03:12 -06:00
evazion
e788d8d0b6 saved searches: fix normalization of labels.
Fix saved searches to remove additional invalid characters from labels:

* Remove repeated spaces or underscores.
* Remove leading and trailing spaces or underscores.
* Normalize Unicode characters to NFC form.

Also add a fix script to renormalize labels in old saved searches. A few
problems with existing searches:

* Some saved searches somehow had labels containing NULL elements.
* Some had leading or trailing underscores.
* Some had repeated underscores.
* Some had non-English characters in uppercase.
2021-01-10 02:03:12 -06:00
evazion
7fbac34962 wiki pages: fix normalization of wiki page title.
Fix the wiki page title "azur___lane" being normalized to "azur__lane"
instead of "azur_lane".
2021-01-10 02:03:12 -06:00
evazion
ff6e640fcb tests: add normalize_attribute helper method.
Add a custom Shoulda matcher for testing that a model correctly normalizes an attribute.

Usage:

    subject { build(:wiki_page) }
    should normalize_attribute(:title).from(" Azur  Lane ").to("azur_lane")
2021-01-10 02:03:12 -06:00
evazion
9759701071 search: add way to search array attributes by regex.
Add a `where_any_in_array_matches_regex` method and expose it to the API:

 * https://danbooru.donmai.us/artists?search[any_other_name_matches_regex]=^blah
 * https://danbooru.donmai.us/wiki_pages?search[any_other_name_matches_regex]=^blah
 * https://danbooru.donmai.us/saved_searches?search[any_label_matches_regex]=^blah

In SQL, this does `WHERE '^blah' ~<< ANY(other_names)`, where `~<<` is a
custom operator based on the `~` regex match operator, but with the
arguments reversed. This allows it to be used with the ANY(array) operator.

See also:

* https://stackoverflow.com/a/22101172
* https://www.postgresql.org/docs/current/sql-createfunction.html
* https://www.postgresql.org/docs/current/sql-createoperator.html
* https://www.postgresql.org/docs/current/functions-comparisons.html
2021-01-10 02:03:02 -06:00
evazion
65adcd09c2 users: track logins, signups, and other user events.
Add tracking of certain important user actions. These events include:

* Logins
* Logouts
* Failed login attempts
* Account creations
* Account deletions
* Password reset requests
* Password changes
* Email address changes

This is similar to the mod actions log, except for account activity
related to a single user.

The information tracked includes the user, the event type (login,
logout, etc), the timestamp, the user's IP address, IP geolocation
information, the user's browser user agent, and the user's session ID
from their session cookie. This information is visible to mods only.

This is done with three models. The UserEvent model tracks the event
type (login, logout, password change, etc) and the user. The UserEvent
is tied to a UserSession, which contains the user's IP address and
browser metadata. Finally, the IpGeolocation model contains the
geolocation information for IPs, including the city, country, ISP, and
whether the IP is a proxy.

This tracking will be used for a few purposes:

* Letting users view their account history, to detect things like logins
  from unrecognized IPs, failed logins attempts, password changes, etc.
* Rate limiting failed login attempts.
* Detecting sockpuppet accounts using their login history.
* Detecting unauthorized account sharing.
2021-01-08 22:34:37 -06:00
evazion
94e125709c users: add Restricted user level.
Add a Restricted user level. Restricted users are level 10, below
Members. New users start out as Restricted if they sign up from a proxy
or an IP recently used by another user.

Restricted users can't update or edit any public content on the site
until they verify their email address, at which point they're promoted
to Member. Restricted users are only allowed to do personal actions
like keep favorites, keep favgroups and saved searches, mark dmails as
read or deleted, or mark forum posts as read.

The restricted state already existed before, the only change here is
that now it's an actual user level instead of a hidden state. Before it
was based on two hidden flags on the user, the `requires_verification`
flag (set when a user signs up from a proxy, etc), and the `is_verified`
flag (set after the user verifies their email). Making it a user level
means that now the Restricted status will be shown publicly.

Introducing a new level below Member means that we have to change every
`is_member?` check to `!is_anonymous` for every place where we used
`is_member?` to check that the current user is logged in.
2021-01-07 17:10:29 -06:00
evazion
da3e8e4726 searchable: fix bug with searching multiple association attributes.
Fix a bug with searches like the following not working correctly:

* https://danbooru.donmai.us/comments.json?search[creator][level]=20&search[creator_id]=1234
* https://danbooru.donmai.us/comments.json?search[creator][level]=20&search[creator_name]=abcd
* https://danbooru.donmai.us/comments.json?search[post][rating]=s&search[post_tags_match]=touhou

It wasn't possible to search for both `creator` and `creator_id` at the
same time (or `post` and `post_tags_match`, etc). Only the `creator_id`
param would be recognized.

Also refactor some internals:

* `search_includes` was renamed to `search_associated_attribute`.
* `search_attribute` was split up into `search_basic_attribute` and
  `search_associated_attribute`.
2021-01-07 17:10:29 -06:00
evazion
e356fd0fd5 models: remove nonexistent associations.
Remove the WikiPageVersion#artist and Post#updater associations. Neither
of these existed and they caused problems with searching includable
associations in the API.
2021-01-07 17:10:29 -06:00
evazion
59d64a76f3 tests: fix debug_mode option.
Fix debug mode to only re-raise unexpected exceptions. Fixes debug mode
breaking controller tests that expected to throw exceptions.
2021-01-07 17:10:29 -06:00
evazion
b223a87868 aliases/implications: add back legacy reason field.
In Danbooru 1, aliases (and implications) had a `reason` field where
either the admin or the alias requester gave a reason for the alias.
This field was removed from the code and the database schema, but it
still existed in the production database. This adds the field back, so
that the dev schema is consistent with the production schema, and so
that legacy reasons can be viewed on site again.

* Add back legacy tag_aliases.reason and tag_implications.reason field.
* Make /tag_aliases and /tag_implications show legacy reasons.
* Add the reason field to the search form.
2021-01-06 16:05:56 -06:00
evazion
c5d109dd87 Merge pull request #4660 from BrokenEagle/multiple-excludes
Add Support For Multiple excludes
2021-01-06 14:48:33 -06:00
evazion
6f93b77fc0 Add "Ctrl+Enter to submit" hint beneath tag box (#4661) 2021-01-06 14:42:08 -06:00
BrokenEagle
db5f9ce243 Support multiple excludes for enum types
It's not possible to pass it off to search_numeric_attribute directly
since the column "category" does not match the prefix "category_id".
2021-01-06 20:21:56 +00:00
BrokenEagle
57de81686b Support using all numeric searches for includes 2021-01-06 20:21:56 +00:00
BrokenEagle
4a439d72d6 Support multiple exclusions
Since it does a not of numeric_attribute_matches which uses the
post query builder, it now also support reverse ranges and reverse
greater/less than.
2021-01-06 20:21:55 +00:00
evazion
65be2c99b0 Fix #4657: Hentai-Foundry: Document tree depth limit exceeded. 2021-01-06 03:05:36 -06:00
evazion
886e43ad11 Update ruby gems and yarn packages. 2021-01-05 00:05:49 -06:00
evazion
873d719481 tests: fix broken Newgrounds test.
Broken again by the source post being deleted.
2021-01-04 23:54:18 -06:00
evazion
62d183ddf4 Add fix script to regenerate old posts with transparent backgrounds.
Fixes #1862. Very old posts with transparent backgrounds used black
instead of white backgrounds in thumbnails. This was changed in #603
(see also #1239), but the thumbnails were never regenerated.
2021-01-04 21:43:27 -06:00
evazion
79ee6a515d post regenerations: refresh Cloudflare when post is regenerated.
Purge cached thumbnails from Cloudflare when a post is regenerated.

This is necessary because regenerating a post may change the thumbnail,
and if we don't purge the cache from Cloudflare then users will still
see the old thumbnail.

We have do this before updating IQDB because if we don't, IQDB will see
the old cached thumbnail and index the wrong image. This may be racy
because the thumbnail might not be completely purged from Cloudflare
before it's downloaded by IQDB.
2021-01-04 21:43:27 -06:00
evazion
b6f9c9a866 post regenerations: regenerate posts asynchronously.
Regenerate posts asynchronously using a delayed job.

Regenerating a post can be slow because it involves downloading the
original file, regenerating the thumbnails, and redistributing the new
thumbnails back to the image servers. It's better to run this in the
background, especially if a user is trying to regenerate posts in bulk.

The downside is there's no notification to the user when the regeneration
is complete. You have to check the modactions log to see when it's finished.
2021-01-04 21:43:27 -06:00
evazion
df44937c57 post regenerations: replace PostRegeneration model with mod actions.
* Remove the PostRegeneration model. Instead just use a mod action
  to log when a post is regenerated.

* Change it so that IQDB is also updated when the image samples are
  regenerated. This is necessary because when the images samples are
  regenerated, the thumbnail may change, which means IQDB needs to be
  updated too. This can happen when regenerating old images with
  transparent backgrounds where the transparency was flattened to black
  instead of white in the thumbnail.

* Only display one "Regenerate image" option in the post sidebar, to
  regenerate both the images and IQDB. Regenerating IQDB only can be
  done through the API. Having two options in the sidebar is too much
  clutter, and it's too confusing for Mods who don't know the difference
  between an IQDB-only regeneration and a full image regeneration.

* Add a confirm prompt to the "Regenerate image" link.
2021-01-04 21:35:43 -06:00
evazion
913ce88024 tests: factor out upload helper methods. 2021-01-04 20:15:37 -06:00
BrokenEagle
16d6f3bbd5 Add post regenerations 2021-01-04 18:35:50 -06:00
evazion
e6f2bf1c89 autocomplete: tweak css. 2021-01-04 04:13:36 -06:00
evazion
1909d6e062 Merge pull request #4636 from nonamethanks/fix_replacements
Uploads preprocessing: get rid of same-source existence check
2021-01-04 01:38:03 -06:00
evazion
3542c401d4 Merge pull request #4654 from nonamethanks/fix_gelbooru_normalization
Fix gelbooru source normalization
2021-01-04 01:31:17 -06:00
evazion
984d9e9886 Merge pull request #4634 from nonamethanks/minor_fix
Post replacements: fix replacement message
2021-01-04 01:30:54 -06:00
evazion
50e799e959 Merge branch 'master' into minor_fix 2021-01-04 01:30:28 -06:00
evazion
d24275c51c Merge pull request #4622 from BrokenEagle/add-childlike-font
Add childlike font
2021-01-04 01:29:25 -06:00
evazion
48018aec14 Merge pull request #4637 from Vladimir-A/patch-1
Update: INSTALL.debian
2021-01-04 01:27:11 -06:00
evazion
5612413546 Merge pull request #4641 from nonamethanks/weibo_previews
Weibo: use proxy for upload previews
2021-01-04 01:20:50 -06:00
evazion
ed7e7b1d30 Merge pull request #4639 from nonamethanks/fix_pixiv_en_links
Update artist finder blacklist
2021-01-04 01:15:15 -06:00
evazion
9008e836e4 BURs: raise limit on Builder artist tag moves from 100 to 200 posts. 2021-01-04 01:10:26 -06:00
evazion
257fa3d9c1 Fix #4645: Builders can alias empty non-artist tags 2021-01-04 01:02:39 -06:00
evazion
69cfa1696a html: disable browser spellcheck on all non-DText inputs.
Disable the browser's native spellchecking ability on all form inputs,
except for DText inputs. We do this by setting `spellcheck="false"` on
the <body> tag, and `spellcheck="true"` on DText <input> tags.

This fixes browsers displaying a red wavy underline beneath tags in the
tag search box, among other places. We disable spellchecking globally
because most form inputs, except for DText inputs, aren't meant for
natural English language.
2021-01-04 00:25:54 -06:00
evazion
6793aedf81 Fix #4650: Differentiate between aliases and corrections in autocomplete.
Display a red wavy underline beneath misspelled tags in autocomplete.

We use an inline image for the underline instead of the native
`text-decoration: red wavy underline` property because the native
underline is too big and ugly, and we have no way to adjust it. Making a
nice-looking wavy underline in CSS is surprisingly difficult. This
turned out to be the cleanest way.
2021-01-04 00:25:47 -06:00
evazion
dd430b3065 Update ruby gems and yarn packages. 2021-01-03 20:56:44 -06:00
evazion
de16d31135 favorites: remove is_favorited attribute from post API.
* Remove the data-is-favorited attribute from post thumbnails.
* Remove the is_favorited attribute from the /posts.json API.
* Remove the fav_string attribute from the /posts.json API (only visible
  to moderators).
* Change `Post#favorited_by?` to not use the fav_string.

Further addresses #4652 by eliminating the last places where fav_string
was used.
2021-01-03 19:58:43 -06:00
evazion
98ee6c31c1 favorites: refactor fav:/ordfav: searches to not use fav_string.
Refactor fav:<name> and ordfav:<name> searches to use the favorites
table instead of the posts.fav_string.

This may be slower for fav:<name> searches. The fav_string effectively
treats favorites like secret tags on the post, so fav:<name> searches
were effectively the same as tag searches. Now they do a subquery on the
favorites table, which may not perform as well for things like multiple
fav:<name> metatags or negated fav:<name> metatags.

For ordfav:<name> searches, this may be faster. ordfav: searches had a
tag match clause (`tag_index @@ 'fav:123'`) in addition to a join on the
favs table. This was redundant, and in some cases it inhibited the query
planner from choosing a more optimal plan.

Partially addresses #4652 by eliminating another place where we depended
on the fav_string.
2021-01-03 19:18:31 -06:00
evazion
11a8c2877b favorites: refactor favlist order on post page.
On the posts show page, in the favorites list, show favorites according
to the order they were added to the favorites table, rather than the
order they were added to the posts's fav_string.

On most posts these should be the same, but on old posts they may be
slightly different. The IDs of the first few hundred thousand favorites
don't appear to be in chronological order. Probably the original
favorite IDs were lost and recreated by a database move at some point in
Danbooru's history. The fav_string is also inconsistent with the
favorites table in some places (one contains favorites that aren't
contained by the other), which also throws off the order.

Partially addresses #4562 by eliminating one place where we depended on
the fav_string.
2021-01-03 19:15:17 -06:00
nonamethanks
b3f92dd2c7 Fix gelbooru source normalization 2021-01-03 20:12:40 +01:00
evazion
dbe2eeb00d emails: remove "Valid?" search option.
No longer necessary after running previous commit because all invalid
email addresses have been purged.
2021-01-02 04:09:43 -06:00
evazion
1aabc0aae0 emails: fix invalid email address deletion script.
Fix script to delete all invalid email addresses. In production there
were ~4000 users with invalid email addresses because we used to not do
any validation of emails during signup.
2021-01-02 04:09:43 -06:00
evazion
014199ec2b user upgrades: handle the refunded status on show page. 2021-01-02 04:09:43 -06:00
evazion
48676789f0 robots.txt: fix hardcoded paths. 2021-01-02 04:09:43 -06:00
evazion
36f95891bd search: let wildcard searches match up to 100 tags.
Let searching for things like *_legwear match up to 100 tags. Previously
the limit was 25.
2021-01-02 04:09:43 -06:00
evazion
890c793d9b Fix #4644: Give unlimited searches for builders
Give Builders unlimited searches, favgroups, and saved searches.
2021-01-02 04:09:41 -06:00
evazion
0b2f9fafa8 users: refactor limit methods.
* Refactor various user limit methods to class methods from instance
  methods so they can be used outside the context of a single user.

* Remove the Danbooru.config.base_tag_query_limit option.
2021-01-01 19:24:37 -06:00