Commit Graph

9889 Commits

Author SHA1 Message Date
evazion
c82e05d828 users: add stricter checks for user promotions.
New rules for user promotions:

* Moderators can no longer promote other users to moderator level. Only
  Admins can promote users to Mod level. Mods can only promote up to Builder level.
* Admins can no longer promote other users to Admin level. Only Owners
  can promote users to Admin. Admins can only promote up to Mod level.
* Admins can no longer demote themselves or other admins.

These rules are being changed to account for the new Owner user level.

Also change it so that when a user upgrades their account, the promotion
is done by DanbooruBot. This means that the inviter and the mod action
will show DanbooruBot as the promoter instead of the user themselves.
2020-12-13 21:21:08 -06:00
evazion
b3ad13e6e3 users: add new owner level.
Add a new Owner user level for the site owner. Highly sensitive
operations like manually changing the passwords of other users will be
restricted to the site owner.
2020-12-13 21:18:24 -06:00
evazion
35134abe8f post query builder: fix incompatibilities with Rails 6.1.
* Rename the `#negate` and `#and` methods that we monkey patch into
  ActiveRecord::Relation. These methods are now defined in Rails 6.1, but
  they shadow our methods and have slightly different behavior.
* Fix a call to `invert`. It no longer accepts an argument.
2020-12-13 04:10:48 -06:00
evazion
8d87b1a0c0 models: fix deprecated errors[:base] << "message" calls.
Replace the idiom `errors[:base] << "message"` with
`errors.add(:base, "message")`. The former is deprecated in Rails 6.1.
2020-12-13 04:10:48 -06:00
evazion
62b69eb133 gems: upgrade http-cookie to fix Rails 6.1 bug.
Upgrade the http-cookie gem to a personal fork containing a bugfix for a
http-cookie bug that is triggered by Rails 6.1.

The bug is that HTTP::Cookie objects raise an exception if they're
compared against non-cookie objects. This bug gets triggered when
the Nijie source strategy calls `Rails.cache.fetch` to cache the
Nijie login cookie. `Rails.cache.fetch` ends up calling
ActiveSupport::Cache::Store::Entry#dup_value!, which compares the cookie
with `true`, which triggers the exception.

The http-cookie gem hasn't been updated for 4 years, so we're stuck
patching the library ourselves.
2020-12-13 04:10:48 -06:00
evazion
8f1d8e2c56 mailers: fix Rails 6.1 incompatibility.
`add_template_helper` is removed in Rails 6.1.
2020-12-13 04:10:48 -06:00
evazion
61e7d32f78 tests: fix FC2 artist normalization url test. 2020-12-13 04:10:48 -06:00
evazion
71ba45c57c forum: fix /forum_posts?search[linked_to] not normalizing tags.
Fix searches like https://danbooru.donmai.us/forum_posts?search[linked_to]=touhou%20
not working because the tag wasn't normalized.
2020-12-13 04:10:48 -06:00
evazion
b002bf25f5 autocomplete: display autocorrected tags like aliases.
Display autocorrected tags similar to aliases, with an arrow pointing at
the corrected tag, but with a dotted underline beneath the misspelled
tag to indicate that it's misspelled.
2020-12-13 04:10:48 -06:00
evazion
6a46aeb55c autocomplete: tune autocorrect algorithm.
Tune autocorrect to produce fewer false positives. Before we used
trigram similarity. Now we use Levenshtein edit distance with a dynamic
typo threshold. Trigram similarity was able to correct large
transpositions (e.g. `miku_hatsune` -> `hatsune_miku`), but it was bad
at correcting small typos. Levenshtein is good at small typos, but can't
correct large transpositions.
2020-12-13 04:10:48 -06:00
evazion
119268e118 autocomplete: fix exception when completing saved search labels.
Fix an exception that was thrown when trying to autocomplete saved
search labels (e.g. `search:all`) as an anonymous user. This was a
pre-existing bug.
2020-12-13 00:45:22 -06:00
evazion
d6a5b9e252 autocomplete: rework cache policy.
The previous cache policy was that all autocomplete results were cached
for a fixed 7 days. The new policy is that if autocomplete returns more
than 10 results they're cached for 24 hours, otherwise if it returns
less than 10 results they're cached for 1 hour.

The rationale is that if autocomplete returns a lot of results, then the
top 10 results are relatively stable and unlikely to change, but if it
returns less than 10 results, then the results are unstable and can be
easily changed.

