Commit Graph

820 Commits

Author SHA1 Message Date
evazion
07e23204b6 rubocop: fix various Rubocop warnings. 2021-06-17 04:17:53 -05:00
evazion
0f36bbf8d3 iqdb: update API client to use new version of IQDB.
Replace the old IQDB API client with a new client for the new forked
version of IQDB at https://github.com/danbooru/iqdb.

Changes:

* The /iqdb_queries endpoint now returns `hash` and `signature` fields.
  The `signature` is the full decoded Haar signature, while the `hash`
  is a encoded version of the signature.
* The /iqdb_queries endpoint no longer returns `width` and `height`
  fields in the response (these were always 128x128).
* We no longer need the IQDBs frontend server, now we talk to the IQDB
  instance directly.
* We no longer send add/remove image commands to IQDB through AWS SQS,
  now we send them to IQDB directly. They are sent in a delayed job so
  that if IQDB is down, uploading images is still possible, the add
  image commands will just get queued up.
* Fix a bug where regenerating an image's thumbnails didn't regenerate
  IQDB, because IQDB silently ignored add image commands when the image
  already existed in the database.
2021-06-16 05:36:24 -05:00
evazion
243b3264e9 posts: fix posts with .jpeg file extension.
There used to be about 1000 posts with a .jpeg file extension instead of
.jpg. These posts have been fixed manually, so we no longer have to
check for this any more.
2021-04-02 02:41:54 -05:00
evazion
28c0a48117 discord: fix tag search commands being limited to 2 tags. 2021-03-14 16:42:07 -05:00
evazion
698be2d0e4 discord: add /random command. 2021-03-11 21:23:20 -06:00
evazion
af84314c38 posts: remove dead has_ugoira_webm? code. 2021-02-18 04:05:18 -06:00
evazion
4c0c3360e7 Fix #4689: Remove 7 day waiting period for new uploaders. 2021-02-04 00:20:52 -06:00
evazion
50864c7147 Fix #4685: Tagging "aliased_tag -aliased_tag" adds aliased_tag. 2021-02-03 23:24:12 -06:00
evazion
d0c9f6e0b8 posts: allow toggling between upvotes and downvotes.
Like 9efb374ae, allow users to toggle between upvoting and downvoting a
post without raising an error or having to manually remove the vote
first. If you upvote a post, then downvote it, the upvote is
automatically removed and replaced by the downvote.

Other changes:

* Tagging a post with `upvote:self` or `downvote:self` is now silently
  ignored when the user doesn't have permission to vote, instead of
  raising an error.
* Undoing a vote that doesn't exist now does nothing instead of
  returning an error. This can happen if you open the same post in two
  tabs, undo the vote in tab 1, then try to undo the vote again in tab 2.

Changes to the /post_votes API:

* `POST /post_votes` and `DELETE /post_votes` now return a post vote
  instead of a post.
* The `score` param in `POST /post_votes` is now 1 or -1, not `up` or
  `down`.
2021-01-29 02:22:23 -06:00
evazion
07bdc6eab0 comments: rework thresholded comments.
Previously thresholded comments were hidden completely. You had to click
the "Show X hidden comments" button to unhide all hidden comments in a
thread. Now it works like this:

* When a comment is below your threshold, the comment text is hidden and
  replaced by a `[hidden]` link, which you can click to unhide the comment.

* When a comment is at half your threshold (for example, your threshold
  is -8 but the comment is at -4), then the comment is greyed out.

This means that comments aren't completely hidden, they're just
collapsed, so you can see the commenter and the score without unhiding
the comment. It also means you don't have to scroll back up to unhide a
comment, and threads aren't disrupted by comments being secretly
hidden (which is confusing when people are replying to hidden comments,
which forces you to go back up and unhide to find).
2021-01-19 04:07:33 -06:00
evazion
054ac51d47 policies: remove current request from context.
This refactors Pundit policies to only rely on the current user, not on
the current user and the current HTTP request. In retrospect, it was a
bad idea to include the current request in the Pundit context. It bleeds
out everywhere and there are many contexts (in tests and models) where
we only have the current user, not the current request. The previous
commit got rid of the only two places where we used it.
2021-01-17 00:57:59 -06:00
evazion
b4530183f4 Fix #4525: Show mod report notices next to reported content. 2021-01-16 01:02:42 -06:00
evazion
966a7aa71c posts: remove unused data-views data attribute. 2021-01-14 21:17:57 -06:00
evazion
ef177a09cf searchable: fixup bugs in e7b454686. 2021-01-11 19:47:20 -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
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
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
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
evazion
dbb66ace90 routes: replace hardcoded routes in models with route helpers.
Add a Routes module that gives models access to route helpers outside of
views, and use it to replace various hardcoded routes.
2020-12-24 00:17:19 -06:00
evazion
6c99bbbf47 posts: limit sources to 1200 chars long.
The longest sources on Danbooru are DeviantArt wixmp.com sources, which
max out at ~900 chars.
2020-12-21 22:42:39 -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
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
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
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
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
evazion
5db11a0b5f Merge branch 'master' into attribute-searching 2020-08-17 14:23:00 -05:00
evazion
f337902c57 modqueue: fix performance regression from including appeals.
* Add index on posts.is_deleted. The modqueue was slow because we the
 appeal condition wasn't constrained to deleted posts, so it degraded to
 a full table scan.

