Commit Graph

97 Commits

Author SHA1 Message Date
evazion
a442658f8a Fix #5237: Deleted comments can be viewed by other users
* Fix it so non-moderators can't search deleted comments using the
  `updater`, `body`, `score`, `do_not_bump_post`, or `is_sticky` fields.
  Searching for these fields will exclude deleted comments.

* Fix it so non-moderators can search for their own deleted comments using the
  `creator` field, but not for deleted comments belonging to other users.

* Fix it so that if a regular user searches `commenter:<username>`, they
  can only see posts with undeleted comments by that user. If a moderator or
  the commenter themselves searches `commenter:<username>`, they can see all
  posts the user has commented on, including posts with deleted comments.

* Fix it so the comment count on user profiles only counts visible
  comments. Regular users can only see the number of undeleted comments
  a user has, while moderators and the commenter themselves can see the
  total number of comments.

Known issue:

* It's still possible to order deleted comments by score, which can let
  you infer the score of deleted comments.
2022-09-22 19:17:33 -05:00
evazion
88ac91f5f3 search: refactor to pass in the current user explicitly. 2022-09-22 04:31:21 -05:00
evazion
1d2bac7b95 Remove CurrentUser.ip_addr.
Remove the `CurrentUser.ip_addr` global variable and replace it with
`request.remote_ip`. Before we had to track the current user's IP in a
global variable so that when we edited a post for example, we could pass
down the user's IP to the model and save it in the post_versions table.
Now that we now longer save IPs in version tables, we don't need a global
variable to get access to the current user's IP outside of controllers.
2022-09-18 05:02:10 -05:00
evazion
d4da8499ce models: stop saving IP addresses in version tables.
Mark various `creator_ip_addr` and `updater_ip_addr` columns as ignored
and stop updating them in preparation for dropping them.
2022-09-18 03:49:17 -05:00
evazion
ee638f976f Add /user_actions page.
Add a /user_actions page. This page shows you a global timeline of
(almost) all activity on the site, including uploads, comments, votes,
edits, forum posts, and so on.

