Commit Graph

2995 Commits

Author SHA1 Message Date
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
ee4516f5fe searchable: refactor searchable_includes.
Pass searchable associations directly to search_attributes instead of
defining them separately in searchable_includes.
2020-12-16 23:57:07 -06:00
evazion
e771c0fca8 searchable: don't automatically include id, created_at, updated_at.
Don't make search methods on models call super in order to search
certain default attributes (id, created_at, updated_at). Simplifies some
magic.
2020-12-16 23:57:07 -06:00
evazion
c02c31b966 autocomplete: recognize Japanese tags in autocomplete.
Allowing typing Japanese tags in autocomplete. For example, typing 東方
in autocomplete will be completed to the touhou tag. Typing ぶくぶ will
complete to the bkub tag.

This works using wiki page and artist other names. Effectively, any name
listed as an other name in a wiki or artist page will be treated like an
alias for autocomplete purposes. This is limited to non-ASCII other names,
to prevent English other names from interfering with regular tag searches.
2020-12-14 18:58:11 -06:00
evazion
852c67f1b7 users: fix #owner method. 2020-12-14 14:13:11 -06:00
evazion
2e633f84f6 emails: add /emails index page.
Add emails index page at https://danbooru.donmai.us/emails. Mods can use
this page to view and search emails belonging to users below mod level.
2020-12-13 21:21:08 -06:00
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
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
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
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
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
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
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
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
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
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
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
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
7f90bc4216 BURs: remove ability to skip secondary validations.
Remove the ability to skip secondary validations when creating a BUR.
The only skippable validation that still existed was the requirement
that both tags in an implication must have wiki pages. It's now
mandatory to write wiki pages for tags before you can request an
implication. This doesn't apply to empty tags.
2020-11-12 20:15:14 -06:00
evazion
25cba710bf BURs: don't allow requesting implications that already exist.
Fix it being possible to request duplicate implications.
2020-11-12 20:15:14 -06:00
evazion
654d2175b6 aliases/implications: remove processing state.
Remove the `processing` state from aliases and implications. This state
was used to mark when an alias or implication had been approved but the
alias or implication was still being processed. Aliases in the
processing state were still considered active, so there was no
functional difference between the active state and the processing state.

This fixes a problem where it was possible for implications to get stuck
in the processing state. This happened when a BUR contained a duplicate
implication. Transitioning from the processing state to the active state
failed in this case because we used `update` instead of `update!`, which
meant validation errors were silently ignored.
2020-11-12 18:22:51 -06:00
evazion
5844f16ed6 BURs: make rename command move aliases/implications.
Make the tag rename command also move any aliases or implications from
the old tag to the new tag. Previously only the create alias command
moved aliases and implications.
2020-11-12 17:12:09 -06:00
evazion
9a287cd71f Fix #4483: Wrong order for BUR caused 12k mistags.
Bug: if a BUR contained a mass update followed by an alias, then the
alias would become active before the mass update, which could cause
the mass update to return incorrect results if both the alias and mass
update touched the same tags.

This happened because all aliases and implications in the BUR were set
to a queued state before the mass update was processed, but putting an
alias in the queued state effectively made it active.

The fix is to remove the queued state. This was only used anyway as a
debugging tool anyway to monitor the state of BURs as they were being
processed.
2020-11-12 16:09:56 -06:00
evazion
cc64f8b7ee tests: fix broken source tests.
Fix various tests broken by source files changing or being deleted.
2020-11-10 14:52:54 -06:00
evazion
aa2d04322a users: fix not being able to verify account with certain valid emails.
Bug: Verifying your account with a hotmail.com email address didn't mark
your account as verified. This was because the list of allowed email
verification domains only included normalized domains, but we were
looking up unnormalized domains.
2020-09-21 15:06:47 -05:00
evazion
7bc7001b12 dmails: add dmail sending rate limits.
Don't allow regular users to send dmails to more than 10 different
users in one hour. This is an anti-spam measure.
2020-08-28 12:36:42 -05:00
evazion
5baeb3eecc dmails: update unread dmail count when dmail is hard deleted.
When a dmail is hard deleted, update the user's unread dmail count and
delete any associated mod reports.