* Avoid extra queries for calculating the page count and disapproval counts.
2020-08-16 14:31:47 -05:00
evazion
0297b631fb moderation: extract 3 day modqueue length to config. 2020-08-12 13:11:22 -05:00
nonamethanks
7c03f0d6c9 Copy annotation tags when copying notes 2020-08-12 06:21:50 +02:00
evazion
3a17b5a13e flags/appeals: replace is_resolved flag with statuses.
Replace references to the `is_resolved` field with the `status` field.
Post flags were marked as resolved when a post was approved (but not
when the post was deleted because it went unapproved). The status field
supercedes the resolved field.
2020-08-07 19:24:57 -05:00
evazion
dd44dce597 posts: fix exception when viewing invalid .zip file.
Fix exception when viewing post #23077 (a .zip that is not a ugoira).
Caused by including large_image_width in the image's data-* attributes.
The image_width was nil, which caused a comparison to fail.
2020-08-07 08:22:23 -05:00
evazion
0a0a85ee70 Fix #4568: Send appealed posts back to the mod queue
* Include appealed posts in the modqueue.

* Add `status` field to appeals. Appeals start out as `pending`, then
  become `rejected` if the post isn't approved within three days. If the
  post is approved, the appeal's status becomes `succeeded`.

* Add `status` field to flags. Flags start out as `pending` then become
  `rejected` if the post is approved within three days. If the post
  isn't approved, the flag's status becomes `succeeded`.

* Leave behind a "Unapproved in three days" dummy flag when an appeal
  goes unapproved, just like when a pending post is unapproved.

* Only allow deleted posts to be appealed. Don't allow flagged posts to be appealed.

* Add `status:appealed` metatag. `status:appealed` is separate from `status:pending`.

* Include appealed posts in `status:modqueue`. Search `status:modqueue order:modqueue`
  to view the modqueue as a normal search.

* Retroactively set old flags and appeals as succeeded or rejected. This
  may not be correct for posts that were appealed or flagged multiple
  times. This is difficult to set correctly because we don't have
  approval records for old posts, so we can't tell the actual outcome of
  old flags and appeals.

* Deprecate the `is_resolved` field on post flags. A resolved flag is a
  flag that isn't pending.

* Known bug: appealed posts have a black border instead of a blue
  border. Checking whether a post has been appealed would require either
  an extra query on the posts/index page, or an is_appealed flag on
  posts, neither of which are very desirable.

* Known bug: you can't use `status:appealed` in blacklists, for the same
  reason as above.
2020-08-06 20:55:45 -05:00
evazion
f9aa1e9718 posts: don't reparent children when expunging posts.
If an expunged post has children, just set their parent to null instead
of reparenting them. Before we reparented them to the oldest child.
2020-08-04 12:28:20 -05:00
evazion
b57122cf7f posts: log md5 when expunging posts. 2020-08-04 12:12:16 -05:00
evazion
79077df713 posts: don't move favorites to parent when expunging.
Don't automatically move favorites to the parent when expunging a post.
This can be done manually if necessary. Posts shouldn't have their
favorites moved unless they're duplicates, which expunged posts usually
aren't.
2020-08-04 12:04:52 -05:00
evazion
3440010310 posts: allow new accounts to remove tags.
Remove the rule that new accounts can't remove tags (except for tagme
and *_request tags) until their account is a week old.
2020-08-04 12:00:13 -05:00
evazion
bfdc13a4bb Fix #4574: "unknown keyword: :tag_count" when changing tag category.
Bug: Tag#update_post_category_counts effectively called
`update_all("tag_count_general" => 123, :tag_count => 456)`, which led
to an argument error due to the :tag_count symbol being treated as a
keyword argument.