We also change it so that autocomplete calls can be cached publicly.
Public caching means that HTTP requests are cached by Cloudflare. This
will ideally reduce load on the server and reduce latency for end users.
This is only safe for calls that return the same results for all users
(i.e. the results don't depend on the current user), since the cache is
publicly shared by all users. Currently username, favgroup, and saved
search autocomplete results depend on the current user, so they can't be
publicly cached.
2020-12-13 00:45:22 -06:00
evazion
b0be8ae456 autocomplete: rework tag autocomplete behavior.
Reworks tag autocomplete to work the same way for all users. Previously
autocomplete for Builders worked differently than autocomplete for
regular users.

This is how it works now:

* If the search starts with a slash (/), then do a tag abbreviation
  match. For example, `/evth` matches eyebrows_visible_through_hair.
* Otherwise if the search contains a wildcard (*), then just do a simple
  wildcard search.
* Otherwise do a tag prefix match against tags and aliases. For example,
  `black` matches all tags or aliases beginning with `black`.
* If the tag prefix match returns no results, then do a autocorrect match.

The differences for regular users:

* You can abbreviate tags with a slash (/).

The differences for Builders:

* Now tag abbreviations have to start with a slash (/).
* Autocorrect isn't performed unless a regular search returns no results.
* Results are always sorted by tag count. Before different types of
  results (regular tag matches, alias matches, abbreviation matches,
  and autocorrect matches) were all mixed together based on a tag
  weighting scheme.
2020-12-13 00:45:22 -06:00
evazion
adc1c2c2cc autocomplete: refactor javascript to use /autocomplete endpoint.
This refactors the autocomplete Javascript to use a single dedicated
/autocomplete.json endpoint instead of a bunch of separate endpoints.

This simplifies the autocomplete Javascript by making it so that instead
of calling a different endpoint for each type of query (for users, wiki
pages, pools, artists, etc), then having to parse the results of each
call to get the data we need, we can call a single endpoint that returns
exactly what we need.

This also means we don't have to parse searches clientside in order to
autocomplete metatags. Instead we can just pass the search term to the
server and let it parse the search, which is easy to do serverside.

Finally, this makes autocomplete easier to test, and it makes it easier
to add more sophisticated autocomplete behavior, since most of the logic
lives serverside.
2020-12-13 00:45:22 -06:00
evazion
1484f8852c posts: remove "repopulated 1 old tag" message.
Remove the "Repopulated 1 old tag" message. Show "Created 1 new tag"
instead. The distinction between creating a brand new tag and
repopulating an empty tag doesn't matter.
2020-12-13 00:45:22 -06:00
evazion
be69778d25 BURs: fix validation error when aliasing tags with implications.
Bug: when aliasing a tag that implied another tag, it was possible for
the alias to fail. Moving the implication could fail because we checked
that the tag category of both tags in the implication was the same, but
we did this before the alias moved the category of the old tag to the
new tag.
2020-12-05 15:05:06 -06:00
evazion
9b48c98c61 Fix #4614: Counts endpoint responds with invalid JSON.
Caused by the search timing out and returning nil for the count. Nil got
serialized as the empty string instead of as null.
2020-12-05 13:10:11 -06:00
evazion
cc781ba2b9 tests: add tests for #4551, #4630. 2020-12-05 12:54:32 -06:00
evazion
92b6204a77 Merge pull request #4630 from nonamethanks/fix_fc2
Fix blog.fc2 urls matching wrong artists
2020-12-05 12:53:51 -06:00
evazion
b358714790 tests: add test for #4613. 2020-12-05 12:48:45 -06:00
evazion
d5d77e506f Merge pull request #4631 from nonamethanks/fix_ordfav
Return empty search for ordfav of fake user
2020-12-05 12:46:26 -06:00
evazion
c8a9015e8e Merge pull request #4611 from aaronfranke/formatting
Make file formatting comply with POSIX standards and remove trailing space characters
2020-12-05 12:45:38 -06:00
evazion
ab8d000b8b logins: redirect back to previous page after login. 2020-12-05 12:40:48 -06:00
evazion
c42f4fae9d BURs: allow implying empty tags.
Allow implications when either tag is empty to account for things like
aliases or mass updates moving tags around.
2020-12-05 12:32:28 -06:00
evazion
7f9fbc25b9 dtext: fix username mentions in [bur:id] tags.
Use the regular name (with underscores) instead of the pretty name (with
spaces) because <@mention> syntax can't handle spaces.
2020-12-05 00:55:09 -06:00
nonamethanks
4070354322 Return empty search for ordfav of fake user 2020-12-04 01:03:34 +01:00
evazion
db3983f487 implications: disable timeout when checking tag count. 2020-12-03 17:25:20 -06:00
nonamethanks
32f4cb1236 Fix blog.fc2 urls matching wrong artists 2020-12-04 00:17:02 +01:00
evazion
9934fd4a70 Update ruby gems and yarn packages. 2020-12-03 17:15:24 -06:00
evazion
8a52d8ed5f BURs: remove dead error handling code.
This is a 'this should never happen' error. This error is only raised if
we add a new bulk update request type and forget to handle it somewhere.
2020-12-03 17:15:24 -06:00
evazion
35d26e92e9 BURs: don't update OP when approving BUR.
When approving or rejecting a BUR, don't edit the OP forum post to add
an EDIT: line stating the request has been approved. Instead just let
the embedded BUR state who it was approved by, and post a reply saying
that the request has been approved.
2020-12-03 17:15:24 -06:00
evazion
19adf92a39 BURs: impose a maximum size limit on BURs.
Enforce a maximum size limit of 100 lines per BUR. Larger BURs should be
split into smaller chunks.
2020-12-03 14:34:43 -06:00
evazion
8a959b44df BURs: don't allow renames for tags with more than 200 posts.
Don't allow tags with more than 200 posts to be renamed. An alias must
be used instead.
2020-12-03 14:24:16 -06:00
evazion
1c9a926eac BURs: add size requirements for implications.
Implications now have the following rules:

* The child tag must have at least 10 posts.
* The child tag must be at least 0.01% the size of the parent tag.
* The child tag can't make up more than 90% of the parent tag.
* These rules only apply to general tags.
2020-12-03 13:58:51 -06:00
evazion
4a4c198287 BURs: don't allow implying tags from different categories.
Don't allow requests for implications between tags of different
categories. For example, don't allow character tags to imply copyright
tags.
2020-12-02 15:02:29 -06:00
evazion
6275e85148 BURs: refactor implication wiki page validations.
Move the validation that the tags in an implication must have wiki pages
back into the TagImplication model. Use validation contexts to only run
the validation when the BUR is created, not when the BUR is approved.
2020-12-02 14:30:18 -06:00
evazion
b7b15b3d95 BURs: add nuke command.
Usage:

* `nuke touhou`
* `nuke pool:Disgustingly_Adorable`

Add a command for nuking tags. `nuke A` is a shortcut for `mass update A -> -A`.
This means it also works for pools.
2020-12-02 13:08:34 -06:00
evazion
86e4c21e48 implications: refactor automatic tags.
Move #automatic_tags_for out of TagImplication since it doesn't really
belong here.
2020-12-02 12:51:51 -06:00
evazion
6485a053a5 aliases: allow aliases to be reversed in one step.
Allow reversing an alias without having to remove the old alias first.
When aliasing A -> B, then if B -> A already exists it will
automatically be removed first.
2020-12-02 12:44:43 -06:00
evazion
9e37f5a588 BURs: don't log mod actions for aliases/implications/mass updates.
Don't log mod actions when aliases, implications, or mass updates are
processed.

Originally aliases and implications were logged because they could be
approved outside of a BUR. Mass updates could also be performed by mods
without making a forum request. This is no longer the case.

They were also logged for debugging purposes. This is no longer needed.
This generated a lot of spam in the mod action logs when a large BUR was
approved.
2020-12-02 12:20:28 -06:00
evazion
33c9d34927 dtext: link to active/rejected BURs in forum posts.
Make "The bulk update request #XXX is active." link to the BUR.
2020-12-01 19:30:35 -06:00
evazion
b9dda5bd21 users: fix /users?name=<username> being case sensitive.
Things like https://danbooru.donmai.us/users?name=Evazion didn't work.
2020-12-01 19:18:39 -06:00
evazion
facc73f23f views: don't cache news updates.
Don't fragment cache the site news banner. Caching this trades a SQL
query for a Redis call, which is unlikely to make much performance
difference to page rendering but puts high traffic volume on Redis.
2020-12-01 19:11:05 -06:00
evazion
0be0395776 BURs: fix validation of multi-step BURs.
Bug: When validating a BUR, we didn't properly simulate running each
line of the BUR in order, which could cause validation to incorrectly
fail in multi-line BURs where some lines depended on previous lines.

This bug meant you couldn't reverse an alias in a single BUR. The old
alias wasn't removed before validating the new alias, so the BUR would
fail with an alias conflict.

This bug also meant that BURs containing duplicate aliases or
redundant implications weren't caught.

The fix is for BUR validation to actually simulate creating and removing
aliases in sequential order, just as they would be when the BUR is
approved. This is done by running the BUR in a transaction, then
rolling back the transaction at the end. This is hacky but it works.
2020-12-01 18:58:45 -06:00
evazion
293b2c0be8 implications: don't update posts that already have the new tag.
When approving an implication, only retag posts that are missing the new
tag. Don't try to update posts that already have the tag. This makes
large implication requests faster to process when most of the posts
already have the implied tag.
2020-12-01 18:58:45 -06:00
evazion
4741a52cc4 aliases/implications: remove 'error' state.
Remove the error status from aliases and implications. Aliases and
implications normally shouldn't fail because they're validated
beforehand. If they do, just let the delayed job itself record the
failure.

Also disable the delayed job from retrying if the alias/implication
somehow fails.
2020-12-01 18:58:45 -06:00
evazion
8717c319ab aliases/implications: remove 'pending' state.
Remove the pending status from tag aliases and implications.

Previously aliases would be created first in the pending state then
changed to active when the alias was later processed in a delayed job.
This meant that BURs weren't processed completely sequentially; first
all the aliases in a BUR would be created in one go, then later they
would be processed and set to active sequentially.

This was problematic in complex BURs that tried to reverse or swap
around aliases, since new pending aliases could be created before old
conflicting aliases were removed.
2020-12-01 18:58:45 -06:00
evazion
45d050d918 tests: fix artist ban tests. 2020-12-01 14:16:47 -06:00
evazion
048db3aacb Update ruby gems and yarn packages. 2020-12-01 13:35:06 -06:00
evazion
dc712258cf Revert "Temp disable popular tags and news banner."
This reverts commit f9a44ab192.
2020-11-12 20:15:45 -06:00