Dmails aren't normally hard deleted, except when there's a large spam
wave that necessitates manual intervention.
2020-08-28 11:28:28 -05:00
evazion
346b143e40 Fix #4599: Editing saved search fails when user has maximum saved searches. 2020-08-27 22:25:16 -05:00
evazion
7770c38d0d saved searches: rearrange macros.
Move macros to the top of file, as they should be.
2020-08-27 21:39:49 -05:00
evazion
bbf2b53d83 aliases: fix broken wiki links when aliasing tags.
When aliasing A to B, update any wikis linking to [[A]] to link to [[B]]
instead.

This is a best-effort process based on rough heuristics. There are a few
known problems:

* We don't always know how to capitalize the new tag. We try to mimic
  the capitalization of the old tag, such that if the old tag was
  capitalized (because it was at the beginning of a sentence), or if
  every word in the old link was capitalized (because it's a proper
  noun), then the new link will be capitalized in the same way. This can
  handle simple general tags and character tags, but will fail for
  copyright tags with mixed capitalization. For example, we don't know
  that [[jojo_no_kimyou_na_bouken]] should be capitalized as [[JoJo no
  Kimyou na Bouken]]. If we don't know how to capitalize the new tag, we
  leave the old tag as-is so it can manually be fixed.

* Some aliases might require changing how a tag is pluralized. If we
  changed [[rat]] to [[mouse]], then we should change `[[rat]]s` to
  [[mice]]. We don't try to deal with this.

* In general, some changes might require entire sentences to be
  rewritten to keep the grammar correct. Changing something like
  [[skirt lift]] to [[lifting skirt]] could break the grammar of the
  sentence. We don't try to deal with this.
2020-08-26 19:02:19 -05:00
evazion
f4f25cf0c8 aliases: fix blacklists when aliasing tags.
When aliasing a tag, update any blacklists containing the old tag to use
the new tag.
2020-08-26 17:06:00 -05:00
evazion
f0299a8945 aliases: refactor tag moving code.
* Factor out the code for moving tags from tag aliases to a separate
  TagMover class.

* When aliasing two tags that have conflicting wikis, merge the old wiki
  into the new one instead of failing with an error. Merge the other names
  fields, replace the old wiki body with a message linking to the new
  wiki, and mark the old wiki as deleted.

* When aliasing two tags that have conflicting artist entries, merge the
  old artist into the new one instead of silently ignore the conflict.
  Merge the group name, other names, and urls fields, and mark the old
  artist as deleted.

* When two tags have conflicting wikis or artist entries, but the old
  wiki or artist entry is deleted, then just ignore the old wiki or
  artist and don't try to merge it.

* Fix it so that when saved searches are rewritten, we rewrite negated
  searches too.
2020-08-26 17:05:41 -05:00
evazion
d9085877be BURs: fix normalization of uppercase characters in scripts.
Only downcase tags in aliases, implications, and category change
commands. Don't downcase mass update commands. Mass updates are
potentially case sensitive (for example: `mass update source:imageboard -> source:Imageboard`).
2020-08-24 17:54:53 -05:00
evazion
1ddcc661e1 BURs: clean up parsing and error handling.
* Don't raise exceptions when a BUR is invalid. Instead, use Rails
  validations to return errors. Fixes invalid BURs potentially raising
  exceptions in views. Also makes it so that each error in a BUR is
  reported, not just the first one.

* Revalidate the BUR whenever the script is edited, not just when the
  BUR is created. Ensures the BUR can't be broken by editing. Fixes a bug
  where forum threads could be broken by someone editing a BUR and
  breaking the syntax, thereby causing the BUR to raise an unparseable
  script error when the forum thread was viewed.

* Validate that removed aliases and implication actually exist.

* Validate that the tag actually exists when changing a tag's category.

* Combine bulk update request processor unit tests with main bulk update
  request unit tests.
2020-08-24 17:10:48 -05:00
evazion
a79aad443d tag relationships: fix typo in consequent_wiki association.
The consequent_wiki association incorrectly used the antecedent wiki.
This caused wiki conflict errors when approving aliases.
2020-08-19 17:04:25 -05:00
evazion
5bad5c6012 comments: fix visible method conflict.
Fix the `Comment#visible` method conflicting with the base class
`visible` method defined in ApplicationRecord.
2020-08-18 15:34:12 -05:00
evazion
937653e519 models: move html_data_attributes to policies.
Move html_data_attributes definitions from models to policies. Which
attributes are permitted as data-* attributes is a view level concern
and should be defined on the policy level, not the model level. Models
should be agnostic about how they're used in views.
2020-08-17 22:33:18 -05:00