Fix: Don't mess around with `update_all`, just regenerate the tag counts
then `save!` the post. We have to do this in an after_save callback
because we need the updated category to be in the database for `set_tag_counts`
to work. Delete `fix_post_counts` because it was unused.

This is most likely a regression caused by the upgrade of the
newrelic_rpm gem to 6.12. This can only be reproduced in production when
using Newrelic and it didn't happen before the upgrade. Presumably
Newrelic is splatting the arguments when it calls `update_all`, which
causes symbol keys to be treated as keywords.
2020-08-04 10:58:42 -05:00
evazion
157cb96551 posts: clean up delete! method.
* Remove unused `ban` and `without_mod_action` options.

* Don't try to set the `is_banned` flag during deletion.

* Don't create modactions for automatic "unapproved in 3 days"
  deletions, only to delete them after the fact.
2020-08-03 20:21:28 -05:00
evazion
3fe18c57d0 posts: always show "resized to X%" notice on mobile.
Always show the "Resized to X% of original" notice when viewing a sample
image on mobile.
2020-07-31 15:09:56 -05:00
BrokenEagle
c4009efccd Convert models to use new search includes mechanism 2020-07-27 19:29:18 +00:00
evazion
5687c67fc3 posts: autotag video instead of webm/mp4.
Automatically add the `video` tag instead of the `webm` or `mp4` tags.
2020-07-13 19:25:29 -05:00
evazion
40a114c99c posts: restrict banned paid rewards for non-approvers. 2020-07-06 13:52:57 -05:00
evazion
0c7d48d890 posts: autoban uploads tagged paid_reward. 2020-07-06 13:52:46 -05:00
evazion
1a8729e0d9 Fix #4462: "You have already favorited this post" on upload.
Make adding the fav:self metatag ignore all errors, including when the
post was already favorited before editing the post.
2020-06-30 14:29:25 -05:00
evazion
eacb4d4df3 models: factor out api_attributes to policies.
Refactor models so that we define attribute API permissions in policy
files instead of directly in models.

This is cleaner because a) permissions are better handled by policies
and b) which attributes are visible to the API is an API-level concern
that models shouldn't have to care about.

This fixes an issue with not being able to precompile CSS/JS assets
unless the database was up and running. This was a problem when building
Docker images because we don't have a database at build time. We needed
the database because `api_attributes` was a class-level macro in some
places, which meant it ran at boot time, but this triggered a database
call because api_attributes used database introspection to get the list
of allowed API attributes.
2020-06-08 18:38:02 -05:00
nonamethanks
307df3b3e4 Refactor source normalization
* Move the source normalization logic out of the post model
  and into individual sources' strategies.
* Rewrite normalization tests to be handled into each source's test,
  and expand them significantly. Previously we were only testing
  a very small subset of domains and variants.
* Fix up normalization for several sites.
* Normalize fav.me urls into normal deviantart urls.
2020-05-21 22:46:51 +02:00
evazion
ad02e0f62c posts/index: fix rating:s being included in page title in safe mode.
Fixes bug described in d3e4ac7c17 (commitcomment-39049351)

When dealing with searches, there are several variables we have to keep
in mind:

* Whether tag aliases should be applied.
* Whether search terms should be sorted.
* Whether the rating:s and -status:deleted metatags should be added by
  safe mode and the hide deleted posts setting.

Which of these things we need to do depends on the context:

* We want to apply aliases when actually doing the search, calculating
  the count, looking up the wiki excerpt, recording missed/popular
  searches in Reportbooru, and calculating related tags for the sidebar,
  but not when displaying the raw search as typed by the user (for
  example, in the page title or in the tag search box).
* We want to sort the search when calculating cache keys for fast_count
  or related tags, and when recording missed/popular searches, but not
  in the page title or when displaying the raw search.
* We want to add rating:s and -status:deleted when performing the
  search, calculating the count, or recording missed/popular searches,
  but not when calculating related tags for the sidebar, or when
  displaying the page title or raw search.

Here we introduce normalized_query and try to use it in contexts where
query normalization is necessary. When to use the normalized query
versus the raw unnormalized query is still subtle and prone to error.
2020-05-12 21:47:00 -05:00