Commit Graph

518 Commits

Author SHA1 Message Date
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
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
88dfc463a1 db/seeds: fix deprecation warning in find_or_create_by!.
`User.find_or_create_by!` calls `User.name_matches` during username
validation, which triggers a deprecation warning for some reason:

    DEPRECATION WARNING: Class level methods will no longer inherit scoping
    from `create!` in Rails 6.1. To continue using the scoped relation,
    pass it into the block directly. To instead access the full set of
    models, as Rails 6.1 will, use `User.default_scoped`.
2020-06-10 22:33:36 -05:00
evazion
cb49489f1e tests: remove SKIP_CLOUDFLARE_CHECK env variable.
This was a hack to deal with the Cloudflare check sometimes being slow
or timing out during tests. The call to https://api.cloudflare.com/client/v4/ips
could hang if there were IPv6 connectivity problems. If this happens, make
sure that IPv6 is configured properly and that `curl -v --http1.1 -6 https://api.cloudflare.com/client/v4/ips`
works.
2020-05-12 15:50:42 -05:00
evazion
d5a7fafca1 posts/index: fix several "This tag is under discussion" issues.
Several fixes for the "This tag is under discussion" notice on the post
index page:

* Fix the notice appearing for BURs that aren't pending.
* Fix the notice never going away because of the cache never expiring.
* List all topics when a tag is involved in multiple BURs.
* Link to the forum post instead of the forum topic (fix #4421).
* Optimization: don't check for BURs when the search isn't a simple
  single tag search.
* Add a `tags` field to the bulk update requests table for tracking all
  tags involved in the request (excluding tags in mass updates that are
  negated/optional/wildcards). Known issue: doesn't handle tag type
  prefixes in mass updates correctly (e.g. `mass update foo -> artist:bar`
  doesn't detect the tag `bar`).
* Allow searching the /bulk_update_requests page by tags.

We don't really need to cache the notice here, but we do it anyway to
reduce queries on the post index page.
2020-04-27 19:11:47 -05:00
evazion
b2ee1f0766 ip bans: add hit counter, deleted flag, new ban type.
* Make IP bans soft deletable.
* Add a hit counter to track how many times an IP ban has blocked someone.
* Add a last hit timestamp to track when the IP ban last blocked someone.
* Add a new type of IP ban, the signup ban. Signup bans restrict new
  signups from editing anything until they've verified their email
  address.
2020-04-06 14:13:22 -05:00
evazion
fde42022c0 post disapprovals: refactor disapproval reasons.
* Factor out reasons into a constant
* Change column default and eliminate unused `legacy` reason.
2020-04-03 23:44:02 -05:00
evazion
4b1114b4a4 users: drop email column. 2020-03-25 18:48:42 -05:00
evazion
ea8cdadce9 commentary versions: migrate columns to non-null.
Fixes #4355.
2020-03-25 18:48:21 -05:00
evazion
b21e1d219c users: remove as_admin and as_current methods. 2020-03-21 23:06:42 -05:00
evazion
9a3b855cf6 bulk update requests: fix reference to title attribute.
Also remove non-nullable and default options from migration. The column
didn't originally have these options so they shouldn't be added if the
migration is reverted.
2020-03-20 16:08:20 -05:00
BrokenEagle
09445cb28b Drop unused BUR title column 2020-03-18 23:16:43 +00:00
evazion
96085f17dd Fix #4334: db:migrate hangs.
Possible fix for #4334. Running fix scripts inside migrations is bad practice.
2020-03-18 03:32:40 -05:00
evazion
7d028f67e9 structure.sql: resynchronize. 2020-03-18 03:09:08 -05:00
evazion
258f4a8b95 users: move emails to separate table.
* Move emails from users table to email_addresses table.
* Validate that addresses are formatted correctly and are unique across
  users. Existing invalid emails are grandfathered in.
* Add is_verified flag (the address has been confirmed by the user).
* Add is_deliverable flag (an undeliverable address is an address that bounces).
* Normalize addresses to prevent registering multiple accounts with the
  same email address (using tricks like Gmail's plus addressing).
2020-03-12 21:18:53 -05:00
evazion
5625458f69 users: refactor password reset flow.
The old password reset flow:

* User requests a password reset.
* Danbooru generates a password reset nonce.
* Danbooru emails user a password reset confirmation link.
* User follows link to password reset confirmation page.
* The link contains a nonce authenticating the user.
* User confirms password reset.
* Danbooru resets user's password to a random string.
* Danbooru emails user their new password in plaintext.

The new password reset flow:

* User requests a password reset.
* Danbooru emails user a password reset link.
* User follows link to password edit page.
* The link contains a signed_user_id param authenticating the user.
* User changes their own password.
2020-03-08 23:18:15 -05:00
evazion
f4da0a127d artists: add is_deleted and is_banned indexes. 2020-03-06 23:23:38 -06:00
evazion
4c11e339bd artists: rename is_active flag to is_deleted.
Rename is_active to is_deleted. This is for better consistency with
other models, and to reduce confusion over what "active" means for
artists. Sometimes users think active is for whether the artist is
actively producing work.
2020-03-06 14:50:21 -06:00
evazion
ce11485fe0 Remove super voters. 2020-02-23 17:52:38 -06:00
evazion
a8e5412d9c implications: refactor calculation of implied tags.
Refactor to use a recursive CTE to calculate implied tags in SQL, rather
than storing them in a descendant_names field. This avoids the
complexity of keeping the stored field up to date. It's also more
flexible, since it allows us to find both descendant tags (tags that
imply a given tag) as well as ancestor tags (tags that are implied by a
given tag).
2020-02-22 22:37:36 -06:00
evazion
2dab9aa075 models: remove creator_id from artists, notes, and pools.
Remove the creator_id field from artists, notes, and pools. The
creator_id wasn't otherwise used and was inconsistent with the
artist/note/pool history in some cases, especially for old artists.
2020-02-16 23:09:00 -06:00
evazion
18affeb4e9 Add new upload limit system (fix #4234). 2020-01-27 00:47:35 -06:00
evazion
13528ac2d3 Drop forum subscriptions.
Few people used forum subscriptions (only around 100), and even fewer
people were subscribed to active threads. Most subscriptions were for
old threads that will never be bumped again. The implementation also had
a few problems:

* Unsubscribe links in emails didn't work (they unset the user's
  receive_email_notifications flag, but forum subscriptions didn't
  respect this flag).
* Some users had invalid email addresses, which caused notifications to
  bounce. There was no mechanism for preventing bounces.
* The implementation wasn't scalable. It involved a daily linear scan
  over _all_ forum subscriptions looking for any topics that had been updated.
2020-01-21 00:10:21 -06:00
evazion
cae9a5d7e3 Drop dmail filters.
Few people used dmail filters (~900 users in 5 years) and even fewer
used them correctly. Most people used them to try to block dmail spam,
but usually they either blocked too much (by adding common words that
are present in nearly all dmails, causing all mails to them to be
filtered) or too little (blocking specific email addresses or urls,
which usually are never seen again after the spammer is banned).
Nowadays the spam detection system does a better job of filtering spam.
2020-01-21 00:10:20 -06:00
BrokenEagle
4cef0e45c2 Create the ability to send reports to moderators
- Limited to Builders+
-- Moderator+ can also use as they may be too busy ATM
- Only on users, comments, and forum posts
- Multiple reports can be generated per instance
- Primarily posts to a moderator-only topic for viewability
- Secondarily has a table for searchability
-- Viewable only by moderators
2020-01-18 06:40:20 +00:00
evazion
4a7322b197 users: rework privacy mode into private favorites (fix #4257).
* Rename 'privacy mode' to 'private favorites'.
* Make the private favorites setting only hide favorites, not favgroups
  and not the user's uploads on their profile page.
* Make the favgroup is_public flag default to true instead of false and
  fix existing favgroups to be public if the user didn't have privacy mode
  enabled before.
* List _all_ public favgroups on the /favorite_groups index, not just
  favgroups belonging to the current user.
* Add a /users/<id>/favorite_groups endpoint.
2020-01-17 22:24:29 -06:00
evazion
ab325c5d2b favgroups: convert post_ids from string to array. 2020-01-17 00:19:20 -06:00
BrokenEagle
3a422b26df Removed unneeded commentary tag checkboxes
As per the discussion on GitHub, these will be handled instead
by the existing mechanisms of related and frequent tags.
2020-01-16 21:40:14 +00:00
BrokenEagle
82b621d87d Added upload commentary enhancements
- Can now translate commentary from the upload page
- Can now add commentary tags with a checkbox
2020-01-14 23:59:27 +00:00
evazion
b650558633 user feedbacks: replace permanent deletions with soft deletions.
* Add is_deleted flag.
* Allow mods to delete and undelete user feedbacks.
* Don't hide old name change feedbacks (these will be deleted instead).
2019-12-23 00:02:54 -06:00
evazion
309821bf73 rubocop: fix various style issues. 2019-12-22 21:23:37 -06:00
evazion
2be9c113e2 Fix #4222: unrecognized configuration parameter "default_table_access_method"
This option was introduced in Postgres 12 and isn't backwards compatible
with older Postgres versions.
2019-12-06 02:32:15 -06:00
evazion
fd29f842fd db: drop keeper_data from posts. 2019-11-19 00:13:24 -06:00
evazion
64728c89d8 db: remove tag_aliases.post_count column.
This was only used in autocomplete, but it was unnecessary here because
we could already get the post count from the tags table.
2019-11-17 14:39:41 -06:00
evazion
a2ea2a65a1 db: drop IP addresses from certain tables.
Don't track IP addresses for post appeals, post flags, tag aliases, tag
implications, or user feedbacks. These things are already tightly
limited. We don't need IPs from them to detect sockpuppets.
2019-11-17 02:45:28 -06:00
evazion
72f17fd1de Fix #3534: Remove Janitor Trials. 2019-11-17 02:10:24 -06:00
evazion
1ae971269c db: drop tag subscriptions table. 2019-11-17 01:52:36 -06:00
evazion
364ecfe68f db: drop unused columns from users table.
Note that the password_hash column was replaced by bcrypt_password_hash
in 2013, but the old password_hash column was never dropped.
2019-11-16 19:34:30 -06:00
evazion
90713ef94c db: fix more inconsistencies between structure.sql and production db.
Fix various cases where db/structure.sql either didn't match the
production db or didn't match the db structure produced when running
migrations from a fresh install.
2019-11-16 16:35:04 -06:00
evazion
3746c9890a db: resync db/structure.sql. 2019-11-15 23:36:31 -06:00
evazion
529fef7224 db: set timestamps to not null. 2019-11-15 22:44:22 -06:00
evazion
dad8114c97 db: fix index inconsistencies with production db. 2019-11-15 22:44:13 -06:00
evazion
0726e4346a migrations: fix old migration not removing posts.uploader_ip_addr index.
Bug: running migrations on a fresh database failed when we got to a
migration adding a posts.uploader_ip_addr index on 2019-11-11. It failed
because the index already existed.

The index already existed because we used to have it at one point, until
it was removed by another migration on 2015-01-20. This migration didn't
correctly remove the index though, because it tried to remove a
posts.source index first, which failed because this index didn't exist
(it probably existed only in production). This error was swallowed,
causing the migration to silently skip removing the posts.uploader_ip_addr
index, which eventually blew up when we tried to add the index again
later on.
2019-11-13 02:06:41 -06:00
evazion
da8fbef5d6 /ip_addresses: add missing created_at, uploader_ip_addr indexes.
Add some missing indexes used by the /ip_addresses page.
2019-11-11 21:03:07 -06:00
evazion
bf6bb94702 Add new IP address search page.
Add a new IP address search page at /ip_addresses. Replaces the old
search page at /moderator/ip_addrs.

On user profile pages, show the user's last known IP to mods. Also add
search links for finding other IPs or accounts associated with the user.

IP address search uses a big UNION ALL statement to merge IP addresses
across various tables into a single view. This makes searching easier,
but is known to timeout in certain cases.

Fixes #4207 (the new IP search page supports searching by subnet).
2019-11-11 21:03:07 -06:00
evazion
a0b6c9b116 wiki pages: drop creator and updater fields.
Drop the creator_id and updater_id fields from wiki pages. These fields
had several issues:

* The creator_id field was inconsistent with the wiki_page_versions
  table. Apparently during the migration to Danbooru 2 in 2012-2013 the
  creator_id field got reset to whoever last updated the wiki at that
  point in time.

* Saving a wiki would set the updater_id even when nothing actually
  changed. This also caused the updated_at timestamp to get bumped.
  Because of this, anything that saved a wiki, including things like
  creating aliases or implications, would bump the updater_id and
  updated_at even though the wiki didn't actually change. This meant
  these fields weren't consistent with the wiki_page_versions history.

Changes:

* Remove `creator_name` field from the /wiki_pages.json API.
* Remove creator name search option from /wiki_pages/search.
2019-10-24 19:48:30 -05:00
evazion
9f0ecf7247 dtext links: add table for tracking links between wikis.
Add a dtext_links table for tracking links between wiki pages. This is
to allow for broken link detection and "what links here" searches, among
other uses.
2019-10-23 21:36:48 -05:00
evazion
3b63f94968 user name changes: remove unused reason, status fields.
Remove all infrastructure around approving or rejecting user name
changes. Name changes haven't been moderated for several years.

* Remove status, approver_id, change_reason, and rejection_reason fields.
* Remove approve and reject controller actions.
2019-09-25 21:43:01 -05:00
evazion
05e754eba3 users: change default user level to member in database.
Fixup for 9c34d5cc3. Default to member level in the database because
setting it in `customize_new_user` clobbered user levels set by factory
bot in tests, which broke the test suite.
2019-09-23 02:22:54 -05:00
evazion
bf51d68f15 users: add dark mode account setting (fix #4158). 2019-09-19 13:20:06 -05:00