The main things it doesn't include are post edits, pool edits, and
favorites (posts and pools live in a separate database, and favorites
don't have the timestamps we need for ordering).

This page is useful for moderation purposes because it lets you see a
history of almost all of a user's activity on a single page.

Currently this page is mod-only. In the future it will be open to all
users, so you can view the history of your own site activity, or the
activity of others.
2022-09-16 05:39:25 -05:00
evazion
345a222163 Fix #4999: Unexpected error: ActiveRecord::RecordNotUnique sometimes appears when uploading posts
Fix two issues that could lead to duplicate errors when creating posts:

* Fix the submit button on the upload form to disable itself on submit, to prevent
  accidental double submit errors.

* Fix a race condition when checking for MD5 duplicates. MD5 uniqueness is checked on both
  the Rails level, with a uniqueness validation, and on the database level, with a unique
  index on the md5 column. Creating a post could fail with an ActiveRecord::RecordNotUnique
  error if the uniqueness validation in Rails passed, but the uniqueness constraint in the
  database failed. In this case, we catch the RecordNotUnique error and convert it to a
  Rails validation error so we can treat it like a normal validation failure.
2022-02-07 21:02:30 -06:00
evazion
33103f6dc4 pools: add ability to search for pools linking to given tag.
Add ability to search for pools linking to a given tag in the pool
description. Example:

    https://danbooru.donmai.us/pools?search[linked_to]=touhou

(This isn't actually exposed in the UI to avoid cluttering the pool
search form with rarely used options.)

Pools with broken links can be found here:

    https://danbooru.donmai.us/dtext_links?search[has_linked_tag]=No&search[has_linked_wiki]=No&search[model_type]=Pool

Lays the groundwork for fixing #4629.
2022-01-15 20:26:30 -06:00
evazion
ea069c7b0d models: remove hack to ignore tsvector columns.
Previously we overrode `ActiveRecord::Base#columns` to make it ignore
tsvector columns so they wouldn't show up in API responses. These
columns have been removed, so this is no longer necessary.
2022-01-07 11:23:53 -06:00
evazion
a7dc05ce63 Enable frozen string literals.
Make all string literals immutable by default.
2021-12-14 21:33:27 -06:00
evazion
300bc6941e newrelic: log with_timeout errors as expected.
Make it so that when a database call inside a `with_timeout` block times
out, the error logged to New Relic is marked as expected. This is so
that expected timeouts, such as timeouts when calculating search counts
or timeouts when generating related tags for the sidebar, don't count
against the error rate.
2021-10-14 23:39:21 -05:00
evazion
e72446463e Fix #4901: Duplicate disapprovals
* Add uniqueness constraint on post_disapprovals (user_id, post_id).
* Add fix script to remove existing duplicates.
2021-10-12 20:22:00 -05:00
evazion
f9d25660b8 Fixup regression in 2eb89a835.
Fix regression in 2eb89a835 that broke the modqueue page because the
arguments to `paginated_search` changed and weren't updated here.

Also fix incorrect YARD documentation syntax.
2021-09-29 06:28:53 -05:00
evazion
2eb89a8354 Fix #4601: Hide deleted pools by default in pool search.
* On /pools, hide deleted pools by default in HTML responses. Don't
  filter out deleted pools in API responses.

* API change: on /forum_topics, only hide deleted forum topics by
  default for HTML responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/forum_topics.json?search[is_deleted]=false
  to filter out deleted topics.

* API change: on /tags, only hide empty tags by default for HTML
  responses, not for API responses. Explicitly do
  https://danbooru.donmai.us/tags.json?search[is_empty]=false to filter
  out empty tags.

* API change: on /pools, default to 20 posts per page for API responses,
  not 40.

* API change: add `search[is_empty]` param to /tags.json endpoint.
  `search[hide_empty]=true` is deprecated in favor of `search[is_empty]=false`.

* On /pools, add option to show/hide deleted pools in search form.

* Fix the /forum_topics page putting `search[order]=sticky&limit=40` in
  the URL when browsing past page 1.
2021-09-29 05:44:59 -05:00
evazion
79fdfa86ae Fix various rubocop warnings. 2021-09-27 00:46:13 -05:00
evazion
463e6d7b49 artists: fix deadlock when banning artists.
Caused by d854bf6b. Banning an artist would deadlock because it was
performed in a transaction, which didn't work with the `parallel_each`
inside the "create an implication to banned_artist" step.
2021-09-24 08:40:33 -05:00
evazion
98b3c82ac5 tests: fix deadlock during artist ban test.
The artist ban tests deadlocked because of a weird interaction between
threads and database transactions when tagging posts in parallel. Add a
hack to work around it.
2021-09-20 02:09:14 -05:00
evazion
d854bf6b53 BURs: update posts in parallel.
When processing an alias, rename, implication, mass update, or nuke,
update the posts in parallel. This means that if we alias foo to bar,
for example, then we use four processes at once to retag the posts from
foo to bar.

This doesn't mean that if we have two aliases in a BUR, we process both
aliases in parallel. It simply means that when processing an alias, we
update the posts in parallel for that alias.
2021-09-20 01:12:14 -05:00
evazion
e23f09235e artists: redact version histories of banned artists.
Fix names and urls of banned artists being visible in Google through
artist version pages.
2021-02-07 23:28:50 -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
0899194f6b Fix conflict between normalize and array_attribute macros.
Fix the `normalize` and `array_attribute` macros conflicting with each
other on the WikiPage model. This meant code like
`wiki_page.other_names = "foo bar"` didn't work. Both macros defined a
`other_names=` method, but one method overrode the other.

The fix is to use anonymous modules and prepend so we can chain method
calls with super.
2021-01-10 02:03:12 -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
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
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
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
BrokenEagle
c141a358bd Add support for chaining more search includes
- A generalized search includes function was added
-- The post and user includes functions were changed to use that
- A search function for polymorphic includes was added
- All models are given 3 class functions to control which includes
  are searchable, and extra restrictions for the "has_" params
2020-07-27 19:29:17 +00: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
45b3370d49 models: fix exception in api_attributes.
Fixup bug in eacb4d4df when calling `api_attributes` on an object that
doesn't have a policy (its policy inherited from ApplicationPolicy).
2020-06-10 18:16:58 -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
evazion
5bc0ab446b models: add deletable concern. 2020-03-06 17:06:29 -06:00
evazion
04b69954eb modqueue: add order options; change default order to newest first.
* Add options for changing the order of the modqueue (newest first,
  oldest first, highest scoring first, lowest scoring first).

* Change the default order from oldest posts first to most recently
  flagged or uploaded posts first.

* Add an order:modqueue metatag to order by most recently flagged or
  uploaded in standard searches.
2020-03-03 03:25:51 -06:00
evazion
b915f1c586 Revert "application model: move pagination extension to concern."
This reverts commit 7855e36d17.

Broke pagination due to incorrect memoization causing @paginator_count
to be shared between requests.
2020-02-25 01:07:09 -06:00
evazion
7855e36d17 application model: move pagination extension to concern. 2020-02-23 17:26:04 -06:00
evazion
0ad42d23c9 models: refactor search visibility methods.
Refactor how model visibility works in index actions:

* Call `visible` in the controller instead of in model `search`
  methods. This decouples model visibility from model searching.

* Explicitly pass CurrentUser when calling `visible`. This reduces
  hidden dependencies on the current user inside models.

* Standardize on calling the method `visible`. In some places it was
  called `permitted` instead.

* Add a `visible` base method to ApplicationModel.
2020-02-19 17:08:59 -06:00
evazion
bd6d896ee0 models: factor out concerns to app/logical/concerns. 2020-02-19 16:37:24 -06:00
evazion
ed702b8854 Fix deprecated keyword argument warnings in Ruby 2.7.
Fix this warning:

    warning: Using the last argument as keyword parameters is
    deprecated; maybe ** should be added to the call.

ref: https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/#delegation
2020-02-16 18:48:41 -06:00
evazion
d3bbd82d8b application record: drop execute_sql, select_value_sql methods. 2020-02-16 05:56:23 -06:00
evazion
d01c6b773c application model: drop unused test_connection method. 2020-02-16 05:38:50 -06:00
BrokenEagle
63b3503bfc Add ability to use nested only parameter
- The only string works much the same as before with its comma separation
-- Nested includes are indicated with square brackets "[ ]"
-- The nested include is the value immediately preceding the square brackets
-- The only string is the comma separated string inside those brackets
- Default includes are split between format types when necessary
-- This prevents unnecessary includes from being added on page load
- Available includes are those items which are allowed to be accessible to the user
-- Some aren't because they are sensitive, such as the creator of a flag
-- Some aren't because the number of associated items is too large
- The amount of times the same model can be included to prevent recursions
-- One exception is the root model may include the same model once
--- e.g. the user model can include the inviter which is also the user model
-- Another exception is if the include is a has_many association
--- e.g. artist urls can include the artist, and then artist urls again
2020-02-12 23:58:53 +00:00
evazion
24cb920608 mod reports: include reported user and message in forum post.
Also fix it so that reports against dmails include the key in the dmail
link so that mods can view the reported dmail.
2020-02-03 04:52:12 -06:00
evazion
f8db577c25 dmails: replace hard deletions with soft deletions.
Turn deletions into soft deletions (set the is_deleted flag) instead of
hard deletions (remove from database). The is_deleted flag actually
already existed, but it was never used before.
2020-01-31 16:24:27 -06:00
evazion
af044c45db mod reports: enable reporting for members, add dmail reporting.
* Add ability to report dmails.
* Enable reports for comments, forum posts, and dmails.
* Allow Members to send reports.
* Don't allow users to report the same thing twice.
2020-01-27 17:12:39 -06:00
evazion
812918556f api: fix *_lower params to downcase input. 2020-01-27 11:29:35 -06:00
BrokenEagle
ac8ec7cb15 Add parameters for searching text attributes by array with case insensitivity 2020-01-26 22:15:01 +00:00
BrokenEagle
df8d7485ad Add parameters for searching array attributes with case insensitivity
It does the by performing a lowercase on the text, so the user of these
params must also do a lowercase on their end before sending the query.
2020-01-26 21:46:48 +00:00
evazion
22cb0ea322 models: replace raw LIKE queries with where_like. 2020-01-22 13:21:31 -06:00
evazion
b4ce2d83a6 models: remove belongs_to_creator macro.
The belongs_to_creator macro was used to initialize the creator_id field
to the CurrentUser. This made tests complicated because it meant you had
to create and set the current user every time you wanted to create an
object, when lead to the current user being set over and over again. It
also meant you had to constantly be aware of what the CurrentUser was in
many different contexts, which was often confusing. Setting creators
explicitly simplifies everything greatly.
2020-01-21 00:09:38 -06:00
BrokenEagle
34368272e8 Added ability to search for URL array parameters
- Also added in different string splitters for the text fields
- Removed or renamed parameters covered by the main search function
2020-01-19 23:59:23 +00:00
evazion
3312030ce3 Fix #4240: only=… param malfunctioning on autocomplete API. 2020-01-07 00:01:14 -06:00
evazion
895199ecfc models: include all int/bool columns as html data attributes by default. 2020-01-05 22:57:47 -06:00